From f629ddaacc1b6d84d4e5b0f468402b664d571565 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 23 Dec 2025 09:17:50 -0800 Subject: [PATCH 01/41] Add a wasm32-wasip3 target Almost all functions are stubbed out to return errors. This is all done in preparation for eventually filling out these functions, but the goal of this commit is to lay down the scaffolding of the target rather than actually implement anything. CI jobs are added to build and test this target. Most tests are expected to fail, but all tests are still run as usual. Once tests are passing they'll be updated in `CMakeLists.txt` to flag the test as expected to pass instead of expected to fail. This is a very large PR line-wise, but all the major changes with large chunks of code are generated code and are expected to be easy to review. The actual changes here in the source are primarily: * Adding `#elif defined(__wasip3__)` cases * Sometimes using the WASIp2 definitions of functions for WASIp3 * Shuffling naming in the network utilities to support both WASIp2 and WASIp3 which have the same types, just renamed. * Generated bindings for WASIp3 are now vendored like WASIp2 bindings. * Wasmtime is updated for testing to be able to run generated WASIp3 binaries. --- .gitattributes | 10 + .github/workflows/main.yml | 13 + CMakeLists.txt | 7 + cmake/bindings.cmake | 138 +- cmake/check-symbols.cmake | 2 + cmake/clang-format.cmake | 3 +- cmake/wasm-component-ld.cmake | 3 +- expected/wasm32-wasip1-threads/include-all.c | 2 + .../predefined-macros.txt | 2 + expected/wasm32-wasip1/include-all.c | 2 + expected/wasm32-wasip1/predefined-macros.txt | 2 + expected/wasm32-wasip2/include-all.c | 2 + expected/wasm32-wasip2/predefined-macros.txt | 2 + expected/wasm32-wasip3/defined-symbols.txt | 1551 ++++++++ expected/wasm32-wasip3/include-all.c | 181 + expected/wasm32-wasip3/predefined-macros.txt | 3507 +++++++++++++++++ expected/wasm32-wasip3/undefined-symbols.txt | 189 + libc-bottom-half/CMakeLists.txt | 29 +- libc-bottom-half/clocks/clock.c | 2 +- libc-bottom-half/clocks/getrusage.c | 2 +- libc-bottom-half/clocks/times.c | 2 +- libc-bottom-half/cloudlibc/src/common/time.h | 8 +- .../cloudlibc/src/libc/dirent/dirent_impl.h | 4 + .../cloudlibc/src/libc/dirent/fdclosedir.c | 3 + .../cloudlibc/src/libc/dirent/fdopendir.c | 5 + .../cloudlibc/src/libc/dirent/readdir.c | 7 + .../cloudlibc/src/libc/dirent/rewinddir.c | 4 + .../cloudlibc/src/libc/dirent/seekdir.c | 4 + .../cloudlibc/src/libc/dirent/telldir.c | 2 +- .../cloudlibc/src/libc/fcntl/fcntl.c | 10 +- .../cloudlibc/src/libc/fcntl/openat.c | 4 + .../cloudlibc/src/libc/fcntl/posix_fadvise.c | 4 + .../src/libc/fcntl/posix_fallocate.c | 2 +- .../cloudlibc/src/libc/poll/poll.c | 8 + .../cloudlibc/src/libc/sched/sched_yield.c | 4 +- .../cloudlibc/src/libc/stdio/renameat.c | 4 + .../cloudlibc/src/libc/stdlib/_Exit.c | 2 +- .../cloudlibc/src/libc/sys/ioctl/ioctl.c | 8 +- .../cloudlibc/src/libc/sys/select/pselect.c | 2 +- .../cloudlibc/src/libc/sys/stat/fstat.c | 4 + .../cloudlibc/src/libc/sys/stat/fstatat.c | 4 + .../cloudlibc/src/libc/sys/stat/futimens.c | 4 + .../cloudlibc/src/libc/sys/stat/mkdirat.c | 4 + .../cloudlibc/src/libc/sys/stat/stat_impl.h | 4 +- .../cloudlibc/src/libc/sys/stat/utimensat.c | 4 + .../src/libc/sys/time/gettimeofday.c | 2 +- .../cloudlibc/src/libc/sys/uio/preadv.c | 2 +- .../cloudlibc/src/libc/sys/uio/pwritev.c | 2 +- .../cloudlibc/src/libc/sys/uio/readv.c | 2 +- .../cloudlibc/src/libc/sys/uio/writev.c | 2 +- .../cloudlibc/src/libc/time/clock_getres.c | 4 + .../cloudlibc/src/libc/time/clock_gettime.c | 2 +- .../cloudlibc/src/libc/time/clock_nanosleep.c | 4 + .../cloudlibc/src/libc/time/time.c | 2 +- .../cloudlibc/src/libc/unistd/faccessat.c | 4 + .../cloudlibc/src/libc/unistd/fdatasync.c | 4 + .../cloudlibc/src/libc/unistd/fsync.c | 4 + .../cloudlibc/src/libc/unistd/ftruncate.c | 4 + .../cloudlibc/src/libc/unistd/linkat.c | 4 + .../cloudlibc/src/libc/unistd/lseek.c | 4 + .../cloudlibc/src/libc/unistd/pread.c | 4 + .../cloudlibc/src/libc/unistd/pwrite.c | 4 + .../cloudlibc/src/libc/unistd/read.c | 4 + .../cloudlibc/src/libc/unistd/readlinkat.c | 4 + .../cloudlibc/src/libc/unistd/symlinkat.c | 4 + .../cloudlibc/src/libc/unistd/usleep.c | 6 +- .../cloudlibc/src/libc/unistd/write.c | 4 + libc-bottom-half/crt/crt1-command.c | 2 +- .../headers/private/wasi/descriptor_table.h | 2 + libc-bottom-half/headers/private/wasi/file.h | 4 +- libc-bottom-half/headers/private/wasi/poll.h | 21 +- .../headers/private/wasi/sockets_utils.h | 36 +- libc-bottom-half/headers/private/wasi/stdio.h | 4 +- libc-bottom-half/headers/private/wasi/tcp.h | 10 +- libc-bottom-half/headers/private/wasi/udp.h | 10 +- .../headers/public/__header_sys_socket.h | 16 +- .../headers/public/wasi/__generated_wasip2.h | 2457 ++++++++++++ .../headers/public/wasi/__generated_wasip3.h | 2031 ++++++++++ libc-bottom-half/headers/public/wasi/api.h | 2 + libc-bottom-half/headers/public/wasi/wasip2.h | 2459 +----------- libc-bottom-half/headers/public/wasi/wasip3.h | 10 + libc-bottom-half/sources/__main_void.c | 24 +- .../sources/__wasilibc_fd_renumber.c | 4 +- .../sources/__wasilibc_initialize_environ.c | 19 +- libc-bottom-half/sources/__wasilibc_random.c | 18 +- libc-bottom-half/sources/__wasilibc_real.c | 2 +- libc-bottom-half/sources/__wasilibc_rmdirat.c | 4 + libc-bottom-half/sources/__wasilibc_tell.c | 4 + .../sources/__wasilibc_unlinkat.c | 4 + libc-bottom-half/sources/accept-wasip2.c | 22 - libc-bottom-half/sources/accept.c | 20 + libc-bottom-half/sources/getentropy.c | 2 +- libc-bottom-half/sources/isatty.c | 4 +- libc-bottom-half/sources/preopens.c | 12 +- libc-bottom-half/sources/socket.c | 29 +- libc-bottom-half/sources/sockets_utils.c | 134 +- libc-bottom-half/sources/wasip3.c | 2640 +++++++++++++ .../sources/wasip3_component_type.o | Bin 0 -> 8092 bytes libc-bottom-half/sources/wasip3_file.c | 12 + libc-bottom-half/sources/wasip3_stdio.c | 11 + libc-bottom-half/sources/wasip3_tcp.c | 13 + libc-bottom-half/sources/wasip3_udp.c | 13 + libc-top-half/CMakeLists.txt | 2 +- libc-top-half/musl/src/env/__stack_chk_fail.c | 2 +- libc-top-half/sources/arc4random.c | 2 +- test/CMakeLists.txt | 151 +- test/scripts/browser-test/harness.mjs | 4 + test/socket-test.cmake | 4 +- test/src/ioctl.c | 4 +- test/src/sockets-multiple-server.c | 3 + test/src/sockets-nonblocking-udp.c | 3 + test/src/sockets-server-udp-blocking.c | 3 + test/src/sockets-server.c | 3 + 113 files changed, 13332 insertions(+), 2740 deletions(-) create mode 100644 expected/wasm32-wasip3/defined-symbols.txt create mode 100644 expected/wasm32-wasip3/include-all.c create mode 100644 expected/wasm32-wasip3/predefined-macros.txt create mode 100644 expected/wasm32-wasip3/undefined-symbols.txt create mode 100644 libc-bottom-half/headers/public/wasi/__generated_wasip2.h create mode 100644 libc-bottom-half/headers/public/wasi/__generated_wasip3.h create mode 100644 libc-bottom-half/headers/public/wasi/wasip3.h delete mode 100644 libc-bottom-half/sources/accept-wasip2.c create mode 100644 libc-bottom-half/sources/accept.c create mode 100644 libc-bottom-half/sources/wasip3.c create mode 100644 libc-bottom-half/sources/wasip3_component_type.o create mode 100644 libc-bottom-half/sources/wasip3_file.c create mode 100644 libc-bottom-half/sources/wasip3_stdio.c create mode 100644 libc-bottom-half/sources/wasip3_tcp.c create mode 100644 libc-bottom-half/sources/wasip3_udp.c diff --git a/.gitattributes b/.gitattributes index aa2b1b7ff..17416b3b0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,3 +2,13 @@ # them differing depending on the line-ending style of the host they # were checked out on. * text eol=lf + +# All of the `expected/**/*.txt` files are auto-generated via the +# `update-symbols` target, so flag them as such. +expected linguist-generated + +# Flag some wit-bindgen-generated files checked into the repo as generated +__generated_wasip2.h linguist-generated +__generated_wasip3.h linguist-generated +libc-bottom-half/sources/wasip2.c linguist-generated +libc-bottom-half/sources/wasip3.c linguist-generated diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 28f8d9a51..b337b55ac 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -125,6 +125,19 @@ jobs: test: true args: -DCMAKE_BUILD_TYPE=Debug -DTARGET_TRIPLE=wasm32-wasip1-threads + - name: Test wasm32-wasip3 + os: ubuntu-24.04 + clang_version: 19 + test: true + upload: wasm32-wasip3 + args: -DTARGET_TRIPLE=wasm32-wasip3 + + - name: Test wasm32-wasip3 (debug) + os: ubuntu-24.04 + clang_version: 19 + test: true + args: -DCMAKE_BUILD_TYPE=Debug -DTARGET_TRIPLE=wasm32-wasip3 + - name: Test emmalloc os: ubuntu-24.04 clang_version: 19 diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c36d62d4..1fe4d6e13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,9 @@ elseif(TARGET_TRIPLE MATCHES "-wasip1$") elseif(TARGET_TRIPLE MATCHES "-wasip2$") set(WASI p2) set(SHARED ON) +elseif(TARGET_TRIPLE MATCHES "-wasip3$") + set(WASI p3) + set(SHARED ON) else() message(FATAL_ERROR "Unknown WASI target triple: ${TARGET_TRIPLE}") endif() @@ -131,6 +134,8 @@ if(WASI STREQUAL "p1") set(__wasip1__ ON) elseif(WASI STREQUAL "p2") set(__wasip2__ ON) +elseif(WASI STREQUAL "p3") + set(__wasip3__ ON) else() message(FATAL_ERROR "Unknown WASI version: ${WASI}") endif() @@ -317,6 +322,8 @@ endif() # here since I can't figure out anything else that works for now. if (WASI STREQUAL "p2") set(libc_extra_objects libc-bottom-half/sources/wasip2_component_type.o) +elseif (WASI STREQUAL "p3") + set(libc_extra_objects libc-bottom-half/sources/wasip3_component_type.o) endif() add_library(c SHARED EXCLUDE_FROM_ALL diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index dc2806485..9ffd02b8e 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -35,59 +35,119 @@ else() endif() include(ExternalProject) +set(p2 0.2.0) ExternalProject_Add( - wasi-wits - URL https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v0.2.0.tar.gz + wasip2-wits + URL https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v${p2}.tar.gz CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" EXCLUDE_FROM_ALL TRUE ) -ExternalProject_Get_Property(wasi-wits SOURCE_DIR) -set(wit_dir ${SOURCE_DIR}/wit) +ExternalProject_Get_Property(wasip2-wits SOURCE_DIR) +set(wasip2_wit_dir ${SOURCE_DIR}/wit) set(bottom_half "${CMAKE_SOURCE_DIR}/libc-bottom-half") add_custom_target( - bindings + bindings-p2 COMMAND ${wit_bindgen} c --autodrop-borrows yes --rename-world wasip2 --type-section-suffix __wasi_libc - --world wasi:cli/imports@0.2.0 - --rename wasi:clocks/monotonic-clock@0.2.0=monotonic_clock - --rename wasi:clocks/wall-clock@0.2.0=wall_clock - --rename wasi:filesystem/preopens@0.2.0=filesystem_preopens - --rename wasi:filesystem/types@0.2.0=filesystem - --rename wasi:io/error@0.2.0=io_error - --rename wasi:io/poll@0.2.0=poll - --rename wasi:io/streams@0.2.0=streams - --rename wasi:random/insecure-seed@0.2.0=random_insecure_seed - --rename wasi:random/insecure@0.2.0=random_insecure - --rename wasi:random/random@0.2.0=random - --rename wasi:sockets/instance-network@0.2.0=instance_network - --rename wasi:sockets/ip-name-lookup@0.2.0=ip_name_lookup - --rename wasi:sockets/network@0.2.0=network - --rename wasi:sockets/tcp-create-socket@0.2.0=tcp_create_socket - --rename wasi:sockets/tcp@0.2.0=tcp - --rename wasi:sockets/udp-create-socket@0.2.0=udp_create_socket - --rename wasi:sockets/udp@0.2.0=udp - --rename wasi:cli/environment@0.2.0=environment - --rename wasi:cli/exit@0.2.0=exit - --rename wasi:cli/stdin@0.2.0=stdin - --rename wasi:cli/stdout@0.2.0=stdout - --rename wasi:cli/stderr@0.2.0=stderr - --rename wasi:cli/terminal-input@0.2.0=terminal_input - --rename wasi:cli/terminal-output@0.2.0=terminal_output - --rename wasi:cli/terminal-stdin@0.2.0=terminal_stdin - --rename wasi:cli/terminal-stdout@0.2.0=terminal_stdout - --rename wasi:cli/terminal-stderr@0.2.0=terminal_stderr - ${wit_dir} - COMMAND cmake -E copy wasip2.h ${bottom_half}/headers/public/wasi/ + --world wasi:cli/imports@${p2} + --rename wasi:clocks/monotonic-clock@${p2}=monotonic_clock + --rename wasi:clocks/wall-clock@${p2}=wall_clock + --rename wasi:filesystem/preopens@${p2}=filesystem_preopens + --rename wasi:filesystem/types@${p2}=filesystem + --rename wasi:io/error@${p2}=io_error + --rename wasi:io/poll@${p2}=poll + --rename wasi:io/streams@${p2}=streams + --rename wasi:random/insecure-seed@${p2}=random_insecure_seed + --rename wasi:random/insecure@${p2}=random_insecure + --rename wasi:random/random@${p2}=random + --rename wasi:sockets/instance-network@${p2}=instance_network + --rename wasi:sockets/ip-name-lookup@${p2}=ip_name_lookup + --rename wasi:sockets/network@${p2}=network + --rename wasi:sockets/tcp-create-socket@${p2}=tcp_create_socket + --rename wasi:sockets/tcp@${p2}=tcp + --rename wasi:sockets/udp-create-socket@${p2}=udp_create_socket + --rename wasi:sockets/udp@${p2}=udp + --rename wasi:cli/environment@${p2}=environment + --rename wasi:cli/exit@${p2}=exit + --rename wasi:cli/stdin@${p2}=stdin + --rename wasi:cli/stdout@${p2}=stdout + --rename wasi:cli/stderr@${p2}=stderr + --rename wasi:cli/terminal-input@${p2}=terminal_input + --rename wasi:cli/terminal-output@${p2}=terminal_output + --rename wasi:cli/terminal-stdin@${p2}=terminal_stdin + --rename wasi:cli/terminal-stdout@${p2}=terminal_stdout + --rename wasi:cli/terminal-stderr@${p2}=terminal_stderr + ${wasip2_wit_dir} + COMMAND cmake -E copy wasip2.h ${bottom_half}/headers/public/wasi/__generated_wasip2.h COMMAND cmake -E copy wasip2_component_type.o ${bottom_half}/sources COMMAND cmake -E copy wasip2.c ${bottom_half}/sources - COMMAND sed -i "'s_#include .wasip2\.h._#include \"wasi/wasip2.h\"_'" ${bottom_half}/sources/wasip2.c - COMMAND sed -i "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/wasip2.h - COMMAND sed -i "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasip2.c - DEPENDS wit-bindgen wasi-wits + DEPENDS wit-bindgen wasip2-wits ) + +set(p3 0.3.0-rc-2025-09-16) +ExternalProject_Add( + wasip3-wits + URL https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v${p3}.tar.gz + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + EXCLUDE_FROM_ALL TRUE +) +ExternalProject_Get_Property(wasip3-wits SOURCE_DIR) +set(wasip3_wit_dir ${SOURCE_DIR}/wit-0.3.0-draft) + +add_custom_target( + bindings-p3 + COMMAND + ${wit_bindgen} c + --autodrop-borrows yes + --rename-world wasip3 + --type-section-suffix __wasi_libc + --world wasi:cli/imports@${p3} + --rename wasi:clocks/monotonic-clock@${p3}=monotonic_clock + --rename wasi:clocks/wall-clock@${p3}=wall_clock + --rename wasi:filesystem/preopens@${p3}=filesystem_preopens + --rename wasi:filesystem/types@${p3}=filesystem + --rename wasi:random/insecure-seed@${p3}=random_insecure_seed + --rename wasi:random/insecure@${p3}=random_insecure + --rename wasi:random/random@${p3}=random + --rename wasi:sockets/types@${p3}=sockets + --rename wasi:sockets/ip-name-lookup@${p3}=ip_name_lookup + --rename wasi:cli/environment@${p3}=environment + --rename wasi:cli/exit@${p3}=exit + --rename wasi:cli/stdin@${p3}=stdin + --rename wasi:cli/stdout@${p3}=stdout + --rename wasi:cli/stderr@${p3}=stderr + --rename wasi:cli/terminal-input@${p3}=terminal_input + --rename wasi:cli/terminal-output@${p3}=terminal_output + --rename wasi:cli/terminal-stdin@${p3}=terminal_stdin + --rename wasi:cli/terminal-stdout@${p3}=terminal_stdout + --rename wasi:cli/terminal-stderr@${p3}=terminal_stderr + ${wasip3_wit_dir} + COMMAND cmake -E copy wasip3.h ${bottom_half}/headers/public/wasi/__generated_wasip3.h + COMMAND cmake -E copy wasip3_component_type.o ${bottom_half}/sources + COMMAND cmake -E copy wasip3.c ${bottom_half}/sources + DEPENDS wit-bindgen wasip3-wits +) + +add_custom_target(bindings DEPENDS bindings-p2 bindings-p3) + +function(wit_bindgen_edit p) + add_custom_target( + bindings-${p}-edit + COMMAND sed -i "'s_#include .wasi${p}\.h._#include \"wasi/wasi${p}.h\"_'" ${bottom_half}/sources/wasi${p}.c + COMMAND sed -i "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/__generated_wasi${p}.h + COMMAND sed -i "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasi${p}.c + DEPENDS bindings-${p} + ) + add_dependencies(bindings bindings-${p}-edit) +endfunction() + +wit_bindgen_edit(p2) +wit_bindgen_edit(p3) diff --git a/cmake/check-symbols.cmake b/cmake/check-symbols.cmake index e472f8adc..813ac2d72 100644 --- a/cmake/check-symbols.cmake +++ b/cmake/check-symbols.cmake @@ -28,6 +28,8 @@ elseif(WASI STREQUAL "p1") set(expected "${CMAKE_SOURCE_DIR}/expected/wasm32-wasip1") elseif(WASI STREQUAL "p2") set(expected "${CMAKE_SOURCE_DIR}/expected/wasm32-wasip2") +elseif(WASI STREQUAL "p3") + set(expected "${CMAKE_SOURCE_DIR}/expected/wasm32-wasip3") else() message(FATAL_ERROR "Unknown WASI version: ${WASI}") endif() diff --git a/cmake/clang-format.cmake b/cmake/clang-format.cmake index 52a5942cb..acd458f07 100644 --- a/cmake/clang-format.cmake +++ b/cmake/clang-format.cmake @@ -20,7 +20,8 @@ add_custom_target(format-check) set(formatted_sources) function(clang_format_file file) - if (file MATCHES "wasip2\..$") # Skip auto-generated files + if (file MATCHES "__generated" OR + file MATCHES "wasip.\.c$") # Skip auto-generated files return() endif() cmake_path(ABSOLUTE_PATH file BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE src) diff --git a/cmake/wasm-component-ld.cmake b/cmake/wasm-component-ld.cmake index 6d03daaeb..2e7976602 100644 --- a/cmake/wasm-component-ld.cmake +++ b/cmake/wasm-component-ld.cmake @@ -14,6 +14,7 @@ if (NOT WASM_COMPONENT_LD_EXECUTABLE) ) ExternalProject_Get_Property(wasm-component-ld SOURCE_DIR) set(WASM_COMPONENT_LD_EXECUTABLE "${SOURCE_DIR}/wasm-component-ld") - add_link_options(-fuse-ld=${WASM_COMPONENT_LD_EXECUTABLE}) add_dependencies(sysroot_inc wasm-component-ld) endif() + +add_link_options(-fuse-ld=${WASM_COMPONENT_LD_EXECUTABLE}) diff --git a/expected/wasm32-wasip1-threads/include-all.c b/expected/wasm32-wasip1-threads/include-all.c index be4ecc5a8..ad12f0cac 100644 --- a/expected/wasm32-wasip1-threads/include-all.c +++ b/expected/wasm32-wasip1-threads/include-all.c @@ -173,5 +173,7 @@ #include #include #include +#include +#include #include #include diff --git a/expected/wasm32-wasip1-threads/predefined-macros.txt b/expected/wasm32-wasip1-threads/predefined-macros.txt index 21a674f1b..5dd34da56 100644 --- a/expected/wasm32-wasip1-threads/predefined-macros.txt +++ b/expected/wasm32-wasip1-threads/predefined-macros.txt @@ -3093,6 +3093,8 @@ #define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)(1 << 1)) #define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)(1 << 0)) #define __WASI_VERSION_H +#define __WASI_WASIP2_H +#define __WASI_WASIP3_H #define __WASI_WHENCE_CUR (UINT8_C(1)) #define __WASI_WHENCE_END (UINT8_C(2)) #define __WASI_WHENCE_SET (UINT8_C(0)) diff --git a/expected/wasm32-wasip1/include-all.c b/expected/wasm32-wasip1/include-all.c index be4ecc5a8..ad12f0cac 100644 --- a/expected/wasm32-wasip1/include-all.c +++ b/expected/wasm32-wasip1/include-all.c @@ -173,5 +173,7 @@ #include #include #include +#include +#include #include #include diff --git a/expected/wasm32-wasip1/predefined-macros.txt b/expected/wasm32-wasip1/predefined-macros.txt index 77b2b7de3..c20d1ad33 100644 --- a/expected/wasm32-wasip1/predefined-macros.txt +++ b/expected/wasm32-wasip1/predefined-macros.txt @@ -3090,6 +3090,8 @@ #define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)(1 << 1)) #define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)(1 << 0)) #define __WASI_VERSION_H +#define __WASI_WASIP2_H +#define __WASI_WASIP3_H #define __WASI_WHENCE_CUR (UINT8_C(1)) #define __WASI_WHENCE_END (UINT8_C(2)) #define __WASI_WHENCE_SET (UINT8_C(0)) diff --git a/expected/wasm32-wasip2/include-all.c b/expected/wasm32-wasip2/include-all.c index 3e8a6c359..2675563e8 100644 --- a/expected/wasm32-wasip2/include-all.c +++ b/expected/wasm32-wasip2/include-all.c @@ -166,6 +166,7 @@ #include #include #include +#include #include #include #include @@ -175,5 +176,6 @@ #include #include #include +#include #include #include diff --git a/expected/wasm32-wasip2/predefined-macros.txt b/expected/wasm32-wasip2/predefined-macros.txt index 6526e5622..13d1f8c5c 100644 --- a/expected/wasm32-wasip2/predefined-macros.txt +++ b/expected/wasm32-wasip2/predefined-macros.txt @@ -3091,6 +3091,8 @@ #define __USER_LABEL_PREFIX__ #define __USE_TIME_BITS64 1 #define __WASI_VERSION_H +#define __WASI_WASIP2_H +#define __WASI_WASIP3_H #define __WCHAR_MAX__ 2147483647 #define __WCHAR_TYPE__ int #define __WCHAR_WIDTH__ 32 diff --git a/expected/wasm32-wasip3/defined-symbols.txt b/expected/wasm32-wasip3/defined-symbols.txt new file mode 100644 index 000000000..81a03a483 --- /dev/null +++ b/expected/wasm32-wasip3/defined-symbols.txt @@ -0,0 +1,1551 @@ +_CLOCK_MONOTONIC +_CLOCK_REALTIME +_Exit +_IO_feof_unlocked +_IO_ferror_unlocked +_IO_getc +_IO_getc_unlocked +_IO_putc +_IO_putc_unlocked +__EINVAL +__ENOMEM +__SIG_ERR +__SIG_IGN +__acquire_ptc +__asctime_r +__assert_fail +__c_dot_utf8 +__c_dot_utf8_locale +__c_locale +__clock +__clock_gettime +__clock_nanosleep +__component_type_object_force_link_wasip3 +__component_type_object_force_link_wasip3_public_use_in_this_compilation_unit +__cos +__cosdf +__cosl +__crypt_blowfish +__crypt_des +__crypt_md5 +__crypt_r +__crypt_sha256 +__crypt_sha512 +__ctype_b_loc +__ctype_get_mb_cur_max +__ctype_tolower_loc +__ctype_toupper_loc +__cxa_atexit +__cxa_finalize +__default_guardsize +__default_stacksize +__des_setkey +__do_cleanup_pop +__do_cleanup_push +__do_des +__duplocale +__env_rm_add +__errno_location +__exp2f_data +__exp_data +__expo2 +__expo2f +__fbufsize +__fclose_ca +__fdopen +__fesetround +__fgetwc_unlocked +__flbf +__floatscan +__fmodeflags +__fopen_rb_ca +__fpending +__fpurge +__fputwc_unlocked +__freadable +__freadahead +__freading +__freadptr +__freadptrinc +__freelocale +__fseeko +__fseeko_unlocked +__fseterr +__fsetlocking +__fsmu8 +__ftello +__ftello_unlocked +__funcs_on_exit +__funcs_on_quick_exit +__futimesat +__fwritable +__fwritex +__fwriting +__get_locale +__getdelim +__getentropy +__getopt_msg +__gmtime_r +__hwcap +__inet_aton +__init_ssp +__init_tp +__intscan +__invtrigl_R +__isalnum_l +__isalpha_l +__isatty +__isblank_l +__iscntrl_l +__isdigit_l +__isgraph_l +__islower_l +__isoc99_fscanf +__isoc99_fwscanf +__isoc99_scanf +__isoc99_sscanf +__isoc99_swscanf +__isoc99_vfscanf +__isoc99_vfwscanf +__isoc99_vscanf +__isoc99_vsscanf +__isoc99_vswscanf +__isoc99_vwscanf +__isoc99_wscanf +__isprint_l +__ispunct_l +__isspace_l +__isupper_l +__iswalnum_l +__iswalpha_l +__iswblank_l +__iswcntrl_l +__iswctype_l +__iswdigit_l +__iswgraph_l +__iswlower_l +__iswprint_l +__iswpunct_l +__iswspace_l +__iswupper_l +__iswxdigit_l +__isxdigit_l +__lctrans +__lctrans_cur +__lctrans_impl +__ldexp_cexp +__ldexp_cexpf +__lgamma_r +__lgammaf_r +__lgammal_r +__libc +__libc_calloc +__libc_free +__libc_malloc +__loc_is_allocated +__localtime_r +__log2_data +__log2f_data +__log_data +__logf_data +__lseek +__main_void +__math_divzero +__math_divzerof +__math_invalid +__math_invalidf +__math_invalidl +__math_oflow +__math_oflowf +__math_uflow +__math_uflowf +__math_xflow +__math_xflowf +__memrchr +__mo_lookup +__month_to_secs +__newlocale +__nl_langinfo +__nl_langinfo_l +__ofl_add +__ofl_lock +__ofl_unlock +__optpos +__optreset +__overflow +__p1evll +__pio2_hi +__pio2_lo +__pleval +__polevll +__posix_getopt +__pow_log_data +__powf_log2_data +__progname +__progname_full +__pthread_cond_timedwait +__pthread_create +__pthread_join +__pthread_key_create +__pthread_key_delete +__pthread_mutex_lock +__pthread_mutex_timedlock +__pthread_mutex_trylock +__pthread_mutex_unlock +__pthread_once +__pthread_rwlock_rdlock +__pthread_rwlock_timedrdlock +__pthread_rwlock_timedwrlock +__pthread_rwlock_tryrdlock +__pthread_rwlock_trywrlock +__pthread_rwlock_unlock +__pthread_rwlock_wrlock +__pthread_setcancelstate +__pthread_testcancel +__pthread_tsd_main +__pthread_tsd_run_dtors +__pthread_tsd_size +__putenv +__qsort_r +__rand48_step +__reallocarray +__release_ptc +__rem_pio2 +__rem_pio2_large +__rem_pio2f +__rem_pio2l +__rsqrt_tab +__secs_to_tm +__secs_to_zone +__seed48 +__shgetc +__shlim +__signgam +__sin +__sindf +__sinl +__small_printf +__stack_chk_fail +__stack_chk_fail_local +__stack_chk_guard +__stderr_FILE +__stderr_used +__stdin_FILE +__stdin_used +__stdio_close +__stdio_exit +__stdio_exit_needed +__stdio_read +__stdio_seek +__stdio_write +__stdout_FILE +__stdout_used +__stdout_write +__stpcpy +__stpncpy +__strcasecmp_l +__strchrnul +__strcoll_l +__strerror_l +__strftime_fmt_1 +__strftime_l +__strncasecmp_l +__strtod_l +__strtof_l +__strtoimax_internal +__strtol_internal +__strtold_l +__strtoll_internal +__strtoul_internal +__strtoull_internal +__strtoumax_internal +__strxfrm_l +__sysinfo +__sysv_signal +__tan +__tandf +__tanl +__testcancel +__tl_lock +__tl_unlock +__tm_to_secs +__tm_to_tzname +__tolower_l +__toread +__toread_needs_stdio_exit +__toupper_l +__towctrans_l +__towlower_l +__towrite +__towrite_needs_stdio_exit +__towupper_l +__tre_mem_alloc_impl +__tre_mem_destroy +__tre_mem_new_impl +__tsearch_balance +__uflow +__unlist_locked_file +__uselocale +__utc +__wasi_init_tp +__wasi_sockets_services_db +__wasi_sockets_utils__any_addr +__wasi_sockets_utils__get_service_entry_by_name +__wasi_sockets_utils__get_service_entry_by_port +__wasi_sockets_utils__map_error +__wasi_sockets_utils__output_addr_validate +__wasi_sockets_utils__output_addr_write +__wasi_sockets_utils__parse_address +__wasi_sockets_utils__parse_port +__wasi_sockets_utils__posix_family +__wasilibc_access +__wasilibc_add_file +__wasilibc_add_tcp_socket +__wasilibc_add_udp_socket +__wasilibc_cwd +__wasilibc_deinitialize_environ +__wasilibc_dttoif +__wasilibc_ensure_environ +__wasilibc_environ +__wasilibc_fd_renumber +__wasilibc_find_abspath +__wasilibc_find_relpath +__wasilibc_find_relpath_alloc +__wasilibc_get_environ +__wasilibc_iftodt +__wasilibc_init_stdio +__wasilibc_initialize_environ +__wasilibc_link +__wasilibc_link_newat +__wasilibc_link_oldat +__wasilibc_maybe_reinitialize_environ_eagerly +__wasilibc_nocwd___wasilibc_rmdirat +__wasilibc_nocwd___wasilibc_unlinkat +__wasilibc_nocwd_faccessat +__wasilibc_nocwd_fstatat +__wasilibc_nocwd_linkat +__wasilibc_nocwd_mkdirat_nomode +__wasilibc_nocwd_openat_nomode +__wasilibc_nocwd_opendirat +__wasilibc_nocwd_readlinkat +__wasilibc_nocwd_renameat +__wasilibc_nocwd_scandirat +__wasilibc_nocwd_symlinkat +__wasilibc_nocwd_utimensat +__wasilibc_open_nomode +__wasilibc_populate_preopens +__wasilibc_pthread_self +__wasilibc_random +__wasilibc_rename_newat +__wasilibc_rename_oldat +__wasilibc_reset_preopens +__wasilibc_rmdirat +__wasilibc_stat +__wasilibc_tell +__wasilibc_unlinkat +__wasilibc_utimens +__wasm_call_dtors +__wcscoll_l +__wcsftime_l +__wcsxfrm_l +__wctrans_l +__wctype_l +__xpg_basename +__xpg_strerror_r +__year_to_secs +_environ +_exit +_flushlbf +_initialize +_pthread_cleanup_pop +_pthread_cleanup_push +_start +a64l +abort +abs +accept +accept4 +access +acos +acosf +acosh +acoshf +acoshl +acosl +aligned_alloc +alphasort +alphasort64 +arc4random +arc4random_buf +arc4random_uniform +asctime +asctime_r +asin +asinf +asinh +asinhf +asinhl +asinl +asprintf +at_quick_exit +atan +atan2 +atan2f +atan2l +atanf +atanh +atanhf +atanhl +atanl +atexit +atof +atoi +atol +atoll +basename +bcmp +bcopy +bind +bsd_signal +bsearch +btowc +bzero +c16rtomb +c32rtomb +cabi_realloc +cabs +cabsf +cabsl +cacos +cacosf +cacosh +cacoshf +cacoshl +cacosl +calloc +carg +cargf +cargl +casin +casinf +casinh +casinhf +casinhl +casinl +catan +catanf +catanh +catanhf +catanhl +catanl +catclose +catgets +catopen +cbrt +cbrtf +cbrtl +ccos +ccosf +ccosh +ccoshf +ccoshl +ccosl +ceil +ceilf +ceill +cexp +cexpf +cexpl +chdir +chmod +cimag +cimagf +cimagl +clearenv +clearerr +clearerr_unlocked +clock +clock_getres +clock_gettime +clock_nanosleep +clog +clogf +clogl +close +closedir +confstr +conj +conjf +conjl +connect +copysign +copysignf +copysignl +cos +cosf +cosh +coshf +coshl +cosl +cpow +cpowf +cpowl +cproj +cprojf +cprojl +creal +crealf +creall +creat +creat64 +crypt +crypt_r +csin +csinf +csinh +csinhf +csinhl +csinl +csqrt +csqrtf +csqrtl +ctan +ctanf +ctanh +ctanhf +ctanhl +ctanl +ctime +ctime_r +descriptor_table_get_ref +descriptor_table_insert +descriptor_table_remove +descriptor_table_renumber +difftime +dirfd +dirname +div +dprintf +drand48 +drem +dremf +duplocale +ecvt +encrypt +environ +environment_get_arguments +environment_get_environment +environment_get_initial_cwd +erand48 +erf +erfc +erfcf +erfcl +erff +erfl +errno +exit +exit_exit +exit_result_void_void_free +exp +exp10 +exp10f +exp10l +exp2 +exp2f +exp2l +expf +expl +explicit_bzero +expm1 +expm1f +expm1l +fabs +fabsf +fabsl +faccessat +fchmod +fchmodat +fclose +fcntl +fcvt +fdatasync +fdclosedir +fdim +fdimf +fdiml +fdopen +fdopendir +feclearexcept +fegetenv +fegetexceptflag +fegetround +feholdexcept +feof +feof_unlocked +feraiseexcept +ferror +ferror_unlocked +fesetenv +fesetexceptflag +fesetround +fetestexcept +feupdateenv +fflush +fflush_unlocked +ffs +ffsl +ffsll +fgetc +fgetc_unlocked +fgetln +fgetpos +fgetpos64 +fgets +fgets_unlocked +fgetwc +fgetwc_unlocked +fgetws +fgetws_unlocked +fileno +fileno_unlocked +filesystem_borrow_descriptor +filesystem_descriptor_drop_own +filesystem_descriptor_stat_free +filesystem_directory_entry_free +filesystem_future_result_void_error_code_cancel_read +filesystem_future_result_void_error_code_cancel_write +filesystem_future_result_void_error_code_drop_readable +filesystem_future_result_void_error_code_drop_writable +filesystem_future_result_void_error_code_new +filesystem_future_result_void_error_code_read +filesystem_future_result_void_error_code_write +filesystem_method_descriptor_advise +filesystem_method_descriptor_append_via_stream +filesystem_method_descriptor_create_directory_at +filesystem_method_descriptor_get_flags +filesystem_method_descriptor_get_type +filesystem_method_descriptor_is_same_object +filesystem_method_descriptor_link_at +filesystem_method_descriptor_metadata_hash +filesystem_method_descriptor_metadata_hash_at +filesystem_method_descriptor_open_at +filesystem_method_descriptor_read_directory +filesystem_method_descriptor_read_via_stream +filesystem_method_descriptor_readlink_at +filesystem_method_descriptor_remove_directory_at +filesystem_method_descriptor_rename_at +filesystem_method_descriptor_set_size +filesystem_method_descriptor_set_times +filesystem_method_descriptor_set_times_at +filesystem_method_descriptor_stat +filesystem_method_descriptor_stat_at +filesystem_method_descriptor_symlink_at +filesystem_method_descriptor_sync +filesystem_method_descriptor_sync_data +filesystem_method_descriptor_unlink_file_at +filesystem_method_descriptor_write_via_stream +filesystem_new_timestamp_free +filesystem_option_datetime_free +filesystem_preopens_get_directories +filesystem_preopens_list_tuple2_own_descriptor_string_free +filesystem_preopens_tuple2_own_descriptor_string_free +filesystem_result_descriptor_flags_error_code_free +filesystem_result_descriptor_stat_error_code_free +filesystem_result_descriptor_type_error_code_free +filesystem_result_metadata_hash_value_error_code_free +filesystem_result_own_descriptor_error_code_free +filesystem_result_string_error_code_free +filesystem_result_void_error_code_free +filesystem_stream_directory_entry_cancel_read +filesystem_stream_directory_entry_cancel_write +filesystem_stream_directory_entry_drop_readable +filesystem_stream_directory_entry_drop_writable +filesystem_stream_directory_entry_new +filesystem_stream_directory_entry_read +filesystem_stream_directory_entry_write +filesystem_stream_u8_cancel_read +filesystem_stream_u8_cancel_write +filesystem_stream_u8_drop_readable +filesystem_stream_u8_drop_writable +filesystem_stream_u8_new +filesystem_stream_u8_read +filesystem_stream_u8_write +finite +finitef +floor +floorf +floorl +fma +fmaf +fmal +fmax +fmaxf +fmaxl +fmemopen +fmin +fminf +fminl +fmod +fmodf +fmodl +fmtmsg +fnmatch +fopen +fopen64 +fopencookie +fpathconf +fprintf +fpurge +fputc +fputc_unlocked +fputs +fputs_unlocked +fputwc +fputwc_unlocked +fputws +fputws_unlocked +fread +fread_unlocked +free +freelocale +freopen +freopen64 +frexp +frexpf +frexpl +fscanf +fseek +fseeko +fseeko64 +fsetpos +fsetpos64 +fstat +fstatat +fstatvfs +fsync +ftell +ftello +ftello64 +ftime +ftruncate +fts_children +fts_close +fts_open +fts_read +fts_set +futimens +futimesat +fwide +fwprintf +fwrite +fwrite_unlocked +fwscanf +gai_strerror +gcvt +get_avphys_pages +get_nprocs +get_nprocs_conf +get_phys_pages +getc +getc_unlocked +getchar +getchar_unlocked +getcwd +getdate +getdate_err +getdelim +getdomainname +getentropy +getenv +gethostid +gethostname +getline +getopt +getopt_long +getopt_long_only +getpagesize +getpeername +getpid +getrusage +getsockname +getsockopt +getsubopt +gettimeofday +getw +getwc +getwc_unlocked +getwchar +getwchar_unlocked +glob +glob64 +globfree +globfree64 +gmtime +gmtime_r +hcreate +hcreate_r +hdestroy +hdestroy_r +hsearch +hsearch_r +htonl +htons +hypot +hypotf +hypotl +iconv +iconv_close +iconv_open +ilogb +ilogbf +ilogbl +imaxabs +imaxdiv +in6addr_any +in6addr_loopback +index +inet_addr +inet_aton +inet_lnaof +inet_makeaddr +inet_netof +inet_network +inet_ntoa +inet_ntop +inet_pton +initstate +insque +ioctl +ip_name_lookup_ip_address_free +ip_name_lookup_list_ip_address_free +ip_name_lookup_resolve_addresses +ip_name_lookup_result_list_ip_address_error_code_free +iprintf +isalnum +isalnum_l +isalpha +isalpha_l +isascii +isatty +isblank +isblank_l +iscntrl +iscntrl_l +isdigit +isdigit_l +isgraph +isgraph_l +islower +islower_l +isprint +isprint_l +ispunct +ispunct_l +isspace +isspace_l +isupper +isupper_l +iswalnum +iswalnum_l +iswalpha +iswalpha_l +iswblank +iswblank_l +iswcntrl +iswcntrl_l +iswctype +iswctype_l +iswdigit +iswdigit_l +iswgraph +iswgraph_l +iswlower +iswlower_l +iswprint +iswprint_l +iswpunct +iswpunct_l +iswspace +iswspace_l +iswupper +iswupper_l +iswxdigit +iswxdigit_l +isxdigit +isxdigit_l +j0 +j0f +j1 +j1f +jn +jnf +jrand48 +l64a +labs +lcong48 +ldexp +ldexpf +ldexpl +ldiv +lfind +lgamma +lgamma_r +lgammaf +lgammaf_r +lgammal +lgammal_r +link +linkat +listen +llabs +lldiv +llrint +llrintf +llrintl +llround +llroundf +llroundl +localeconv +localtime +localtime_r +log +log10 +log10f +log10l +log1p +log1pf +log1pl +log2 +log2f +log2l +logb +logbf +logbl +logf +logl +lrand48 +lrint +lrintf +lrintl +lround +lroundf +lroundl +lsearch +lseek +lstat +malloc +malloc_usable_size +mblen +mbrlen +mbrtoc16 +mbrtoc32 +mbrtowc +mbsinit +mbsnrtowcs +mbsrtowcs +mbstowcs +mbtowc +memccpy +memchr +memcmp +memcpy +memmem +memmove +mempcpy +memrchr +memset +mkdir +mkdirat +mktime +mmap +modf +modff +modfl +monotonic_clock_get_resolution +monotonic_clock_now +monotonic_clock_wait_for +monotonic_clock_wait_until +mprotect +mrand48 +munmap +nan +nanf +nanl +nanosleep +nearbyint +nearbyintf +nearbyintl +newlocale +nextafter +nextafterf +nextafterl +nexttoward +nexttowardf +nexttowardl +nftw +nftw64 +nl_langinfo +nl_langinfo_l +nrand48 +ntohl +ntohs +open +open_memstream +open_wmemstream +openat +opendir +opendirat +optarg +opterr +optind +optopt +optreset +pathconf +perror +poll +posix_close +posix_fadvise +posix_fallocate +posix_memalign +pow +pow10 +pow10f +pow10l +powf +powl +pread +preadv +printf +program_invocation_name +program_invocation_short_name +pselect +psignal +pthread_attr_destroy +pthread_attr_getdetachstate +pthread_attr_getguardsize +pthread_attr_getschedparam +pthread_attr_getstack +pthread_attr_getstacksize +pthread_attr_init +pthread_attr_setdetachstate +pthread_attr_setguardsize +pthread_attr_setschedparam +pthread_attr_setstack +pthread_attr_setstacksize +pthread_barrier_destroy +pthread_barrier_init +pthread_barrier_wait +pthread_barrierattr_destroy +pthread_barrierattr_getpshared +pthread_barrierattr_init +pthread_barrierattr_setpshared +pthread_cancel +pthread_cond_broadcast +pthread_cond_destroy +pthread_cond_init +pthread_cond_signal +pthread_cond_timedwait +pthread_cond_wait +pthread_condattr_destroy +pthread_condattr_getclock +pthread_condattr_getpshared +pthread_condattr_init +pthread_condattr_setclock +pthread_condattr_setpshared +pthread_create +pthread_detach +pthread_equal +pthread_getattr_np +pthread_getspecific +pthread_join +pthread_key_create +pthread_key_delete +pthread_mutex_consistent +pthread_mutex_destroy +pthread_mutex_getprioceiling +pthread_mutex_init +pthread_mutex_lock +pthread_mutex_timedlock +pthread_mutex_trylock +pthread_mutex_unlock +pthread_mutexattr_destroy +pthread_mutexattr_getprotocol +pthread_mutexattr_getpshared +pthread_mutexattr_getrobust +pthread_mutexattr_gettype +pthread_mutexattr_init +pthread_mutexattr_setprotocol +pthread_mutexattr_setpshared +pthread_mutexattr_setrobust +pthread_mutexattr_settype +pthread_once +pthread_rwlock_destroy +pthread_rwlock_init +pthread_rwlock_rdlock +pthread_rwlock_timedrdlock +pthread_rwlock_timedwrlock +pthread_rwlock_tryrdlock +pthread_rwlock_trywrlock +pthread_rwlock_unlock +pthread_rwlock_wrlock +pthread_rwlockattr_destroy +pthread_rwlockattr_getpshared +pthread_rwlockattr_init +pthread_rwlockattr_setpshared +pthread_self +pthread_setcancelstate +pthread_setcanceltype +pthread_setspecific +pthread_spin_destroy +pthread_spin_init +pthread_spin_lock +pthread_spin_trylock +pthread_spin_unlock +pthread_testcancel +pthread_timedjoin_np +pthread_tryjoin_np +putc +putc_unlocked +putchar +putchar_unlocked +putenv +puts +putw +putwc +putwc_unlocked +putwchar +putwchar_unlocked +pwrite +pwritev +qsort +qsort_r +quick_exit +raise +rand +rand_r +random +random_get_random_bytes +random_get_random_u64 +random_insecure_get_insecure_random_bytes +random_insecure_get_insecure_random_u64 +random_insecure_seed_get_insecure_seed +read +readdir +readlink +readlinkat +readv +realloc +reallocarray +realpath +recv +recvfrom +regcomp +regerror +regexec +regfree +remainder +remainderf +remainderl +remove +remque +remquo +remquof +remquol +rename +renameat +rewind +rewinddir +rindex +rint +rintf +rintl +rmdir +round +roundf +roundl +sbrk +scalb +scalbf +scalbln +scalblnf +scalblnl +scalbn +scalbnf +scalbnl +scandir +scandirat +scanf +sched_yield +seed48 +seekdir +select +send +sendto +setbuf +setbuffer +setenv +setkey +setlinebuf +setlocale +setsockopt +setstate +setvbuf +shutdown +signal +signgam +significand +significandf +sin +sincos +sincosf +sincosl +sinf +sinh +sinhf +sinhl +sinl +sleep +snprintf +socket +sockets_borrow_tcp_socket +sockets_borrow_udp_socket +sockets_future_result_void_error_code_cancel_read +sockets_future_result_void_error_code_cancel_write +sockets_future_result_void_error_code_drop_readable +sockets_future_result_void_error_code_drop_writable +sockets_future_result_void_error_code_new +sockets_future_result_void_error_code_read +sockets_future_result_void_error_code_write +sockets_ip_address_free +sockets_ip_socket_address_free +sockets_method_tcp_socket_bind +sockets_method_tcp_socket_connect +sockets_method_tcp_socket_get_address_family +sockets_method_tcp_socket_get_hop_limit +sockets_method_tcp_socket_get_is_listening +sockets_method_tcp_socket_get_keep_alive_count +sockets_method_tcp_socket_get_keep_alive_enabled +sockets_method_tcp_socket_get_keep_alive_idle_time +sockets_method_tcp_socket_get_keep_alive_interval +sockets_method_tcp_socket_get_local_address +sockets_method_tcp_socket_get_receive_buffer_size +sockets_method_tcp_socket_get_remote_address +sockets_method_tcp_socket_get_send_buffer_size +sockets_method_tcp_socket_listen +sockets_method_tcp_socket_receive +sockets_method_tcp_socket_send +sockets_method_tcp_socket_set_hop_limit +sockets_method_tcp_socket_set_keep_alive_count +sockets_method_tcp_socket_set_keep_alive_enabled +sockets_method_tcp_socket_set_keep_alive_idle_time +sockets_method_tcp_socket_set_keep_alive_interval +sockets_method_tcp_socket_set_listen_backlog_size +sockets_method_tcp_socket_set_receive_buffer_size +sockets_method_tcp_socket_set_send_buffer_size +sockets_method_udp_socket_bind +sockets_method_udp_socket_connect +sockets_method_udp_socket_disconnect +sockets_method_udp_socket_get_address_family +sockets_method_udp_socket_get_local_address +sockets_method_udp_socket_get_receive_buffer_size +sockets_method_udp_socket_get_remote_address +sockets_method_udp_socket_get_send_buffer_size +sockets_method_udp_socket_get_unicast_hop_limit +sockets_method_udp_socket_receive +sockets_method_udp_socket_send +sockets_method_udp_socket_set_receive_buffer_size +sockets_method_udp_socket_set_send_buffer_size +sockets_method_udp_socket_set_unicast_hop_limit +sockets_option_ip_socket_address_free +sockets_result_bool_error_code_free +sockets_result_duration_error_code_free +sockets_result_ip_socket_address_error_code_free +sockets_result_own_tcp_socket_error_code_free +sockets_result_own_udp_socket_error_code_free +sockets_result_stream_own_tcp_socket_error_code_free +sockets_result_tuple2_list_u8_ip_socket_address_error_code_free +sockets_result_u32_error_code_free +sockets_result_u64_error_code_free +sockets_result_u8_error_code_free +sockets_result_void_error_code_free +sockets_static_tcp_socket_create +sockets_static_udp_socket_create +sockets_stream_own_tcp_socket_cancel_read +sockets_stream_own_tcp_socket_cancel_write +sockets_stream_own_tcp_socket_drop_readable +sockets_stream_own_tcp_socket_drop_writable +sockets_stream_own_tcp_socket_new +sockets_stream_own_tcp_socket_read +sockets_stream_own_tcp_socket_write +sockets_stream_u8_cancel_read +sockets_stream_u8_cancel_write +sockets_stream_u8_drop_readable +sockets_stream_u8_drop_writable +sockets_stream_u8_new +sockets_stream_u8_read +sockets_stream_u8_write +sockets_tcp_socket_drop_own +sockets_tuple2_list_u8_ip_socket_address_free +sockets_udp_socket_drop_own +sprintf +sqrt +sqrtf +sqrtl +srand +srand48 +srandom +sscanf +stat +statvfs +stderr +stderr_result_void_error_code_free +stderr_write_via_stream +stdin +stdin_future_result_void_error_code_cancel_read +stdin_future_result_void_error_code_cancel_write +stdin_future_result_void_error_code_drop_readable +stdin_future_result_void_error_code_drop_writable +stdin_future_result_void_error_code_new +stdin_future_result_void_error_code_read +stdin_future_result_void_error_code_write +stdin_read_via_stream +stdin_result_void_error_code_free +stdin_stream_u8_cancel_read +stdin_stream_u8_cancel_write +stdin_stream_u8_drop_readable +stdin_stream_u8_drop_writable +stdin_stream_u8_new +stdin_stream_u8_read +stdin_stream_u8_write +stdout +stdout_result_void_error_code_free +stdout_write_via_stream +stpcpy +stpncpy +strcasecmp +strcasecmp_l +strcasestr +strcat +strchr +strchrnul +strcmp +strcoll +strcoll_l +strcpy +strcspn +strdup +strerror +strerror_l +strerror_r +strfmon +strfmon_l +strftime +strftime_l +strlcat +strlcpy +strlen +strncasecmp +strncasecmp_l +strncat +strncmp +strncpy +strndup +strnlen +strpbrk +strptime +strrchr +strsep +strsignal +strspn +strstr +strtod +strtod_l +strtof +strtof_l +strtoimax +strtok +strtok_r +strtol +strtold +strtold_l +strtoll +strtoul +strtoull +strtoumax +strverscmp +strxfrm +strxfrm_l +swab +swprintf +swscanf +symlink +symlinkat +sysconf +tan +tanf +tanh +tanhf +tanhl +tanl +tdelete +tdestroy +telldir +terminal_input_borrow_terminal_input +terminal_input_terminal_input_drop_own +terminal_output_borrow_terminal_output +terminal_output_terminal_output_drop_own +terminal_stderr_get_terminal_stderr +terminal_stderr_option_own_terminal_output_free +terminal_stdin_get_terminal_stdin +terminal_stdin_option_own_terminal_input_free +terminal_stdout_get_terminal_stdout +terminal_stdout_option_own_terminal_output_free +tfind +tgamma +tgammaf +tgammal +thrd_current +thrd_detach +thrd_equal +thrd_sleep +time +timegm +times +timespec_get +toascii +tolower +tolower_l +toupper +toupper_l +towctrans +towctrans_l +towlower +towlower_l +towupper +towupper_l +trunc +truncate +truncf +truncl +tsearch +tss_get +twalk +uname +ungetc +ungetwc +unlink +unlinkat +unsetenv +uselocale +usleep +utime +utimensat +utimes +vasprintf +vdprintf +versionsort +versionsort64 +vfprintf +vfscanf +vfwprintf +vfwscanf +vprintf +vscanf +vsnprintf +vsprintf +vsscanf +vswprintf +vswscanf +vwprintf +vwscanf +wall_clock_get_resolution +wall_clock_now +wasip3_backpressure_dec +wasip3_backpressure_inc +wasip3_backpressure_set +wasip3_context_get +wasip3_context_set +wasip3_list_string_free +wasip3_list_tuple2_string_string_free +wasip3_list_u8_free +wasip3_option_string_free +wasip3_string_dup +wasip3_string_free +wasip3_string_set +wasip3_subtask_cancel +wasip3_subtask_drop +wasip3_task_cancel +wasip3_tuple2_string_string_free +wasip3_waitable_join +wasip3_waitable_set_drop +wasip3_waitable_set_new +wasip3_waitable_set_poll +wasip3_waitable_set_wait +wasip3_yield +wasip3_yield_cancellable +wcpcpy +wcpncpy +wcrtomb +wcscasecmp +wcscasecmp_l +wcscat +wcschr +wcscmp +wcscoll +wcscoll_l +wcscpy +wcscspn +wcsdup +wcsftime +wcsftime_l +wcslen +wcsncasecmp +wcsncasecmp_l +wcsncat +wcsncmp +wcsncpy +wcsnlen +wcsnrtombs +wcspbrk +wcsrchr +wcsrtombs +wcsspn +wcsstr +wcstod +wcstof +wcstoimax +wcstok +wcstol +wcstold +wcstoll +wcstombs +wcstoul +wcstoull +wcstoumax +wcswcs +wcswidth +wcsxfrm +wcsxfrm_l +wctob +wctomb +wctrans +wctrans_l +wctype +wctype_l +wcwidth +wmemchr +wmemcmp +wmemcpy +wmemmove +wmemset +wprintf +write +writev +wscanf +y0 +y0f +y1 +y1f +yn +ynf \ No newline at end of file diff --git a/expected/wasm32-wasip3/include-all.c b/expected/wasm32-wasip3/include-all.c new file mode 100644 index 000000000..770ce5d76 --- /dev/null +++ b/expected/wasm32-wasip3/include-all.c @@ -0,0 +1,181 @@ +#include <__errno.h> +#include <__errno_values.h> +#include <__fd_set.h> +#include <__function___isatty.h> +#include <__functions_malloc.h> +#include <__functions_memcpy.h> +#include <__header_dirent.h> +#include <__header_fcntl.h> +#include <__header_inttypes.h> +#include <__header_netinet_in.h> +#include <__header_poll.h> +#include <__header_stdlib.h> +#include <__header_string.h> +#include <__header_sys_ioctl.h> +#include <__header_sys_resource.h> +#include <__header_sys_socket.h> +#include <__header_sys_stat.h> +#include <__header_time.h> +#include <__header_unistd.h> +#include <__macro_FD_SETSIZE.h> +#include <__macro_PAGESIZE.h> +#include <__mode_t.h> +#include <__seek.h> +#include <__struct_dirent.h> +#include <__struct_in6_addr.h> +#include <__struct_in_addr.h> +#include <__struct_iovec.h> +#include <__struct_msghdr.h> +#include <__struct_pollfd.h> +#include <__struct_rusage.h> +#include <__struct_sockaddr.h> +#include <__struct_sockaddr_in.h> +#include <__struct_sockaddr_in6.h> +#include <__struct_sockaddr_storage.h> +#include <__struct_sockaddr_un.h> +#include <__struct_stat.h> +#include <__struct_timespec.h> +#include <__struct_timeval.h> +#include <__struct_tm.h> +#include <__struct_tms.h> +#include <__typedef_DIR.h> +#include <__typedef_blkcnt_t.h> +#include <__typedef_blksize_t.h> +#include <__typedef_clock_t.h> +#include <__typedef_clockid_t.h> +#include <__typedef_dev_t.h> +#include <__typedef_fd_set.h> +#include <__typedef_gid_t.h> +#include <__typedef_in_addr_t.h> +#include <__typedef_in_port_t.h> +#include <__typedef_ino_t.h> +#include <__typedef_mode_t.h> +#include <__typedef_nfds_t.h> +#include <__typedef_nlink_t.h> +#include <__typedef_off_t.h> +#include <__typedef_sa_family_t.h> +#include <__typedef_sigset_t.h> +#include <__typedef_socklen_t.h> +#include <__typedef_ssize_t.h> +#include <__typedef_suseconds_t.h> +#include <__typedef_time_t.h> +#include <__typedef_uid_t.h> +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/expected/wasm32-wasip3/predefined-macros.txt b/expected/wasm32-wasip3/predefined-macros.txt new file mode 100644 index 000000000..8f6bc4aa3 --- /dev/null +++ b/expected/wasm32-wasip3/predefined-macros.txt @@ -0,0 +1,3507 @@ +#define ABDAY_1 0x20000 +#define ABDAY_2 0x20001 +#define ABDAY_3 0x20002 +#define ABDAY_4 0x20003 +#define ABDAY_5 0x20004 +#define ABDAY_6 0x20005 +#define ABDAY_7 0x20006 +#define ABMON_1 0x2000E +#define ABMON_10 0x20017 +#define ABMON_11 0x20018 +#define ABMON_12 0x20019 +#define ABMON_2 0x2000F +#define ABMON_3 0x20010 +#define ABMON_4 0x20011 +#define ABMON_5 0x20012 +#define ABMON_6 0x20013 +#define ABMON_7 0x20014 +#define ABMON_8 0x20015 +#define ABMON_9 0x20016 +#define ABORT 238 +#define ACK 04 +#define ADD ns_uop_add +#define ADJ_ESTERROR 0x0008 +#define ADJ_FREQUENCY 0x0002 +#define ADJ_MAXERROR 0x0004 +#define ADJ_MICRO 0x1000 +#define ADJ_NANO 0x2000 +#define ADJ_OFFSET 0x0001 +#define ADJ_OFFSET_SINGLESHOT 0x8001 +#define ADJ_OFFSET_SS_READ 0xa001 +#define ADJ_SETOFFSET 0x0100 +#define ADJ_STATUS 0x0010 +#define ADJ_TAI 0x0080 +#define ADJ_TICK 0x4000 +#define ADJ_TIMECONST 0x0020 +#define AF_INET PF_INET +#define AF_INET6 PF_INET6 +#define AF_UNIX 3 +#define AF_UNSPEC PF_UNSPEC +#define AI_ADDRCONFIG 0x20 +#define AI_ALL 0x10 +#define AI_CANONNAME 0x02 +#define AI_NUMERICHOST 0x04 +#define AI_NUMERICSERV 0x400 +#define AI_PASSIVE 0x01 +#define AI_V4MAPPED 0x08 +#define ALT_DIGITS 0x2002F +#define AM_STR 0x20026 +#define ANYMARK 0x01 +#define AO 245 +#define AREGTYPE '\0' +#define ARFMAG "`\n" +#define ARG_MAX 131072 +#define ARMAG "!\n" +#define AT_EACCESS (0x0) +#define AT_FDCWD (-2) +#define AT_REMOVEDIR (0x4) +#define AT_SYMLINK_FOLLOW (0x2) +#define AT_SYMLINK_NOFOLLOW (0x1) +#define AUTHTYPE_CNT 5 +#define AUTHTYPE_KERBEROS_V4 1 +#define AUTHTYPE_KERBEROS_V5 2 +#define AUTHTYPE_MINK 4 +#define AUTHTYPE_NAME(x) authtype_names[x] +#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT) +#define AUTHTYPE_NULL 0 +#define AUTHTYPE_SPX 3 +#define AUTHTYPE_TEST 99 +#define AUTH_HOW_MASK 2 +#define AUTH_HOW_MUTUAL 2 +#define AUTH_HOW_ONE_WAY 0 +#define AUTH_WHO_CLIENT 0 +#define AUTH_WHO_MASK 1 +#define AUTH_WHO_SERVER 1 +#define AYT 246 +#define BIG_ENDIAN __BIG_ENDIAN +#define BITSPERBYTE CHAR_BIT +#define BLKTYPE '4' +#define BLK_BYTECOUNT 2 +#define BLK_EOF 0x40 +#define BLK_EOR 0x80 +#define BLK_ERRORS 0x20 +#define BLK_RESTART 0x10 +#define BREAK 243 +#define BUFSIZ 1024 +#define BYTE_ORDER __BYTE_ORDER +#define CANBSIZ 255 +#define CBRK CEOL +#define CDISCARD CTRL('o') +#define CDSUSP CTRL('y') +#define CEOF CTRL('d') +#define CEOL '\0' +#define CEOT CEOF +#define CERASE 0177 +#define CFLUSH CDISCARD +#define CHARBITS (sizeof(char) * 8) +#define CHARCLASS_NAME_MAX 14 +#define CHAR_BIT 8 +#define CHAR_MAX 127 +#define CHAR_MIN (-128) +#define CHRTYPE '3' +#define CINTR CTRL('c') +#define CKILL CTRL('u') +#define CLNEXT CTRL('v') +#define CLOCKS_PER_SEC ((clock_t)1000000000) +#define CLOCK_MONOTONIC (&_CLOCK_MONOTONIC) +#define CLOCK_REALTIME (&_CLOCK_REALTIME) +#define CMIN 1 +#define CMPLX(x,y) __CMPLX(x, y, double) +#define CMPLXF(x,y) __CMPLX(x, y, float) +#define CMPLXL(x,y) __CMPLX(x, y, long double) +#define CODESET 14 +#define COLL_WEIGHTS_MAX 2 +#define COMPLETE 2 +#define CONTINUE 3 +#define CONTTYPE '7' +#define CQUIT 034 +#define CREPRINT CTRL('r') +#define CRNCYSTR 0x4000F +#define CRPRNT CREPRINT +#define CSTART CTRL('q') +#define CSTATUS '\0' +#define CSTOP CTRL('s') +#define CSUSP CTRL('z') +#define CTIME 0 +#define CTRL(x) ((x)&037) +#define CWERASE CTRL('w') +#define C_ANY ns_c_any +#define C_CHAOS ns_c_chaos +#define C_HS ns_c_hs +#define C_IN ns_c_in +#define C_IRGRP 000040 +#define C_IROTH 000004 +#define C_IRUSR 000400 +#define C_ISBLK 060000 +#define C_ISCHR 020000 +#define C_ISCTG 0110000 +#define C_ISDIR 040000 +#define C_ISFIFO 010000 +#define C_ISGID 002000 +#define C_ISLNK 0120000 +#define C_ISREG 0100000 +#define C_ISSOCK 0140000 +#define C_ISUID 004000 +#define C_ISVTX 001000 +#define C_IWGRP 000020 +#define C_IWOTH 000002 +#define C_IWUSR 000200 +#define C_IXGRP 000010 +#define C_IXOTH 000001 +#define C_IXUSR 000100 +#define C_NONE ns_c_none +#define DATA 03 +#define DAY_1 0x20007 +#define DAY_2 0x20008 +#define DAY_3 0x20009 +#define DAY_4 0x2000A +#define DAY_5 0x2000B +#define DAY_6 0x2000C +#define DAY_7 0x2000D +#define DBL_DECIMAL_DIG 17 +#define DBL_DIG 15 +#define DBL_EPSILON 2.22044604925031308085e-16 +#define DBL_HAS_SUBNORM 1 +#define DBL_MANT_DIG 53 +#define DBL_MAX 1.79769313486231570815e+308 +#define DBL_MAX_10_EXP 308 +#define DBL_MAX_EXP 1024 +#define DBL_MIN 2.22507385850720138309e-308 +#define DBL_MIN_10_EXP (-307) +#define DBL_MIN_EXP (-1021) +#define DBL_TRUE_MIN 4.94065645841246544177e-324 +#define DECIMAL_DIG 36 +#define DELAYTIMER_MAX 0x7fffffff +#define DELETE ns_uop_delete +#define DEV_BSIZE 512 +#define DIRTYPE '5' +#define DM 242 +#define DMAXEXP DBL_MAX_EXP +#define DMINEXP DBL_MIN_EXP +#define DO 253 +#define DONT 254 +#define DOUBLEBITS (sizeof(double) * 8) +#define DTTOIF(x) (__wasilibc_dttoif(x)) +#define DT_BLK 1 +#define DT_CHR 2 +#define DT_DIR 3 +#define DT_FIFO 6 +#define DT_LNK 7 +#define DT_REG 4 +#define DT_SOCK 20 +#define DT_UNKNOWN 0 +#define D_FMT 0x20029 +#define D_T_FMT 0x20028 +#define E2BIG 1 +#define EACCES 2 +#define EACCESS 2 +#define EADDRINUSE 3 +#define EADDRNOTAVAIL 4 +#define EAFNOSUPPORT 5 +#define EAGAIN 6 +#define EAI_ADDRFAMILY -9 +#define EAI_AGAIN -3 +#define EAI_ALLDONE -103 +#define EAI_BADFLAGS -1 +#define EAI_CANCELED -101 +#define EAI_FAIL -4 +#define EAI_FAMILY -6 +#define EAI_IDN_ENCODE -105 +#define EAI_INPROGRESS -100 +#define EAI_INTR -104 +#define EAI_MEMORY -10 +#define EAI_NODATA -5 +#define EAI_NONAME -2 +#define EAI_NOTCANCELED -102 +#define EAI_OVERFLOW -12 +#define EAI_SERVICE -8 +#define EAI_SOCKTYPE -7 +#define EAI_SYSTEM -11 +#define EALREADY 7 +#define EBADF 8 +#define EBADID 5 +#define EBADMSG 9 +#define EBADOP 4 +#define EBUSY 10 +#define EC 247 +#define ECANCELED 11 +#define ECHILD 12 +#define ECONNABORTED 13 +#define ECONNREFUSED 14 +#define ECONNRESET 15 +#define EDEADLK 16 +#define EDESTADDRREQ 17 +#define EDOM 18 +#define EDQUOT 19 +#define EEXIST 20 +#define EEXISTS 6 +#define EFAULT 21 +#define EFBIG 22 +#define EFD_CLOEXEC O_CLOEXEC +#define EFD_NONBLOCK O_NONBLOCK +#define EFD_SEMAPHORE 1 +#define EHOSTUNREACH 23 +#define EIDRM 24 +#define EILSEQ 25 +#define EINPROGRESS 26 +#define EINTR 27 +#define EINVAL 28 +#define EIO 29 +#define EISCONN 30 +#define EISDIR 31 +#define EL 248 +#define ELOOP 32 +#define EMFILE 33 +#define EMLINK 34 +#define EMSGSIZE 35 +#define EMULTIHOP 36 +#define ENAMETOOLONG 37 +#define ENCRYPT_CNT 9 +#define ENCRYPT_DEC_KEYID 8 +#define ENCRYPT_ENC_KEYID 7 +#define ENCRYPT_END 4 +#define ENCRYPT_IS 0 +#define ENCRYPT_NAME(x) encrypt_names[x] +#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT) +#define ENCRYPT_REPLY 2 +#define ENCRYPT_REQEND 6 +#define ENCRYPT_REQSTART 5 +#define ENCRYPT_START 3 +#define ENCRYPT_SUPPORT 1 +#define ENCTYPE_ANY 0 +#define ENCTYPE_CNT 3 +#define ENCTYPE_DES_CFB64 1 +#define ENCTYPE_DES_OFB64 2 +#define ENCTYPE_NAME(x) enctype_names[x] +#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT) +#define ENETDOWN 38 +#define ENETRESET 39 +#define ENETUNREACH 40 +#define ENFILE 41 +#define ENOBUFS 42 +#define ENODEV 43 +#define ENOENT 44 +#define ENOEXEC 45 +#define ENOLCK 46 +#define ENOLINK 47 +#define ENOMEM 48 +#define ENOMSG 49 +#define ENOPROTOOPT 50 +#define ENOSPACE 3 +#define ENOSPC 51 +#define ENOSYS 52 +#define ENOTCAPABLE 76 +#define ENOTCONN 53 +#define ENOTDIR 54 +#define ENOTEMPTY 55 +#define ENOTFOUND 1 +#define ENOTRECOVERABLE 56 +#define ENOTSOCK 57 +#define ENOTSUP 58 +#define ENOTTY 59 +#define ENOUSER 7 +#define ENV_ESC 2 +#define ENV_USERVAR 3 +#define ENXIO 60 +#define EOF (-1) +#define EOPNOTSUPP ENOTSUP +#define EOR 239 +#define EOVERFLOW 61 +#define EOWNERDEAD 62 +#define EPERM 63 +#define EPIPE 64 +#define EPROTO 65 +#define EPROTONOSUPPORT 66 +#define EPROTOTYPE 67 +#define ERA 0x2002C +#define ERANGE 68 +#define ERA_D_FMT 0x2002E +#define ERA_D_T_FMT 0x20030 +#define ERA_T_FMT 0x20031 +#define EROFS 69 +#define ERROR 05 +#define ESPIPE 70 +#define ESRCH 71 +#define ESTALE 72 +#define ETIMEDOUT 73 +#define ETXTBSY 74 +#define EUNDEF 0 +#define EWOULDBLOCK EAGAIN +#define EXDEV 75 +#define EXIT_FAILURE 1 +#define EXIT_SUCCESS 0 +#define EX_CANTCREAT 73 +#define EX_CONFIG 78 +#define EX_DATAERR 65 +#define EX_IOERR 74 +#define EX_NOHOST 68 +#define EX_NOINPUT 66 +#define EX_NOPERM 77 +#define EX_NOUSER 67 +#define EX_OK 0 +#define EX_OSERR 71 +#define EX_OSFILE 72 +#define EX_PROTOCOL 76 +#define EX_SOFTWARE 70 +#define EX_TEMPFAIL 75 +#define EX_UNAVAILABLE 69 +#define EX_USAGE 64 +#define EX__BASE 64 +#define EX__MAX 78 +#define FD_CLOEXEC (1) +#define FD_CLR(fd,set) (FD_CLR((fd), (set))) +#define FD_COPY(from,to) (FD_COPY((from), (to))) +#define FD_ISSET(fd,set) (FD_ISSET((fd), (set))) +#define FD_SET(fd,set) (FD_SET((fd), (set))) +#define FD_SETSIZE 1024 +#define FD_ZERO(set) (FD_ZERO((set))) +#define FE_ALL_EXCEPT 0 +#define FE_DFL_ENV ((const fenv_t *) -1) +#define FE_TONEAREST 0 +#define FIFOTYPE '6' +#define FILENAME_MAX 4096 +#define FILESIZEBITS 64 +#define FILESYSTEM_ADVICE_DONT_NEED 4 +#define FILESYSTEM_ADVICE_NORMAL 0 +#define FILESYSTEM_ADVICE_NO_REUSE 5 +#define FILESYSTEM_ADVICE_RANDOM 2 +#define FILESYSTEM_ADVICE_SEQUENTIAL 1 +#define FILESYSTEM_ADVICE_WILL_NEED 3 +#define FILESYSTEM_DESCRIPTOR_FLAGS_DATA_INTEGRITY_SYNC (1 << 3) +#define FILESYSTEM_DESCRIPTOR_FLAGS_FILE_INTEGRITY_SYNC (1 << 2) +#define FILESYSTEM_DESCRIPTOR_FLAGS_MUTATE_DIRECTORY (1 << 5) +#define FILESYSTEM_DESCRIPTOR_FLAGS_READ (1 << 0) +#define FILESYSTEM_DESCRIPTOR_FLAGS_REQUESTED_WRITE_SYNC (1 << 4) +#define FILESYSTEM_DESCRIPTOR_FLAGS_WRITE (1 << 1) +#define FILESYSTEM_DESCRIPTOR_TYPE_BLOCK_DEVICE 1 +#define FILESYSTEM_DESCRIPTOR_TYPE_CHARACTER_DEVICE 2 +#define FILESYSTEM_DESCRIPTOR_TYPE_DIRECTORY 3 +#define FILESYSTEM_DESCRIPTOR_TYPE_FIFO 4 +#define FILESYSTEM_DESCRIPTOR_TYPE_REGULAR_FILE 6 +#define FILESYSTEM_DESCRIPTOR_TYPE_SOCKET 7 +#define FILESYSTEM_DESCRIPTOR_TYPE_SYMBOLIC_LINK 5 +#define FILESYSTEM_DESCRIPTOR_TYPE_UNKNOWN 0 +#define FILESYSTEM_ERROR_CODE_ACCESS 0 +#define FILESYSTEM_ERROR_CODE_ALREADY 1 +#define FILESYSTEM_ERROR_CODE_BAD_DESCRIPTOR 2 +#define FILESYSTEM_ERROR_CODE_BUSY 3 +#define FILESYSTEM_ERROR_CODE_CROSS_DEVICE 35 +#define FILESYSTEM_ERROR_CODE_DEADLOCK 4 +#define FILESYSTEM_ERROR_CODE_EXIST 6 +#define FILESYSTEM_ERROR_CODE_FILE_TOO_LARGE 7 +#define FILESYSTEM_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE 8 +#define FILESYSTEM_ERROR_CODE_INSUFFICIENT_MEMORY 21 +#define FILESYSTEM_ERROR_CODE_INSUFFICIENT_SPACE 22 +#define FILESYSTEM_ERROR_CODE_INTERRUPTED 10 +#define FILESYSTEM_ERROR_CODE_INVALID 11 +#define FILESYSTEM_ERROR_CODE_INVALID_SEEK 33 +#define FILESYSTEM_ERROR_CODE_IN_PROGRESS 9 +#define FILESYSTEM_ERROR_CODE_IO 12 +#define FILESYSTEM_ERROR_CODE_IS_DIRECTORY 13 +#define FILESYSTEM_ERROR_CODE_LOOP 14 +#define FILESYSTEM_ERROR_CODE_MESSAGE_SIZE 16 +#define FILESYSTEM_ERROR_CODE_NAME_TOO_LONG 17 +#define FILESYSTEM_ERROR_CODE_NOT_DIRECTORY 23 +#define FILESYSTEM_ERROR_CODE_NOT_EMPTY 24 +#define FILESYSTEM_ERROR_CODE_NOT_PERMITTED 30 +#define FILESYSTEM_ERROR_CODE_NOT_RECOVERABLE 25 +#define FILESYSTEM_ERROR_CODE_NO_DEVICE 18 +#define FILESYSTEM_ERROR_CODE_NO_ENTRY 19 +#define FILESYSTEM_ERROR_CODE_NO_LOCK 20 +#define FILESYSTEM_ERROR_CODE_NO_SUCH_DEVICE 28 +#define FILESYSTEM_ERROR_CODE_NO_TTY 27 +#define FILESYSTEM_ERROR_CODE_OVERFLOW 29 +#define FILESYSTEM_ERROR_CODE_PIPE 31 +#define FILESYSTEM_ERROR_CODE_QUOTA 5 +#define FILESYSTEM_ERROR_CODE_READ_ONLY 32 +#define FILESYSTEM_ERROR_CODE_TEXT_FILE_BUSY 34 +#define FILESYSTEM_ERROR_CODE_TOO_MANY_LINKS 15 +#define FILESYSTEM_ERROR_CODE_UNSUPPORTED 26 +#define FILESYSTEM_NEW_TIMESTAMP_NOW 1 +#define FILESYSTEM_NEW_TIMESTAMP_NO_CHANGE 0 +#define FILESYSTEM_NEW_TIMESTAMP_TIMESTAMP 2 +#define FILESYSTEM_OPEN_FLAGS_CREATE (1 << 0) +#define FILESYSTEM_OPEN_FLAGS_DIRECTORY (1 << 1) +#define FILESYSTEM_OPEN_FLAGS_EXCLUSIVE (1 << 2) +#define FILESYSTEM_OPEN_FLAGS_TRUNCATE (1 << 3) +#define FILESYSTEM_PATH_FLAGS_SYMLINK_FOLLOW (1 << 0) +#define FIONBIO 2 +#define FIONREAD 1 +#define FLOATBITS (sizeof(float) * 8) +#define FLT_DECIMAL_DIG 9 +#define FLT_DIG 6 +#define FLT_EPSILON 1.1920928955078125e-07F +#define FLT_EVAL_METHOD 0 +#define FLT_HAS_SUBNORM 1 +#define FLT_MANT_DIG 24 +#define FLT_MAX 3.40282346638528859812e+38F +#define FLT_MAX_10_EXP 38 +#define FLT_MAX_EXP 128 +#define FLT_MIN 1.17549435082228750797e-38F +#define FLT_MIN_10_EXP (-37) +#define FLT_MIN_EXP (-125) +#define FLT_RADIX 2 +#define FLT_ROUNDS (__builtin_flt_rounds()) +#define FLT_TRUE_MIN 1.40129846432481707092e-45F +#define FLUSHBAND 0x04 +#define FLUSHR 0x01 +#define FLUSHRW 0x03 +#define FLUSHW 0x02 +#define FMAXEXP FLT_MAX_EXP +#define FMINEXP FLT_MIN_EXP +#define FMNAMESZ 8 +#define FNM_CASEFOLD 0x10 +#define FNM_FILE_NAME FNM_PATHNAME +#define FNM_LEADING_DIR 0x8 +#define FNM_NOESCAPE 0x2 +#define FNM_NOMATCH 1 +#define FNM_NOSYS (-1) +#define FNM_PATHNAME 0x1 +#define FNM_PERIOD 0x4 +#define FOPEN_MAX 1000 +#define FORMERR ns_r_formerr +#define FORM_C 3 +#define FORM_N 1 +#define FORM_T 2 +#define FP_ILOGB0 FP_ILOGBNAN +#define FP_ILOGBNAN (-1-0x7fffffff) +#define FP_INFINITE 1 +#define FP_NAN 0 +#define FP_NORMAL 4 +#define FP_SUBNORMAL 3 +#define FP_ZERO 2 +#define FSETLOCKING_BYCALLER 2 +#define FSETLOCKING_INTERNAL 1 +#define FSETLOCKING_QUERY 0 +#define FTS_AGAIN 1 +#define FTS_COMFOLLOW 0x001 +#define FTS_D 1 +#define FTS_DC 2 +#define FTS_DEFAULT 3 +#define FTS_DNR 4 +#define FTS_DONTCHDIR 0x01 +#define FTS_DOT 5 +#define FTS_DP 6 +#define FTS_ERR 7 +#define FTS_F 8 +#define FTS_FOLLOW 2 +#define FTS_INIT 9 +#define FTS_ISW 0x04 +#define FTS_LOGICAL 0x002 +#define FTS_NAMEONLY 0x100 +#define FTS_NOCHDIR 0x004 +#define FTS_NOINSTR 3 +#define FTS_NOSTAT 0x008 +#define FTS_NS 10 +#define FTS_NSOK 11 +#define FTS_OPTIONMASK 0x0ff +#define FTS_PHYSICAL 0x010 +#define FTS_ROOTLEVEL 0 +#define FTS_ROOTPARENTLEVEL -1 +#define FTS_SEEDOT 0x020 +#define FTS_SKIP 4 +#define FTS_SL 12 +#define FTS_SLNONE 13 +#define FTS_STOP 0x200 +#define FTS_SYMFOLLOW 0x02 +#define FTS_W 14 +#define FTS_WHITEOUT 0x080 +#define FTS_XDEV 0x040 +#define FTW_CHDIR 4 +#define FTW_D 2 +#define FTW_DEPTH 8 +#define FTW_DNR 3 +#define FTW_DP 6 +#define FTW_F 1 +#define FTW_MOUNT 2 +#define FTW_NS 4 +#define FTW_PHYS 1 +#define FTW_SL 5 +#define FTW_SLN 7 +#define F_GETFD (1) +#define F_GETFL (3) +#define F_LOCK 1 +#define F_OK (0) +#define F_SETFD (2) +#define F_SETFL (4) +#define F_TEST 3 +#define F_TLOCK 2 +#define F_ULOCK 0 +#define GA 249 +#define GETLONG NS_GET32 +#define GETSHORT NS_GET16 +#define GLOB_ABORTED 2 +#define GLOB_APPEND 0x20 +#define GLOB_DOOFFS 0x08 +#define GLOB_ERR 0x01 +#define GLOB_MARK 0x02 +#define GLOB_NOCHECK 0x10 +#define GLOB_NOESCAPE 0x40 +#define GLOB_NOMATCH 3 +#define GLOB_NOSORT 0x04 +#define GLOB_NOSPACE 1 +#define GLOB_NOSYS 4 +#define GLOB_PERIOD 0x80 +#define GROUP_FILTER_SIZE(numsrc) (sizeof(struct group_filter) - sizeof(struct sockaddr_storage) + (numsrc) * sizeof(struct sockaddr_storage)) +#define HFIXEDSZ NS_HFIXEDSZ +#define HIBITL MINLONG +#define HIBITS MINSHORT +#define HOST_NAME_MAX 255 +#define HOST_NOT_FOUND 1 +#define HUGE 3.40282346638528859812e+38F +#define HUGE_VAL ((double)INFINITY) +#define HUGE_VALF INFINITY +#define HUGE_VALL ((long double)INFINITY) +#define I _Complex_I +#define IAC 255 +#define ICMP6_DST_UNREACH 1 +#define ICMP6_DST_UNREACH_ADDR 3 +#define ICMP6_DST_UNREACH_ADMIN 1 +#define ICMP6_DST_UNREACH_BEYONDSCOPE 2 +#define ICMP6_DST_UNREACH_NOPORT 4 +#define ICMP6_DST_UNREACH_NOROUTE 0 +#define ICMP6_ECHO_REPLY 129 +#define ICMP6_ECHO_REQUEST 128 +#define ICMP6_FILTER 1 +#define ICMP6_FILTER_BLOCK 1 +#define ICMP6_FILTER_BLOCKOTHERS 3 +#define ICMP6_FILTER_PASS 2 +#define ICMP6_FILTER_PASSONLY 4 +#define ICMP6_FILTER_SETBLOCK(type,filterp) ((((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))) +#define ICMP6_FILTER_SETBLOCKALL(filterp) memset (filterp, 0xFF, sizeof (struct icmp6_filter)); +#define ICMP6_FILTER_SETPASS(type,filterp) ((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))) +#define ICMP6_FILTER_SETPASSALL(filterp) memset (filterp, 0, sizeof (struct icmp6_filter)); +#define ICMP6_FILTER_WILLBLOCK(type,filterp) ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0) +#define ICMP6_FILTER_WILLPASS(type,filterp) ((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0) +#define ICMP6_INFOMSG_MASK 0x80 +#define ICMP6_PACKET_TOO_BIG 2 +#define ICMP6_PARAMPROB_HEADER 0 +#define ICMP6_PARAMPROB_NEXTHEADER 1 +#define ICMP6_PARAMPROB_OPTION 2 +#define ICMP6_PARAM_PROB 4 +#define ICMP6_ROUTER_RENUMBERING 138 +#define ICMP6_RR_FLAGS_FORCEAPPLY 0x20 +#define ICMP6_RR_FLAGS_PREVDONE 0x08 +#define ICMP6_RR_FLAGS_REQRESULT 0x40 +#define ICMP6_RR_FLAGS_SPECSITE 0x10 +#define ICMP6_RR_FLAGS_TEST 0x80 +#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40 +#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80 +#define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x10 +#define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x20 +#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100 +#define ICMP6_RR_RESULT_FLAGS_OOB 0x0200 +#define ICMP6_TIME_EXCEEDED 3 +#define ICMP6_TIME_EXCEED_REASSEMBLY 1 +#define ICMP6_TIME_EXCEED_TRANSIT 0 +#define ICMP_ADDRESS 17 +#define ICMP_ADDRESSREPLY 18 +#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) +#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) +#define ICMP_DEST_UNREACH 3 +#define ICMP_ECHO 8 +#define ICMP_ECHOREPLY 0 +#define ICMP_EXC_FRAGTIME 1 +#define ICMP_EXC_TTL 0 +#define ICMP_FRAG_NEEDED 4 +#define ICMP_HOST_ANO 10 +#define ICMP_HOST_ISOLATED 8 +#define ICMP_HOST_UNKNOWN 7 +#define ICMP_HOST_UNREACH 1 +#define ICMP_HOST_UNR_TOS 12 +#define ICMP_INFOTYPE(type) ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) +#define ICMP_INFO_REPLY 16 +#define ICMP_INFO_REQUEST 15 +#define ICMP_IREQ 15 +#define ICMP_IREQREPLY 16 +#define ICMP_MASKLEN 12 +#define ICMP_MASKREPLY 18 +#define ICMP_MASKREQ 17 +#define ICMP_MAXTYPE 18 +#define ICMP_MINLEN 8 +#define ICMP_NET_ANO 9 +#define ICMP_NET_UNKNOWN 6 +#define ICMP_NET_UNREACH 0 +#define ICMP_NET_UNR_TOS 11 +#define ICMP_PARAMETERPROB 12 +#define ICMP_PARAMPROB 12 +#define ICMP_PARAMPROB_OPTABSENT 1 +#define ICMP_PKT_FILTERED 13 +#define ICMP_PORT_UNREACH 3 +#define ICMP_PREC_CUTOFF 15 +#define ICMP_PREC_VIOLATION 14 +#define ICMP_PROT_UNREACH 2 +#define ICMP_REDIRECT 5 +#define ICMP_REDIRECT_HOST 1 +#define ICMP_REDIRECT_NET 0 +#define ICMP_REDIRECT_TOSHOST 3 +#define ICMP_REDIRECT_TOSNET 2 +#define ICMP_REDIR_HOST 1 +#define ICMP_REDIR_HOSTTOS 3 +#define ICMP_REDIR_NET 0 +#define ICMP_REDIR_NETTOS 2 +#define ICMP_ROUTERADVERT 9 +#define ICMP_ROUTERSOLICIT 10 +#define ICMP_SOURCEQUENCH 4 +#define ICMP_SOURCE_QUENCH 4 +#define ICMP_SR_FAILED 5 +#define ICMP_TIMESTAMP 13 +#define ICMP_TIMESTAMPREPLY 14 +#define ICMP_TIME_EXCEEDED 11 +#define ICMP_TIMXCEED 11 +#define ICMP_TIMXCEED_INTRANS 0 +#define ICMP_TIMXCEED_REASS 1 +#define ICMP_TSLEN (8 + 3 * sizeof (n_time)) +#define ICMP_TSTAMP 13 +#define ICMP_TSTAMPREPLY 14 +#define ICMP_UNREACH 3 +#define ICMP_UNREACH_FILTER_PROHIB 13 +#define ICMP_UNREACH_HOST 1 +#define ICMP_UNREACH_HOST_PRECEDENCE 14 +#define ICMP_UNREACH_HOST_PROHIB 10 +#define ICMP_UNREACH_HOST_UNKNOWN 7 +#define ICMP_UNREACH_ISOLATED 8 +#define ICMP_UNREACH_NEEDFRAG 4 +#define ICMP_UNREACH_NET 0 +#define ICMP_UNREACH_NET_PROHIB 9 +#define ICMP_UNREACH_NET_UNKNOWN 6 +#define ICMP_UNREACH_PORT 3 +#define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 +#define ICMP_UNREACH_PROTOCOL 2 +#define ICMP_UNREACH_SRCFAIL 5 +#define ICMP_UNREACH_TOSHOST 12 +#define ICMP_UNREACH_TOSNET 11 +#define IFTODT(x) (__wasilibc_iftodt(x)) +#define IGMP_AWAKENING_MEMBER 5 +#define IGMP_DELAYING_MEMBER 1 +#define IGMP_DVMRP 0x13 +#define IGMP_HOST_LEAVE_MESSAGE IGMP_V2_LEAVE_GROUP +#define IGMP_HOST_MEMBERSHIP_QUERY IGMP_MEMBERSHIP_QUERY +#define IGMP_HOST_MEMBERSHIP_REPORT IGMP_V1_MEMBERSHIP_REPORT +#define IGMP_HOST_NEW_MEMBERSHIP_REPORT IGMP_V2_MEMBERSHIP_REPORT +#define IGMP_IDLE_MEMBER 2 +#define IGMP_LAZY_MEMBER 3 +#define IGMP_MAX_HOST_REPORT_DELAY 10 +#define IGMP_MEMBERSHIP_QUERY 0x11 +#define IGMP_MINLEN 8 +#define IGMP_MTRACE 0x1f +#define IGMP_MTRACE_RESP 0x1e +#define IGMP_PIM 0x14 +#define IGMP_SLEEPING_MEMBER 4 +#define IGMP_TIMER_SCALE 10 +#define IGMP_TRACE 0x15 +#define IGMP_V1_MEMBERSHIP_REPORT 0x12 +#define IGMP_V2_LEAVE_GROUP 0x17 +#define IGMP_V2_MEMBERSHIP_REPORT 0x16 +#define IGMP_v1_ROUTER 1 +#define IGMP_v2_ROUTER 2 +#define IN6ADDRSZ NS_IN6ADDRSZ +#define IN6ADDR_ANY_INIT { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } +#define IN6ADDR_LOOPBACK_INIT { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } } +#define IN6_ARE_ADDR_EQUAL(a,b) __ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b)) +#define IN6_IS_ADDR_LINKLOCAL(a) ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80) +#define IN6_IS_ADDR_LOOPBACK(a) (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[12] == 0 && ((uint8_t *) (a))[13] == 0 && ((uint8_t *) (a))[14] == 0 && ((uint8_t *) (a))[15] == 1 ) +#define IN6_IS_ADDR_MC_GLOBAL(a) (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe)) +#define IN6_IS_ADDR_MC_LINKLOCAL(a) (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2)) +#define IN6_IS_ADDR_MC_NODELOCAL(a) (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1)) +#define IN6_IS_ADDR_MC_ORGLOCAL(a) (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8)) +#define IN6_IS_ADDR_MC_SITELOCAL(a) (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5)) +#define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff) +#define IN6_IS_ADDR_SITELOCAL(a) ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0) +#define IN6_IS_ADDR_UNSPECIFIED(a) (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && ((uint32_t *) (a))[2] == 0 && ((uint32_t *) (a))[3] == 0) +#define IN6_IS_ADDR_V4COMPAT(a) (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[15] > 1) +#define IN6_IS_ADDR_V4MAPPED(a) (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && ((uint8_t *) (a))[8] == 0 && ((uint8_t *) (a))[9] == 0 && ((uint8_t *) (a))[10] == 0xff && ((uint8_t *) (a))[11] == 0xff) +#define INADDRSZ NS_INADDRSZ +#define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) +#define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) +#define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a) +#define INADDR_ANY ((in_addr_t) 0x00000000) +#define INADDR_BROADCAST ((in_addr_t) 0xffffffff) +#define INADDR_DUMMY ((in_addr_t) 0xc0000008) +#define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) +#define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) +#define INADDR_NONE ((in_addr_t) 0xffffffff) +#define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) +#define INDIR_MASK NS_CMPRSFLGS +#define INET6_ADDRSTRLEN 46 +#define INET_ADDRSTRLEN 16 +#define INFINITY 1e5000f +#define INT16SZ NS_INT16SZ +#define INT16_C(c) c +#define INT16_MAX (0x7fff) +#define INT16_MIN (-1-0x7fff) +#define INT32SZ NS_INT32SZ +#define INT32_C(c) c +#define INT32_MAX (0x7fffffff) +#define INT32_MIN (-1-0x7fffffff) +#define INT64_C(c) c ## LL +#define INT64_MAX (0x7fffffffffffffff) +#define INT64_MIN (-1-0x7fffffffffffffff) +#define INT8SZ NS_INT8SZ +#define INT8_C(c) c +#define INT8_MAX (0x7f) +#define INT8_MIN (-1-0x7f) +#define INTBITS (sizeof(int) * 8) +#define INTMAX_C(c) c ## LL +#define INTMAX_MAX INT64_MAX +#define INTMAX_MIN INT64_MIN +#define INTPTR_MAX INT32_MAX +#define INTPTR_MIN INT32_MIN +#define INT_FAST16_MAX INT16_MAX +#define INT_FAST16_MIN INT16_MIN +#define INT_FAST32_MAX INT32_MAX +#define INT_FAST32_MIN INT32_MIN +#define INT_FAST64_MAX INT64_MAX +#define INT_FAST64_MIN INT64_MIN +#define INT_FAST8_MAX INT8_MAX +#define INT_FAST8_MIN INT8_MIN +#define INT_LEAST16_MAX INT16_MAX +#define INT_LEAST16_MIN INT16_MIN +#define INT_LEAST32_MAX INT32_MAX +#define INT_LEAST32_MIN INT32_MIN +#define INT_LEAST64_MAX INT64_MAX +#define INT_LEAST64_MIN INT64_MIN +#define INT_LEAST8_MAX INT8_MAX +#define INT_LEAST8_MIN INT8_MIN +#define INT_MAX 0x7fffffff +#define INT_MIN (-1-0x7fffffff) +#define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000) +#define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0) +#define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET) +#define IN_CLASSA_MAX 128 +#define IN_CLASSA_NET 0xff000000 +#define IN_CLASSA_NSHIFT 24 +#define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000) +#define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET) +#define IN_CLASSB_MAX 65536 +#define IN_CLASSB_NET 0xffff0000 +#define IN_CLASSB_NSHIFT 16 +#define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000) +#define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET) +#define IN_CLASSC_NET 0xffffff00 +#define IN_CLASSC_NSHIFT 8 +#define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000) +#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000) +#define IN_LOOPBACKNET 127 +#define IN_MULTICAST(a) IN_CLASSD(a) +#define IOV_MAX 1024 +#define IP 244 +#define IP6F_MORE_FRAG 0x0100 +#define IP6F_OFF_MASK 0xf8ff +#define IP6F_RESERVED_MASK 0x0600 +#define IP6OPT_JUMBO 0xc2 +#define IP6OPT_JUMBO_LEN 6 +#define IP6OPT_NSAP_ADDR 0xc3 +#define IP6OPT_PAD1 0 +#define IP6OPT_PADN 1 +#define IP6OPT_ROUTER_ALERT 0x05 +#define IP6OPT_TUNNEL_LIMIT 0x04 +#define IP6OPT_TYPE(o) ((o) & 0xc0) +#define IP6OPT_TYPE_DISCARD 0x40 +#define IP6OPT_TYPE_FORCEICMP 0x80 +#define IP6OPT_TYPE_ICMP 0xc0 +#define IP6OPT_TYPE_MUTABLE 0x20 +#define IP6OPT_TYPE_SKIP 0x00 +#define IP6_ALERT_AN 0x0200 +#define IP6_ALERT_MLD 0x0000 +#define IP6_ALERT_RSVP 0x0100 +#define IPDEFTTL 64 +#define IPFRAGTTL 60 +#define IPOPT_CLASS(o) ((o) & IPOPT_CLASS_MASK) +#define IPOPT_CLASS_MASK 0x60 +#define IPOPT_CONTROL 0x00 +#define IPOPT_COPIED(o) ((o) & IPOPT_COPY) +#define IPOPT_COPY 0x80 +#define IPOPT_DEBMEAS 0x40 +#define IPOPT_END IPOPT_EOL +#define IPOPT_EOL 0 +#define IPOPT_LSRR 131 +#define IPOPT_MEASUREMENT IPOPT_DEBMEAS +#define IPOPT_MINOFF 4 +#define IPOPT_NOOP IPOPT_NOP +#define IPOPT_NOP 1 +#define IPOPT_NUMBER(o) ((o) & IPOPT_NUMBER_MASK) +#define IPOPT_NUMBER_MASK 0x1f +#define IPOPT_OFFSET 2 +#define IPOPT_OLEN 1 +#define IPOPT_OPTVAL 0 +#define IPOPT_RA 148 +#define IPOPT_RESERVED1 0x20 +#define IPOPT_RESERVED2 0x60 +#define IPOPT_RR 7 +#define IPOPT_SATID 136 +#define IPOPT_SEC IPOPT_SECURITY +#define IPOPT_SECURITY 130 +#define IPOPT_SECUR_CONFID 0xf135 +#define IPOPT_SECUR_EFTO 0x789a +#define IPOPT_SECUR_MMMM 0xbc4d +#define IPOPT_SECUR_RESTR 0xaf13 +#define IPOPT_SECUR_SECRET 0xd788 +#define IPOPT_SECUR_TOPSECRET 0x6bc5 +#define IPOPT_SECUR_UNCLASS 0x0000 +#define IPOPT_SID IPOPT_SATID +#define IPOPT_SSRR 137 +#define IPOPT_TIMESTAMP IPOPT_TS +#define IPOPT_TS 68 +#define IPOPT_TS_PRESPEC 3 +#define IPOPT_TS_TSANDADDR 1 +#define IPOPT_TS_TSONLY 0 +#define IPPORT_RESERVED 1024 +#define IPPROTO_ICMP 1 +#define IPPROTO_IP 0 +#define IPPROTO_IPV6 41 +#define IPPROTO_RAW 255 +#define IPPROTO_TCP 6 +#define IPPROTO_UDP 17 +#define IPTOS_CLASS(x) ((x) & IPTOS_CLASS_MASK) +#define IPTOS_CLASS_CS0 0x00 +#define IPTOS_CLASS_CS1 0x20 +#define IPTOS_CLASS_CS2 0x40 +#define IPTOS_CLASS_CS3 0x60 +#define IPTOS_CLASS_CS4 0x80 +#define IPTOS_CLASS_CS5 0xa0 +#define IPTOS_CLASS_CS6 0xc0 +#define IPTOS_CLASS_CS7 0xe0 +#define IPTOS_CLASS_DEFAULT IPTOS_CLASS_CS0 +#define IPTOS_CLASS_MASK 0xe0 +#define IPTOS_DSCP(x) ((x) & IPTOS_DSCP_MASK) +#define IPTOS_DSCP_AF11 0x28 +#define IPTOS_DSCP_AF12 0x30 +#define IPTOS_DSCP_AF13 0x38 +#define IPTOS_DSCP_AF21 0x48 +#define IPTOS_DSCP_AF22 0x50 +#define IPTOS_DSCP_AF23 0x58 +#define IPTOS_DSCP_AF31 0x68 +#define IPTOS_DSCP_AF32 0x70 +#define IPTOS_DSCP_AF33 0x78 +#define IPTOS_DSCP_AF41 0x88 +#define IPTOS_DSCP_AF42 0x90 +#define IPTOS_DSCP_AF43 0x98 +#define IPTOS_DSCP_EF 0xb8 +#define IPTOS_DSCP_MASK 0xfc +#define IPTOS_ECN(x) ((x) & IPTOS_ECN_MASK) +#define IPTOS_ECN_CE 0x03 +#define IPTOS_ECN_ECT0 0x02 +#define IPTOS_ECN_ECT1 0x01 +#define IPTOS_ECN_MASK 0x03 +#define IPTOS_ECN_NOT_ECT 0x00 +#define IPTOS_LOWCOST 0x02 +#define IPTOS_LOWDELAY 0x10 +#define IPTOS_MINCOST IPTOS_LOWCOST +#define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) +#define IPTOS_PREC_CRITIC_ECP 0xa0 +#define IPTOS_PREC_FLASH 0x60 +#define IPTOS_PREC_FLASHOVERRIDE 0x80 +#define IPTOS_PREC_IMMEDIATE 0x40 +#define IPTOS_PREC_INTERNETCONTROL 0xc0 +#define IPTOS_PREC_MASK 0xe0 +#define IPTOS_PREC_NETCONTROL 0xe0 +#define IPTOS_PREC_PRIORITY 0x20 +#define IPTOS_PREC_ROUTINE 0x00 +#define IPTOS_RELIABILITY 0x04 +#define IPTOS_THROUGHPUT 0x08 +#define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK) +#define IPTOS_TOS_MASK 0x1E +#define IPTTLDEC 1 +#define IPV6_2292DSTOPTS 4 +#define IPV6_2292HOPLIMIT 8 +#define IPV6_2292HOPOPTS 3 +#define IPV6_2292PKTINFO 2 +#define IPV6_2292PKTOPTIONS 6 +#define IPV6_2292RTHDR 5 +#define IPV6_ADDRFORM 1 +#define IPV6_ADDR_PREFERENCES 72 +#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP +#define IPV6_AUTHHDR 10 +#define IPV6_AUTOFLOWLABEL 70 +#define IPV6_CHECKSUM 7 +#define IPV6_DONTFRAG 62 +#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP +#define IPV6_DSTOPTS 59 +#define IPV6_FREEBIND 78 +#define IPV6_HDRINCL 36 +#define IPV6_HOPLIMIT 52 +#define IPV6_HOPOPTS 54 +#define IPV6_IPSEC_POLICY 34 +#define IPV6_JOIN_ANYCAST 27 +#define IPV6_JOIN_GROUP 20 +#define IPV6_LEAVE_ANYCAST 28 +#define IPV6_LEAVE_GROUP 21 +#define IPV6_MINHOPCOUNT 73 +#define IPV6_MTU 24 +#define IPV6_MTU_DISCOVER 23 +#define IPV6_MULTICAST_ALL 29 +#define IPV6_MULTICAST_HOPS 18 +#define IPV6_MULTICAST_IF 17 +#define IPV6_MULTICAST_LOOP 19 +#define IPV6_NEXTHOP 9 +#define IPV6_ORIGDSTADDR 74 +#define IPV6_PATHMTU 61 +#define IPV6_PKTINFO 50 +#define IPV6_PMTUDISC_DO 2 +#define IPV6_PMTUDISC_DONT 0 +#define IPV6_PMTUDISC_INTERFACE 4 +#define IPV6_PMTUDISC_OMIT 5 +#define IPV6_PMTUDISC_PROBE 3 +#define IPV6_PMTUDISC_WANT 1 +#define IPV6_PREFER_SRC_CGA 0x0008 +#define IPV6_PREFER_SRC_COA 0x0004 +#define IPV6_PREFER_SRC_HOME 0x0400 +#define IPV6_PREFER_SRC_NONCGA 0x0800 +#define IPV6_PREFER_SRC_PUBLIC 0x0002 +#define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100 +#define IPV6_PREFER_SRC_TMP 0x0001 +#define IPV6_RECVDSTOPTS 58 +#define IPV6_RECVERR 25 +#define IPV6_RECVFRAGSIZE 77 +#define IPV6_RECVHOPLIMIT 51 +#define IPV6_RECVHOPOPTS 53 +#define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR +#define IPV6_RECVPATHMTU 60 +#define IPV6_RECVPKTINFO 49 +#define IPV6_RECVRTHDR 56 +#define IPV6_RECVTCLASS 66 +#define IPV6_ROUTER_ALERT 22 +#define IPV6_ROUTER_ALERT_ISOLATE 30 +#define IPV6_RTHDR 57 +#define IPV6_RTHDRDSTOPTS 55 +#define IPV6_RTHDR_LOOSE 0 +#define IPV6_RTHDR_STRICT 1 +#define IPV6_RTHDR_TYPE_0 0 +#define IPV6_RXDSTOPTS IPV6_DSTOPTS +#define IPV6_RXHOPOPTS IPV6_HOPOPTS +#define IPV6_TCLASS 67 +#define IPV6_TRANSPARENT 75 +#define IPV6_UNICAST_HOPS 16 +#define IPV6_UNICAST_IF 76 +#define IPV6_V6ONLY 26 +#define IPV6_XFRM_POLICY 35 +#define IPVERSION 4 +#define IP_ADD_MEMBERSHIP 35 +#define IP_ADD_SOURCE_MEMBERSHIP 39 +#define IP_BIND_ADDRESS_NO_PORT 24 +#define IP_BLOCK_SOURCE 38 +#define IP_CHECKSUM 23 +#define IP_DEFAULT_MULTICAST_LOOP 1 +#define IP_DEFAULT_MULTICAST_TTL 1 +#define IP_DF 0x4000 +#define IP_DROP_MEMBERSHIP 36 +#define IP_DROP_SOURCE_MEMBERSHIP 40 +#define IP_FREEBIND 15 +#define IP_HDRINCL 3 +#define IP_IPSEC_POLICY 16 +#define IP_MAXPACKET 65535 +#define IP_MAX_MEMBERSHIPS 20 +#define IP_MF 0x2000 +#define IP_MINTTL 21 +#define IP_MSFILTER 41 +#define IP_MSFILTER_SIZE(numsrc) (sizeof(struct ip_msfilter) - sizeof(struct in_addr) + (numsrc) * sizeof(struct in_addr)) +#define IP_MSS 576 +#define IP_MTU 14 +#define IP_MTU_DISCOVER 10 +#define IP_MULTICAST_ALL 49 +#define IP_MULTICAST_IF 32 +#define IP_MULTICAST_LOOP 34 +#define IP_MULTICAST_TTL 33 +#define IP_NAME_LOOKUP_ERROR_CODE_ACCESS_DENIED 1 +#define IP_NAME_LOOKUP_ERROR_CODE_INVALID_ARGUMENT 2 +#define IP_NAME_LOOKUP_ERROR_CODE_NAME_UNRESOLVABLE 3 +#define IP_NAME_LOOKUP_ERROR_CODE_PERMANENT_RESOLVER_FAILURE 5 +#define IP_NAME_LOOKUP_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE 4 +#define IP_NAME_LOOKUP_ERROR_CODE_UNKNOWN 0 +#define IP_NODEFRAG 22 +#define IP_OFFMASK 0x1fff +#define IP_OPTIONS 4 +#define IP_ORIGDSTADDR 20 +#define IP_PASSSEC 18 +#define IP_PKTINFO 8 +#define IP_PKTOPTIONS 9 +#define IP_PMTUDISC 10 +#define IP_PMTUDISC_DO 2 +#define IP_PMTUDISC_DONT 0 +#define IP_PMTUDISC_INTERFACE 4 +#define IP_PMTUDISC_OMIT 5 +#define IP_PMTUDISC_PROBE 3 +#define IP_PMTUDISC_WANT 1 +#define IP_RECVERR 11 +#define IP_RECVERR_RFC4884 26 +#define IP_RECVFRAGSIZE 25 +#define IP_RECVOPTS 6 +#define IP_RECVORIGDSTADDR IP_ORIGDSTADDR +#define IP_RECVRETOPTS IP_RETOPTS +#define IP_RECVTOS 13 +#define IP_RECVTTL 12 +#define IP_RETOPTS 7 +#define IP_RF 0x8000 +#define IP_ROUTER_ALERT 5 +#define IP_TOS 1 +#define IP_TRANSPARENT 19 +#define IP_TTL 2 +#define IP_UNBLOCK_SOURCE 37 +#define IP_UNICAST_IF 50 +#define IP_XFRM_POLICY 17 +#define IQUERY ns_o_iquery +#define I_ATMARK (__SID |31) +#define I_CANPUT (__SID |34) +#define I_CKBAND (__SID |29) +#define I_FDINSERT (__SID |16) +#define I_FIND (__SID |11) +#define I_FLUSH (__SID | 5) +#define I_FLUSHBAND (__SID |28) +#define I_GETBAND (__SID |30) +#define I_GETCLTIME (__SID |33) +#define I_GETSIG (__SID |10) +#define I_GRDOPT (__SID | 7) +#define I_GWROPT (__SID |20) +#define I_LINK (__SID |12) +#define I_LIST (__SID |21) +#define I_LOOK (__SID | 4) +#define I_NREAD (__SID | 1) +#define I_PEEK (__SID |15) +#define I_PLINK (__SID |22) +#define I_POP (__SID | 3) +#define I_PUNLINK (__SID |23) +#define I_PUSH (__SID | 2) +#define I_RECVFD (__SID |14) +#define I_SENDFD (__SID |17) +#define I_SETCLTIME (__SID |32) +#define I_SETSIG (__SID | 9) +#define I_SRDOPT (__SID | 6) +#define I_STR (__SID | 8) +#define I_SWROPT (__SID |19) +#define I_UNLINK (__SID |13) +#define LASTMARK 0x02 +#define LC_ALL 6 +#define LC_ALL_MASK 0x7fffffff +#define LC_COLLATE 3 +#define LC_COLLATE_MASK (1<(b))?(a):(b)) +#define MAXCDNAME NS_MAXCDNAME +#define MAXDNAME NS_MAXDNAME +#define MAXDOUBLE DBL_MAX +#define MAXFLOAT FLT_MAX +#define MAXHOSTNAMELEN 64 +#define MAXINT INT_MAX +#define MAXLABEL NS_MAXLABEL +#define MAXLONG LONG_MAX +#define MAXNAMLEN 255 +#define MAXPATHLEN 4096 +#define MAXSHORT SHRT_MAX +#define MAXSYMLINKS 20 +#define MAXTC 6 +#define MAXTTL 255 +#define MAX_IPOPTLEN 40 +#define MB_CUR_MAX (__ctype_get_mb_cur_max()) +#define MB_LEN_MAX 4 +#define MCAST_BLOCK_SOURCE 43 +#define MCAST_EXCLUDE 0 +#define MCAST_INCLUDE 1 +#define MCAST_JOIN_GROUP 42 +#define MCAST_JOIN_SOURCE_GROUP 46 +#define MCAST_LEAVE_GROUP 45 +#define MCAST_LEAVE_SOURCE_GROUP 47 +#define MCAST_MSFILTER 48 +#define MCAST_UNBLOCK_SOURCE 44 +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MINDOUBLE DBL_MIN +#define MINFLOAT FLT_MIN +#define MININT INT_MIN +#define MINLONG LONG_MIN +#define MINSHORT SHRT_MIN +#define MLD_LISTENER_QUERY 130 +#define MLD_LISTENER_REDUCTION 132 +#define MLD_LISTENER_REPORT 131 +#define MM_APPL 8 +#define MM_CONSOLE 512 +#define MM_ERROR 2 +#define MM_FIRM 4 +#define MM_HALT 1 +#define MM_HARD 1 +#define MM_INFO 4 +#define MM_NOCON 4 +#define MM_NOMSG 1 +#define MM_NOSEV 0 +#define MM_NOTOK (-1) +#define MM_NRECOV 128 +#define MM_NULLACT ((char*)0) +#define MM_NULLLBL ((char*)0) +#define MM_NULLMC 0L +#define MM_NULLSEV 0 +#define MM_NULLTAG ((char*)0) +#define MM_NULLTXT ((char*)0) +#define MM_OK 0 +#define MM_OPSYS 32 +#define MM_PRINT 256 +#define MM_RECOVER 64 +#define MM_SOFT 2 +#define MM_UTIL 16 +#define MM_WARNING 3 +#define MODE_ACK 0x04 +#define MODE_B 2 +#define MODE_C 3 +#define MODE_ECHO 0x0200 +#define MODE_EDIT 0x01 +#define MODE_FLOW 0x0100 +#define MODE_FORCE 0x1000 +#define MODE_INBIN 0x0400 +#define MODE_LIT_ECHO 0x10 +#define MODE_MASK 0x1f +#define MODE_OUTBIN 0x0800 +#define MODE_S 1 +#define MODE_SOFT_TAB 0x08 +#define MODE_TRAPSIG 0x02 +#define MOD_CLKA ADJ_OFFSET_SINGLESHOT +#define MOD_CLKB ADJ_TICK +#define MOD_ESTERROR ADJ_ESTERROR +#define MOD_FREQUENCY ADJ_FREQUENCY +#define MOD_MAXERROR ADJ_MAXERROR +#define MOD_MICRO ADJ_MICRO +#define MOD_NANO ADJ_NANO +#define MOD_OFFSET ADJ_OFFSET +#define MOD_STATUS ADJ_STATUS +#define MOD_TAI ADJ_TAI +#define MOD_TIMECONST ADJ_TIMECONST +#define MON_1 0x2001A +#define MON_10 0x20023 +#define MON_11 0x20024 +#define MON_12 0x20025 +#define MON_2 0x2001B +#define MON_3 0x2001C +#define MON_4 0x2001D +#define MON_5 0x2001E +#define MON_6 0x2001F +#define MON_7 0x20020 +#define MON_8 0x20021 +#define MON_9 0x20022 +#define MORECTL 1 +#define MOREDATA 2 +#define MSG_ANY 0x02 +#define MSG_BAND 0x04 +#define MSG_DONTWAIT 0x0040 +#define MSG_HIPRI 0x01 +#define MSG_NOSIGNAL 0x4000 +#define MSG_PEEK 0x0002 +#define MSG_TRUNC 0x0020 +#define MSG_WAITALL 0x0100 +#define MUXID_ALL (-1) +#define M_1_PI 0.31830988618379067154 +#define M_2_PI 0.63661977236758134308 +#define M_2_SQRTPI 1.12837916709551257390 +#define M_E 2.7182818284590452354 +#define M_LN10 2.30258509299404568402 +#define M_LN2 0.69314718055994530942 +#define M_LOG10E 0.43429448190325182765 +#define M_LOG2E 1.4426950408889634074 +#define M_PI 3.14159265358979323846 +#define M_PI_2 1.57079632679489661923 +#define M_PI_4 0.78539816339744830962 +#define M_SQRT1_2 0.70710678118654752440 +#define M_SQRT2 1.41421356237309504880 +#define NAMESERVER_PORT NS_DEFAULTPORT +#define NAME_MAX 255 +#define NAN (0.0f/0.0f) +#define NBBY 8 +#define NCARGS 131072 +#define ND_NA_FLAG_OVERRIDE 0x00000020 +#define ND_NA_FLAG_ROUTER 0x00000080 +#define ND_NA_FLAG_SOLICITED 0x00000040 +#define ND_NEIGHBOR_ADVERT 136 +#define ND_NEIGHBOR_SOLICIT 135 +#define ND_OPT_HOME_AGENT_INFO 8 +#define ND_OPT_MTU 5 +#define ND_OPT_PI_FLAG_AUTO 0x40 +#define ND_OPT_PI_FLAG_ONLINK 0x80 +#define ND_OPT_PI_FLAG_RADDR 0x20 +#define ND_OPT_PREFIX_INFORMATION 3 +#define ND_OPT_REDIRECTED_HEADER 4 +#define ND_OPT_RTR_ADV_INTERVAL 7 +#define ND_OPT_SOURCE_LINKADDR 1 +#define ND_OPT_TARGET_LINKADDR 2 +#define ND_RA_FLAG_HOME_AGENT 0x20 +#define ND_RA_FLAG_MANAGED 0x80 +#define ND_RA_FLAG_OTHER 0x40 +#define ND_REDIRECT 137 +#define ND_ROUTER_ADVERT 134 +#define ND_ROUTER_SOLICIT 133 +#define NEW_ENV_VALUE 1 +#define NEW_ENV_VAR 0 +#define NGROUPS 32 +#define NGROUPS_MAX 32 +#define NI_DGRAM 0x10 +#define NI_MAXHOST 255 +#define NI_MAXSERV 32 +#define NI_NAMEREQD 0x08 +#define NI_NOFQDN 0x04 +#define NI_NUMERICHOST 0x01 +#define NI_NUMERICSCOPE 0x100 +#define NI_NUMERICSERV 0x02 +#define NL_ARGMAX 9 +#define NL_CAT_LOCALE 1 +#define NL_LANGMAX 32 +#define NL_LOCALE_NAME(cat) _NL_LOCALE_NAME(cat) +#define NL_MSGMAX 32767 +#define NL_NMAX 16 +#define NL_SETD 1 +#define NL_SETMAX 255 +#define NL_TEXTMAX 2048 +#define NOERROR ns_r_noerror +#define NOEXPR 0x50001 +#define NOFILE 256 +#define NOGROUP (-1) +#define NOP 241 +#define NOSTR 0x50003 +#define NOTAUTH ns_r_notauth +#define NOTIMP ns_r_notimpl +#define NOTZONE ns_r_notzone +#define NO_ADDRESS NO_DATA +#define NO_DATA 4 +#define NO_RECOVERY 3 +#define NR_ICMP_TYPES 18 +#define NR_ICMP_UNREACH 15 +#define NSLC 18 +#define NS_ALG_DH 2 +#define NS_ALG_DSA 3 +#define NS_ALG_DSS NS_ALG_DSA +#define NS_ALG_EXPIRE_ONLY 253 +#define NS_ALG_MD5RSA 1 +#define NS_ALG_PRIVATE_OID 254 +#define NS_CMPRSFLGS 0xc0 +#define NS_DEFAULTPORT 53 +#define NS_DSA_MAX_BYTES 405 +#define NS_DSA_MIN_SIZE 213 +#define NS_DSA_SIG_SIZE 41 +#define NS_GET16(s,cp) (void)((s) = ns_get16(((cp)+=2)-2)) +#define NS_GET32(l,cp) (void)((l) = ns_get32(((cp)+=4)-4)) +#define NS_HFIXEDSZ 12 +#define NS_IN6ADDRSZ 16 +#define NS_INADDRSZ 4 +#define NS_INT16SZ 2 +#define NS_INT32SZ 4 +#define NS_INT8SZ 1 +#define NS_KEY_EXTENDED_FLAGS 0x1000 +#define NS_KEY_NAME_ENTITY 0x0200 +#define NS_KEY_NAME_RESERVED 0x0300 +#define NS_KEY_NAME_TYPE 0x0300 +#define NS_KEY_NAME_USER 0x0000 +#define NS_KEY_NAME_ZONE 0x0100 +#define NS_KEY_NO_AUTH 0x8000 +#define NS_KEY_NO_CONF 0x4000 +#define NS_KEY_PROT_ANY 255 +#define NS_KEY_PROT_DNSSEC 3 +#define NS_KEY_PROT_EMAIL 2 +#define NS_KEY_PROT_IPSEC 4 +#define NS_KEY_PROT_TLS 1 +#define NS_KEY_RESERVED10 0x0020 +#define NS_KEY_RESERVED11 0x0010 +#define NS_KEY_RESERVED2 0x2000 +#define NS_KEY_RESERVED4 0x0800 +#define NS_KEY_RESERVED5 0x0400 +#define NS_KEY_RESERVED8 0x0080 +#define NS_KEY_RESERVED9 0x0040 +#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | NS_KEY_RESERVED4 | NS_KEY_RESERVED5 | NS_KEY_RESERVED8 | NS_KEY_RESERVED9 | NS_KEY_RESERVED10 | NS_KEY_RESERVED11 ) +#define NS_KEY_RESERVED_BITMASK2 0xFFFF +#define NS_KEY_SIGNATORYMASK 0x000F +#define NS_KEY_TYPEMASK 0xC000 +#define NS_KEY_TYPE_AUTH_CONF 0x0000 +#define NS_KEY_TYPE_AUTH_ONLY 0x4000 +#define NS_KEY_TYPE_CONF_ONLY 0x8000 +#define NS_KEY_TYPE_NO_KEY 0xC000 +#define NS_MAXCDNAME 255 +#define NS_MAXDNAME 1025 +#define NS_MAXLABEL 63 +#define NS_MAXMSG 65535 +#define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4) +#define NS_MD5RSA_MAX_BITS 4096 +#define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3) +#define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8) +#define NS_MD5RSA_MIN_BITS 512 +#define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8) +#define NS_NOTIFY_OP ns_o_notify +#define NS_NXT_BITS 8 +#define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS))) +#define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) +#define NS_NXT_BIT_SET(n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS))) +#define NS_NXT_MAX 127 +#define NS_OPT_DNSSEC_OK 0x8000U +#define NS_OPT_NSID 3 +#define NS_PACKETSZ 512 +#define NS_PUT16(s,cp) ns_put16((s), ((cp)+=2)-2) +#define NS_PUT32(l,cp) ns_put32((l), ((cp)+=4)-4) +#define NS_QFIXEDSZ 4 +#define NS_RRFIXEDSZ 10 +#define NS_SIG_ALG 2 +#define NS_SIG_EXPIR 8 +#define NS_SIG_FOOT 16 +#define NS_SIG_LABELS 3 +#define NS_SIG_OTTL 4 +#define NS_SIG_SIGNED 12 +#define NS_SIG_SIGNER 18 +#define NS_SIG_TYPE 0 +#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT" +#define NS_TSIG_ERROR_FORMERR -12 +#define NS_TSIG_ERROR_NO_SPACE -11 +#define NS_TSIG_ERROR_NO_TSIG -10 +#define NS_TSIG_FUDGE 300 +#define NS_TSIG_TCP_COUNT 100 +#define NS_UPDATE_OP ns_o_update +#define NTELOPTS (1+TELOPT_NEW_ENVIRON) +#define NULL ((void*)0) +#define NXDOMAIN ns_r_nxdomain +#define NXRRSET ns_r_nxrrset +#define NZERO 20 +#define OLD_ENV_VALUE 0 +#define OLD_ENV_VAR 1 +#define ONCE_FLAG_INIT 0 +#define O_ACCMODE (O_EXEC | O_RDWR | O_SEARCH) +#define O_APPEND 0x0001 +#define O_CLOEXEC (0) +#define O_CREAT (0x0001 << 12) +#define O_DIRECTORY (0x0002 << 12) +#define O_DSYNC 0x0002 +#define O_EXCL (0x0004 << 12) +#define O_EXEC (0x02000000) +#define O_NOCTTY (0) +#define O_NOFOLLOW (0x01000000) +#define O_NONBLOCK 0x0004 +#define O_RDONLY (0x04000000) +#define O_RDWR (O_RDONLY | O_WRONLY) +#define O_RSYNC 0x0008 +#define O_SEARCH (0x08000000) +#define O_SYNC 0x0010 +#define O_TRUNC (0x0008 << 12) +#define O_TTY_INIT (0) +#define O_WRONLY (0x10000000) +#define PACKETSZ NS_PACKETSZ +#define PACKET_ADD_MEMBERSHIP 1 +#define PACKET_AUXDATA 8 +#define PACKET_BROADCAST 1 +#define PACKET_COPY_THRESH 7 +#define PACKET_DROP_MEMBERSHIP 2 +#define PACKET_FANOUT 18 +#define PACKET_FANOUT_DATA 22 +#define PACKET_FASTROUTE 6 +#define PACKET_HDRLEN 11 +#define PACKET_HOST 0 +#define PACKET_IGNORE_OUTGOING 23 +#define PACKET_LOOPBACK 5 +#define PACKET_LOSS 14 +#define PACKET_MR_ALLMULTI 2 +#define PACKET_MR_MULTICAST 0 +#define PACKET_MR_PROMISC 1 +#define PACKET_MR_UNICAST 3 +#define PACKET_MULTICAST 2 +#define PACKET_ORIGDEV 9 +#define PACKET_OTHERHOST 3 +#define PACKET_OUTGOING 4 +#define PACKET_QDISC_BYPASS 20 +#define PACKET_RECV_OUTPUT 3 +#define PACKET_RESERVE 12 +#define PACKET_ROLLOVER_STATS 21 +#define PACKET_RX_RING 5 +#define PACKET_STATISTICS 6 +#define PACKET_TIMESTAMP 17 +#define PACKET_TX_HAS_OFF 19 +#define PACKET_TX_RING 13 +#define PACKET_TX_TIMESTAMP 16 +#define PACKET_VERSION 10 +#define PACKET_VNET_HDR 15 +#define PAGESIZE (0x10000) +#define PAGE_SIZE PAGESIZE +#define PATH_MAX 4096 +#define PDP_ENDIAN __PDP_ENDIAN +#define PF_INET 1 +#define PF_INET6 2 +#define PF_UNSPEC 0 +#define PM_STR 0x20027 +#define POLLERR 0x1000 +#define POLLHUP 0x2000 +#define POLLIN POLLRDNORM +#define POLLNVAL 0x4000 +#define POLLOUT POLLWRNORM +#define POLLRDNORM 0x1 +#define POLLWRNORM 0x2 +#define POSIX_CLOSE_RESTART 0 +#define POSIX_FADV_DONTNEED 4 +#define POSIX_FADV_NOREUSE 5 +#define POSIX_FADV_NORMAL 0 +#define POSIX_FADV_RANDOM 2 +#define POSIX_FADV_SEQUENTIAL 1 +#define POSIX_FADV_WILLNEED 3 +#define PRELIM 1 +#define PRIX16 __UINT16_FMTX__ +#define PRIX32 __UINT32_FMTX__ +#define PRIX64 __UINT64_FMTX__ +#define PRIX8 __UINT8_FMTX__ +#define PRIXFAST16 __UINT_FAST16_FMTX__ +#define PRIXFAST32 __UINT_FAST32_FMTX__ +#define PRIXFAST64 __UINT_FAST64_FMTX__ +#define PRIXFAST8 __UINT_FAST8_FMTX__ +#define PRIXLEAST16 __UINT_LEAST16_FMTX__ +#define PRIXLEAST32 __UINT_LEAST32_FMTX__ +#define PRIXLEAST64 __UINT_LEAST64_FMTX__ +#define PRIXLEAST8 __UINT_LEAST8_FMTX__ +#define PRIXMAX __UINTMAX_FMTX__ +#define PRIXPTR __UINTPTR_FMTX__ +#define PRId16 __INT16_FMTd__ +#define PRId32 __INT32_FMTd__ +#define PRId64 __INT64_FMTd__ +#define PRId8 __INT8_FMTd__ +#define PRIdFAST16 __INT_FAST16_FMTd__ +#define PRIdFAST32 __INT_FAST32_FMTd__ +#define PRIdFAST64 __INT_FAST64_FMTd__ +#define PRIdFAST8 __INT_FAST8_FMTd__ +#define PRIdLEAST16 __INT_LEAST16_FMTd__ +#define PRIdLEAST32 __INT_LEAST32_FMTd__ +#define PRIdLEAST64 __INT_LEAST64_FMTd__ +#define PRIdLEAST8 __INT_LEAST8_FMTd__ +#define PRIdMAX __INTMAX_FMTd__ +#define PRIdPTR __INTPTR_FMTd__ +#define PRIi16 __INT16_FMTi__ +#define PRIi32 __INT32_FMTi__ +#define PRIi64 __INT64_FMTi__ +#define PRIi8 __INT8_FMTi__ +#define PRIiFAST16 __INT_FAST16_FMTi__ +#define PRIiFAST32 __INT_FAST32_FMTi__ +#define PRIiFAST64 __INT_FAST64_FMTi__ +#define PRIiFAST8 __INT_FAST8_FMTi__ +#define PRIiLEAST16 __INT_LEAST16_FMTi__ +#define PRIiLEAST32 __INT_LEAST32_FMTi__ +#define PRIiLEAST64 __INT_LEAST64_FMTi__ +#define PRIiLEAST8 __INT_LEAST8_FMTi__ +#define PRIiMAX __INTMAX_FMTi__ +#define PRIiPTR __INTPTR_FMTi__ +#define PRIo16 __UINT16_FMTo__ +#define PRIo32 __UINT32_FMTo__ +#define PRIo64 __UINT64_FMTo__ +#define PRIo8 __UINT8_FMTo__ +#define PRIoFAST16 __UINT_FAST16_FMTo__ +#define PRIoFAST32 __UINT_FAST32_FMTo__ +#define PRIoFAST64 __UINT_FAST64_FMTo__ +#define PRIoFAST8 __UINT_FAST8_FMTo__ +#define PRIoLEAST16 __UINT_LEAST16_FMTo__ +#define PRIoLEAST32 __UINT_LEAST32_FMTo__ +#define PRIoLEAST64 __UINT_LEAST64_FMTo__ +#define PRIoLEAST8 __UINT_LEAST8_FMTo__ +#define PRIoMAX __UINTMAX_FMTo__ +#define PRIoPTR __UINTPTR_FMTo__ +#define PRIu16 __UINT16_FMTu__ +#define PRIu32 __UINT32_FMTu__ +#define PRIu64 __UINT64_FMTu__ +#define PRIu8 __UINT8_FMTu__ +#define PRIuFAST16 __UINT_FAST16_FMTu__ +#define PRIuFAST32 __UINT_FAST32_FMTu__ +#define PRIuFAST64 __UINT_FAST64_FMTu__ +#define PRIuFAST8 __UINT_FAST8_FMTu__ +#define PRIuLEAST16 __UINT_LEAST16_FMTu__ +#define PRIuLEAST32 __UINT_LEAST32_FMTu__ +#define PRIuLEAST64 __UINT_LEAST64_FMTu__ +#define PRIuLEAST8 __UINT_LEAST8_FMTu__ +#define PRIuMAX __UINTMAX_FMTu__ +#define PRIuPTR __UINTPTR_FMTu__ +#define PRIx16 __UINT16_FMTx__ +#define PRIx32 __UINT32_FMTx__ +#define PRIx64 __UINT64_FMTx__ +#define PRIx8 __UINT8_FMTx__ +#define PRIxFAST16 __UINT_FAST16_FMTx__ +#define PRIxFAST32 __UINT_FAST32_FMTx__ +#define PRIxFAST64 __UINT_FAST64_FMTx__ +#define PRIxFAST8 __UINT_FAST8_FMTx__ +#define PRIxLEAST16 __UINT_LEAST16_FMTx__ +#define PRIxLEAST32 __UINT_LEAST32_FMTx__ +#define PRIxLEAST64 __UINT_LEAST64_FMTx__ +#define PRIxLEAST8 __UINT_LEAST8_FMTx__ +#define PRIxMAX __UINTMAX_FMTx__ +#define PRIxPTR __UINTPTR_FMTx__ +#define PTHREAD_BARRIER_SERIAL_THREAD (-1) +#define PTHREAD_CANCELED ((void *)-1) +#define PTHREAD_CANCEL_ASYNCHRONOUS 1 +#define PTHREAD_CANCEL_DEFERRED 0 +#define PTHREAD_CANCEL_DISABLE 1 +#define PTHREAD_CANCEL_ENABLE 0 +#define PTHREAD_CANCEL_MASKED 2 +#define PTHREAD_COND_INITIALIZER {{{0}}} +#define PTHREAD_CREATE_DETACHED 1 +#define PTHREAD_CREATE_JOINABLE 0 +#define PTHREAD_DESTRUCTOR_ITERATIONS 4 +#define PTHREAD_EXPLICIT_SCHED 1 +#define PTHREAD_INHERIT_SCHED 0 +#define PTHREAD_KEYS_MAX 128 +#define PTHREAD_MUTEX_DEFAULT 0 +#define PTHREAD_MUTEX_ERRORCHECK 2 +#define PTHREAD_MUTEX_INITIALIZER {{{0}}} +#define PTHREAD_MUTEX_NORMAL 0 +#define PTHREAD_MUTEX_RECURSIVE 1 +#define PTHREAD_MUTEX_ROBUST 1 +#define PTHREAD_MUTEX_STALLED 0 +#define PTHREAD_NULL ((pthread_t)0) +#define PTHREAD_ONCE_INIT 0 +#define PTHREAD_PRIO_INHERIT 1 +#define PTHREAD_PRIO_NONE 0 +#define PTHREAD_PRIO_PROTECT 2 +#define PTHREAD_PROCESS_PRIVATE 0 +#define PTHREAD_PROCESS_SHARED 1 +#define PTHREAD_RWLOCK_INITIALIZER {{{0}}} +#define PTHREAD_SCOPE_PROCESS 1 +#define PTHREAD_SCOPE_SYSTEM 0 +#define PTHREAD_STACK_MIN 2048 +#define PTRBITS (sizeof(char *) * 8) +#define PTRDIFF_MAX INT32_MAX +#define PTRDIFF_MIN INT32_MIN +#define PUTLONG NS_PUT32 +#define PUTSHORT NS_PUT16 +#define QFIXEDSZ NS_QFIXEDSZ +#define QUERY ns_o_query +#define RADIXCHAR 0x10000 +#define RAND_MAX (0x7fffffff) +#define REC_EOF '\002' +#define REC_EOR '\001' +#define REC_ESC '\377' +#define REFUSED ns_r_refused +#define REGTYPE '0' +#define REG_BADBR 10 +#define REG_BADPAT 2 +#define REG_BADRPT 13 +#define REG_EBRACE 9 +#define REG_EBRACK 7 +#define REG_ECOLLATE 3 +#define REG_ECTYPE 4 +#define REG_EESCAPE 5 +#define REG_ENOSYS -1 +#define REG_EPAREN 8 +#define REG_ERANGE 11 +#define REG_ESPACE 12 +#define REG_ESUBREG 6 +#define REG_EXTENDED 1 +#define REG_ICASE 2 +#define REG_NEWLINE 4 +#define REG_NOMATCH 1 +#define REG_NOSUB 8 +#define REG_NOTBOL 1 +#define REG_NOTEOL 2 +#define REG_OK 0 +#define RE_DUP_MAX 255 +#define RMSGD 0x0001 +#define RMSGN 0x0002 +#define RNORM 0x0000 +#define RPM_PCO_ADD 1 +#define RPM_PCO_CHANGE 2 +#define RPM_PCO_SETGLOBAL 3 +#define RPROTDAT 0x0004 +#define RPROTDIS 0x0008 +#define RPROTMASK 0x001C +#define RPROTNORM 0x0010 +#define RRFIXEDSZ NS_RRFIXEDSZ +#define RRQ 01 +#define RS_HIPRI 0x01 +#define RTLD_DEFAULT ((void *)0) +#define RTLD_GLOBAL 256 +#define RTLD_LAZY 1 +#define RTLD_LOCAL 8 +#define RTLD_NEXT ((void *)-1) +#define RTLD_NODELETE 4096 +#define RTLD_NOLOAD 4 +#define RTLD_NOW 2 +#define RUSAGE_CHILDREN 2 +#define RUSAGE_SELF 1 +#define R_OK (4) +#define SARMAG 8 +#define SB 250 +#define SCHAR_MAX 127 +#define SCHAR_MIN (-128) +#define SCNd16 __INT16_FMTd__ +#define SCNd32 __INT32_FMTd__ +#define SCNd64 __INT64_FMTd__ +#define SCNd8 __INT8_FMTd__ +#define SCNdFAST16 __INT_FAST16_FMTd__ +#define SCNdFAST32 __INT_FAST32_FMTd__ +#define SCNdFAST64 __INT_FAST64_FMTd__ +#define SCNdFAST8 __INT_FAST8_FMTd__ +#define SCNdLEAST16 __INT_LEAST16_FMTd__ +#define SCNdLEAST32 __INT_LEAST32_FMTd__ +#define SCNdLEAST64 __INT_LEAST64_FMTd__ +#define SCNdLEAST8 __INT_LEAST8_FMTd__ +#define SCNdMAX __INTMAX_FMTd__ +#define SCNdPTR __INTPTR_FMTd__ +#define SCNi16 __INT16_FMTi__ +#define SCNi32 __INT32_FMTi__ +#define SCNi64 __INT64_FMTi__ +#define SCNi8 __INT8_FMTi__ +#define SCNiFAST16 __INT_FAST16_FMTi__ +#define SCNiFAST32 __INT_FAST32_FMTi__ +#define SCNiFAST64 __INT_FAST64_FMTi__ +#define SCNiFAST8 __INT_FAST8_FMTi__ +#define SCNiLEAST16 __INT_LEAST16_FMTi__ +#define SCNiLEAST32 __INT_LEAST32_FMTi__ +#define SCNiLEAST64 __INT_LEAST64_FMTi__ +#define SCNiLEAST8 __INT_LEAST8_FMTi__ +#define SCNiMAX __INTMAX_FMTi__ +#define SCNiPTR __INTPTR_FMTi__ +#define SCNo16 __UINT16_FMTo__ +#define SCNo32 __UINT32_FMTo__ +#define SCNo64 __UINT64_FMTo__ +#define SCNo8 __UINT8_FMTo__ +#define SCNoFAST16 __UINT_FAST16_FMTo__ +#define SCNoFAST32 __UINT_FAST32_FMTo__ +#define SCNoFAST64 __UINT_FAST64_FMTo__ +#define SCNoFAST8 __UINT_FAST8_FMTo__ +#define SCNoLEAST16 __UINT_LEAST16_FMTo__ +#define SCNoLEAST32 __UINT_LEAST32_FMTo__ +#define SCNoLEAST64 __UINT_LEAST64_FMTo__ +#define SCNoLEAST8 __UINT_LEAST8_FMTo__ +#define SCNoMAX __UINTMAX_FMTo__ +#define SCNoPTR __UINTPTR_FMTo__ +#define SCNu16 __UINT16_FMTu__ +#define SCNu32 __UINT32_FMTu__ +#define SCNu64 __UINT64_FMTu__ +#define SCNu8 __UINT8_FMTu__ +#define SCNuFAST16 __UINT_FAST16_FMTu__ +#define SCNuFAST32 __UINT_FAST32_FMTu__ +#define SCNuFAST64 __UINT_FAST64_FMTu__ +#define SCNuFAST8 __UINT_FAST8_FMTu__ +#define SCNuLEAST16 __UINT_LEAST16_FMTu__ +#define SCNuLEAST32 __UINT_LEAST32_FMTu__ +#define SCNuLEAST64 __UINT_LEAST64_FMTu__ +#define SCNuLEAST8 __UINT_LEAST8_FMTu__ +#define SCNuMAX __UINTMAX_FMTu__ +#define SCNuPTR __UINTPTR_FMTu__ +#define SCNx16 __UINT16_FMTx__ +#define SCNx32 __UINT32_FMTx__ +#define SCNx64 __UINT64_FMTx__ +#define SCNx8 __UINT8_FMTx__ +#define SCNxFAST16 __UINT_FAST16_FMTx__ +#define SCNxFAST32 __UINT_FAST32_FMTx__ +#define SCNxFAST64 __UINT_FAST64_FMTx__ +#define SCNxFAST8 __UINT_FAST8_FMTx__ +#define SCNxLEAST16 __UINT_LEAST16_FMTx__ +#define SCNxLEAST32 __UINT_LEAST32_FMTx__ +#define SCNxLEAST64 __UINT_LEAST64_FMTx__ +#define SCNxLEAST8 __UINT_LEAST8_FMTx__ +#define SCNxMAX __UINTMAX_FMTx__ +#define SCNxPTR __UINTPTR_FMTx__ +#define SE 240 +#define SEEK_CUR 1 +#define SEEK_END 2 +#define SEEK_SET 0 +#define SEGSIZE 512 +#define SEM_FAILED ((sem_t *)0) +#define SERVFAIL ns_r_servfail +#define SHORTBITS (sizeof(short) * 8) +#define SHRT_MAX 0x7fff +#define SHRT_MIN (-1-0x7fff) +#define SHUT_RD 1 +#define SHUT_RDWR (SHUT_RD | SHUT_WR) +#define SHUT_WR 2 +#define SIG_ATOMIC_MAX INT32_MAX +#define SIG_ATOMIC_MIN INT32_MIN +#define SIZE_MAX UINT32_MAX +#define SI_LOAD_SHIFT 16 +#define SLC_ABORT 7 +#define SLC_ACK 0x80 +#define SLC_AO 4 +#define SLC_AYT 5 +#define SLC_BRK 2 +#define SLC_CANTCHANGE 1 +#define SLC_DEFAULT 3 +#define SLC_EC 10 +#define SLC_EL 11 +#define SLC_EOF 8 +#define SLC_EOR 6 +#define SLC_EW 12 +#define SLC_FLAGS 1 +#define SLC_FLUSHIN 0x40 +#define SLC_FLUSHOUT 0x20 +#define SLC_FORW1 17 +#define SLC_FORW2 18 +#define SLC_FUNC 0 +#define SLC_IP 3 +#define SLC_LEVELBITS 0x03 +#define SLC_LNEXT 14 +#define SLC_NAME(x) slc_names[x] +#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", "LNEXT", "XON", "XOFF", "FORW1", "FORW2", 0, +#define SLC_NAMES SLC_NAMELIST +#define SLC_NAME_OK(x) ((unsigned int)(x) <= NSLC) +#define SLC_NOSUPPORT 0 +#define SLC_RP 13 +#define SLC_SUSP 9 +#define SLC_SYNCH 1 +#define SLC_VALUE 2 +#define SLC_VARIABLE 2 +#define SLC_XOFF 16 +#define SLC_XON 15 +#define SNDPIPE 0x002 +#define SNDZERO 0x001 +#define SOCKETS_ERROR_CODE_ACCESS_DENIED 1 +#define SOCKETS_ERROR_CODE_ADDRESS_IN_USE 8 +#define SOCKETS_ERROR_CODE_ADDRESS_NOT_BINDABLE 7 +#define SOCKETS_ERROR_CODE_CONNECTION_ABORTED 12 +#define SOCKETS_ERROR_CODE_CONNECTION_REFUSED 10 +#define SOCKETS_ERROR_CODE_CONNECTION_RESET 11 +#define SOCKETS_ERROR_CODE_DATAGRAM_TOO_LARGE 13 +#define SOCKETS_ERROR_CODE_INVALID_ARGUMENT 3 +#define SOCKETS_ERROR_CODE_INVALID_STATE 6 +#define SOCKETS_ERROR_CODE_NOT_SUPPORTED 2 +#define SOCKETS_ERROR_CODE_OUT_OF_MEMORY 4 +#define SOCKETS_ERROR_CODE_REMOTE_UNREACHABLE 9 +#define SOCKETS_ERROR_CODE_TIMEOUT 5 +#define SOCKETS_ERROR_CODE_UNKNOWN 0 +#define SOCKETS_IP_ADDRESS_FAMILY_IPV4 0 +#define SOCKETS_IP_ADDRESS_FAMILY_IPV6 1 +#define SOCKETS_IP_ADDRESS_IPV4 0 +#define SOCKETS_IP_ADDRESS_IPV6 1 +#define SOCKETS_IP_SOCKET_ADDRESS_IPV4 0 +#define SOCKETS_IP_SOCKET_ADDRESS_IPV6 1 +#define SOCK_CLOEXEC (0x00002000) +#define SOCK_DGRAM 5 +#define SOCK_NONBLOCK (0x00004000) +#define SOCK_STREAM 6 +#define SOL_IP 0 +#define SOL_IPV6 41 +#define SOL_SOCKET 0x7fffffff +#define SOL_TCP 6 +#define SOL_UDP 17 +#define SOMAXCONN 128 +#define SO_ACCEPTCONN 30 +#define SO_DOMAIN 39 +#define SO_ERROR 4 +#define SO_KEEPALIVE 9 +#define SO_PROTOCOL 38 +#define SO_RCVBUF 8 +#define SO_RCVTIMEO 66 +#define SO_REUSEADDR 2 +#define SO_SNDBUF 7 +#define SO_SNDTIMEO 67 +#define SO_TYPE 3 +#define SSIZE_MAX LONG_MAX +#define STATUS ns_o_status +#define STA_CLK 0x8000 +#define STA_CLOCKERR 0x1000 +#define STA_DEL 0x0020 +#define STA_FLL 0x0008 +#define STA_FREQHOLD 0x0080 +#define STA_INS 0x0010 +#define STA_MODE 0x4000 +#define STA_NANO 0x2000 +#define STA_PLL 0x0001 +#define STA_PPSERROR 0x0800 +#define STA_PPSFREQ 0x0002 +#define STA_PPSJITTER 0x0200 +#define STA_PPSSIGNAL 0x0100 +#define STA_PPSTIME 0x0004 +#define STA_PPSWANDER 0x0400 +#define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK) +#define STA_UNSYNC 0x0040 +#define STDERR_FILENO 2 +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STRU_F 1 +#define STRU_P 3 +#define STRU_R 2 +#define ST_APPEND 256 +#define ST_IMMUTABLE 512 +#define ST_MANDLOCK 64 +#define ST_NOATIME 1024 +#define ST_NODEV 4 +#define ST_NODIRATIME 2048 +#define ST_NOEXEC 8 +#define ST_NOSUID 2 +#define ST_RDONLY 1 +#define ST_RELATIME 4096 +#define ST_SYNCHRONOUS 16 +#define ST_WRITE 128 +#define SUN_LEN(s) (2+strlen((s)->sun_path)) +#define SUSP 237 +#define SYMLOOP_MAX 40 +#define SYMTYPE '2' +#define SYNCH 242 +#define S_ADDT ns_s_ar +#define S_BANDURG 0x0200 +#define S_ERROR 0x0010 +#define S_HANGUP 0x0020 +#define S_HIPRI 0x0002 +#define S_IEXEC S_IXUSR +#define S_IFBLK (0x6000) +#define S_IFCHR (0x2000) +#define S_IFDIR (0x4000) +#define S_IFIFO (0x1000) +#define S_IFLNK (0xa000) +#define S_IFMT (S_IFBLK | S_IFCHR | S_IFDIR | S_IFIFO | S_IFLNK | S_IFREG | S_IFSOCK) +#define S_IFREG (0x8000) +#define S_IFSOCK (0xc000) +#define S_INPUT 0x0001 +#define S_IREAD S_IRUSR +#define S_IRGRP (0x20) +#define S_IROTH (0x4) +#define S_IRUSR (0x100) +#define S_IRWXG (S_IXGRP | S_IWGRP | S_IRGRP) +#define S_IRWXO (S_IXOTH | S_IWOTH | S_IROTH) +#define S_IRWXU (S_IXUSR | S_IWUSR | S_IRUSR) +#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) +#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) +#define S_ISGID (0x400) +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) +#define S_ISUID (0x800) +#define S_ISVTX (0x200) +#define S_IWGRP (0x10) +#define S_IWOTH (0x2) +#define S_IWRITE S_IWUSR +#define S_IWUSR (0x80) +#define S_IXGRP (0x8) +#define S_IXOTH (0x1) +#define S_IXUSR (0x40) +#define S_MSG 0x0008 +#define S_OUTPUT 0x0004 +#define S_PREREQ ns_s_pr +#define S_RDBAND 0x0080 +#define S_RDNORM 0x0040 +#define S_UPDATE ns_s_ud +#define S_WRBAND 0x0100 +#define S_WRNORM S_OUTPUT +#define S_ZONE ns_s_zn +#define TCPI_OPT_ECN 8 +#define TCPI_OPT_SACK 2 +#define TCPI_OPT_TIMESTAMPS 1 +#define TCPI_OPT_WSCALE 4 +#define TCPOLEN_MAXSEG 4 +#define TCPOLEN_SACK_PERMITTED 2 +#define TCPOLEN_TIMESTAMP 10 +#define TCPOLEN_WINDOW 3 +#define TCPOPT_EOL 0 +#define TCPOPT_MAXSEG 2 +#define TCPOPT_NOP 1 +#define TCPOPT_SACK 5 +#define TCPOPT_SACK_PERMITTED 4 +#define TCPOPT_TIMESTAMP 8 +#define TCPOPT_WINDOW 3 +#define TCP_CA_CWR 2 +#define TCP_CA_Disorder 1 +#define TCP_CA_Loss 4 +#define TCP_CA_Open 0 +#define TCP_CA_Recovery 3 +#define TCP_CC_INFO 26 +#define TCP_CLOSE 7 +#define TCP_CLOSE_WAIT 8 +#define TCP_CLOSING 11 +#define TCP_CM_INQ TCP_INQ +#define TCP_CONGESTION 13 +#define TCP_CORK 3 +#define TCP_DEFER_ACCEPT 9 +#define TCP_ENCAP_ESPINTCP 7 +#define TCP_ESTABLISHED 1 +#define TCP_FASTOPEN 23 +#define TCP_FASTOPEN_CONNECT 30 +#define TCP_FASTOPEN_KEY 33 +#define TCP_FASTOPEN_NO_COOKIE 34 +#define TCP_FIN_WAIT1 4 +#define TCP_FIN_WAIT2 5 +#define TCP_INFO 11 +#define TCP_INQ 36 +#define TCP_KEEPCNT 6 +#define TCP_KEEPIDLE 4 +#define TCP_KEEPINTVL 5 +#define TCP_LAST_ACK 9 +#define TCP_LINGER2 8 +#define TCP_LISTEN 10 +#define TCP_MAXSEG 2 +#define TCP_MD5SIG 14 +#define TCP_MD5SIG_EXT 32 +#define TCP_MD5SIG_FLAG_IFINDEX 0x2 +#define TCP_MD5SIG_FLAG_PREFIX 0x1 +#define TCP_MD5SIG_MAXKEYLEN 80 +#define TCP_NODELAY 1 +#define TCP_NOTSENT_LOWAT 25 +#define TCP_QUEUE_SEQ 21 +#define TCP_QUICKACK 12 +#define TCP_RECEIVE_ZEROCOPY_FLAG_TLB_CLEAN_HINT 0x1 +#define TCP_REPAIR 19 +#define TCP_REPAIR_OFF 0 +#define TCP_REPAIR_OFF_NO_WP -1 +#define TCP_REPAIR_ON 1 +#define TCP_REPAIR_OPTIONS 22 +#define TCP_REPAIR_QUEUE 20 +#define TCP_REPAIR_WINDOW 29 +#define TCP_SAVED_SYN 28 +#define TCP_SAVE_SYN 27 +#define TCP_SYNCNT 7 +#define TCP_SYN_RECV 3 +#define TCP_SYN_SENT 2 +#define TCP_THIN_DUPACK 17 +#define TCP_THIN_LINEAR_TIMEOUTS 16 +#define TCP_TIMESTAMP 24 +#define TCP_TIME_WAIT 6 +#define TCP_TX_DELAY 37 +#define TCP_ULP 31 +#define TCP_USER_TIMEOUT 18 +#define TCP_WINDOW_CLAMP 10 +#define TCP_ZEROCOPY_RECEIVE 35 +#define TELCMD(x) telcmds[(x)-TELCMD_FIRST] +#define TELCMD_FIRST xEOF +#define TELCMD_LAST IAC +#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && (unsigned int)(x) >= TELCMD_FIRST) +#define TELOPT_3270REGIME 29 +#define TELOPT_AUTHENTICATION 37 +#define TELOPT_BINARY 0 +#define TELOPT_BM 19 +#define TELOPT_DET 20 +#define TELOPT_ECHO 1 +#define TELOPT_ENCRYPT 38 +#define TELOPT_EOR 25 +#define TELOPT_EXOPL 255 +#define TELOPT_LFLOW 33 +#define TELOPT_LINEMODE 34 +#define TELOPT_LOGOUT 18 +#define TELOPT_NAMS 4 +#define TELOPT_NAOCRD 10 +#define TELOPT_NAOFFD 13 +#define TELOPT_NAOHTD 12 +#define TELOPT_NAOHTS 11 +#define TELOPT_NAOL 8 +#define TELOPT_NAOLFD 16 +#define TELOPT_NAOP 9 +#define TELOPT_NAOVTD 15 +#define TELOPT_NAOVTS 14 +#define TELOPT_NAWS 31 +#define TELOPT_NEW_ENVIRON 39 +#define TELOPT_OLD_ENVIRON 36 +#define TELOPT_OUTMRK 27 +#define TELOPT_RCP 2 +#define TELOPT_RCTE 7 +#define TELOPT_SGA 3 +#define TELOPT_SNDLOC 23 +#define TELOPT_STATUS 5 +#define TELOPT_SUPDUP 21 +#define TELOPT_SUPDUPOUTPUT 22 +#define TELOPT_TM 6 +#define TELOPT_TSPEED 32 +#define TELOPT_TTYLOC 28 +#define TELOPT_TTYPE 24 +#define TELOPT_TUID 26 +#define TELOPT_X3PAD 30 +#define TELOPT_XASCII 17 +#define TELOPT_XDISPLOC 35 +#define TELQUAL_INFO 2 +#define TELQUAL_IS 0 +#define TELQUAL_NAME 3 +#define TELQUAL_REPLY 2 +#define TELQUAL_SEND 1 +#define TGEXEC 00010 +#define TGREAD 00040 +#define TGWRITE 00020 +#define THOUSEP 0x10001 +#define TH_ACK 0x10 +#define TH_FIN 0x01 +#define TH_PUSH 0x08 +#define TH_RST 0x04 +#define TH_SYN 0x02 +#define TH_URG 0x20 +#define TIMER_ABSTIME 1 +#define TIMESPEC_TO_TIMEVAL(tv,ts) ( (tv)->tv_sec = (ts)->tv_sec, (tv)->tv_usec = (ts)->tv_nsec / 1000, (void)0 ) +#define TIMEVAL_TO_TIMESPEC(tv,ts) ( (ts)->tv_sec = (tv)->tv_sec, (ts)->tv_nsec = (tv)->tv_usec * 1000, (void)0 ) +#define TIME_BAD TIME_ERROR +#define TIME_DEL 2 +#define TIME_ERROR 5 +#define TIME_INS 1 +#define TIME_OK 0 +#define TIME_OOP 3 +#define TIME_UTC 1 +#define TIME_WAIT 4 +#define TMAGIC "ustar" +#define TMAGLEN 6 +#define TOEXEC 00001 +#define TOREAD 00004 +#define TOWRITE 00002 +#define TRANSIENT 4 +#define TRY_AGAIN 2 +#define TSGID 02000 +#define TSS_DTOR_ITERATIONS 4 +#define TSUID 04000 +#define TSVTX 01000 +#define TTYDEF_CFLAG (CREAD | CS7 | PARENB | HUPCL) +#define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY) +#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL) +#define TTYDEF_OFLAG (OPOST | ONLCR | XTABS) +#define TTYDEF_SPEED (B9600) +#define TTY_NAME_MAX 32 +#define TUEXEC 00100 +#define TUREAD 00400 +#define TUWRITE 00200 +#define TVERSION "00" +#define TVERSLEN 2 +#define TYPE_A 1 +#define TYPE_E 2 +#define TYPE_I 3 +#define TYPE_L 4 +#define TZNAME_MAX 6 +#define T_A ns_t_a +#define T_A6 ns_t_a6 +#define T_AAAA ns_t_aaaa +#define T_AFSDB ns_t_afsdb +#define T_ANY ns_t_any +#define T_ATMA ns_t_atma +#define T_AVC ns_t_avc +#define T_AXFR ns_t_axfr +#define T_CAA ns_t_caa +#define T_CDNSKEY ns_t_cdnskey +#define T_CDS ns_t_cds +#define T_CNAME ns_t_cname +#define T_CSYNC ns_t_csync +#define T_DHCID ns_t_dhcid +#define T_DLV ns_t_dlv +#define T_DNAME ns_t_dname +#define T_DNSKEY ns_t_dnskey +#define T_DS ns_t_ds +#define T_EID ns_t_eid +#define T_EUI48 ns_t_eui48 +#define T_EUI64 ns_t_eui64 +#define T_FMT 0x2002A +#define T_FMT_AMPM 0x2002B +#define T_GID ns_t_gid +#define T_GPOS ns_t_gpos +#define T_HINFO ns_t_hinfo +#define T_HIP ns_t_hip +#define T_IPSECKEY ns_t_ipseckey +#define T_ISDN ns_t_isdn +#define T_IXFR ns_t_ixfr +#define T_KEY ns_t_key +#define T_L32 ns_t_l32 +#define T_L64 ns_t_l64 +#define T_LOC ns_t_loc +#define T_LP ns_t_lp +#define T_MAILA ns_t_maila +#define T_MAILB ns_t_mailb +#define T_MB ns_t_mb +#define T_MD ns_t_md +#define T_MF ns_t_mf +#define T_MG ns_t_mg +#define T_MINFO ns_t_minfo +#define T_MR ns_t_mr +#define T_MX ns_t_mx +#define T_NAPTR ns_t_naptr +#define T_NID ns_t_nid +#define T_NIMLOC ns_t_nimloc +#define T_NINFO ns_t_ninfo +#define T_NS ns_t_ns +#define T_NSAP ns_t_nsap +#define T_NSAP_PTR ns_t_nsap_ptr +#define T_NSEC ns_t_nsec +#define T_NSEC3 ns_t_nsec3 +#define T_NSEC3PARAM ns_t_nsec3param +#define T_NULL ns_t_null +#define T_NXT ns_t_nxt +#define T_OPENPGPKEY ns_t_openpgpkey +#define T_PTR ns_t_ptr +#define T_PX ns_t_px +#define T_RKEY ns_t_rkey +#define T_RP ns_t_rp +#define T_RRSIG ns_t_rrsig +#define T_RT ns_t_rt +#define T_SIG ns_t_sig +#define T_SMIMEA ns_t_smimea +#define T_SOA ns_t_soa +#define T_SPF ns_t_spf +#define T_SRV ns_t_srv +#define T_SSHFP ns_t_sshfp +#define T_TA ns_t_ta +#define T_TALINK ns_t_talink +#define T_TKEY ns_t_tkey +#define T_TLSA ns_t_tlsa +#define T_TSIG ns_t_tsig +#define T_TXT ns_t_txt +#define T_UID ns_t_uid +#define T_UINFO ns_t_uinfo +#define T_UNSPEC ns_t_unspec +#define T_URI ns_t_uri +#define T_WKS ns_t_wks +#define T_X25 ns_t_x25 +#define UCHAR_MAX 255 +#define UDP_CORK 1 +#define UDP_ENCAP 100 +#define UDP_ENCAP_ESPINUDP 2 +#define UDP_ENCAP_ESPINUDP_NON_IKE 1 +#define UDP_ENCAP_GTP0 4 +#define UDP_ENCAP_GTP1U 5 +#define UDP_ENCAP_L2TPINUDP 3 +#define UDP_ENCAP_RXRPC 6 +#define UDP_GRO 104 +#define UDP_NO_CHECK6_RX 102 +#define UDP_NO_CHECK6_TX 101 +#define UDP_SEGMENT 103 +#define UINT16_C(c) c +#define UINT16_MAX (0xffff) +#define UINT32_C(c) c ## U +#define UINT32_MAX (0xffffffffu) +#define UINT64_C(c) c ## ULL +#define UINT64_MAX (0xffffffffffffffffu) +#define UINT8_C(c) c +#define UINT8_MAX (0xff) +#define UINTMAX_C(c) c ## ULL +#define UINTMAX_MAX UINT64_MAX +#define UINTPTR_MAX UINT32_MAX +#define UINT_FAST16_MAX UINT16_MAX +#define UINT_FAST32_MAX UINT32_MAX +#define UINT_FAST64_MAX UINT64_MAX +#define UINT_FAST8_MAX UINT8_MAX +#define UINT_LEAST16_MAX UINT16_MAX +#define UINT_LEAST32_MAX UINT32_MAX +#define UINT_LEAST64_MAX UINT64_MAX +#define UINT_LEAST8_MAX UINT8_MAX +#define UINT_MAX 0xffffffffU +#define UIO_MAXIOV 1024 +#define ULLONG_MAX (2ULL*LLONG_MAX+1) +#define ULONG_MAX (2UL*LONG_MAX+1) +#define USHRT_MAX 0xffff +#define UTIME_NOW (-1) +#define UTIME_OMIT (-2) +#define WASIP3_CALLBACK_CODE_EXIT 0 +#define WASIP3_CALLBACK_CODE_POLL(set) (3 | (set << 4)) +#define WASIP3_CALLBACK_CODE_WAIT(set) (2 | (set << 4)) +#define WASIP3_CALLBACK_CODE_YIELD 1 +#define WASIP3_SUBTASK_HANDLE(status) ((wasip3_subtask_t) ((status) >> 4)) +#define WASIP3_SUBTASK_STATE(status) ((wasip3_subtask_state_t) ((status) & 0xf)) +#define WASIP3_WAITABLE_COUNT(status) ((uint32_t) ((status) >> 4)) +#define WASIP3_WAITABLE_STATE(status) ((wasip3_waitable_state_t) ((status) & 0xf)) +#define WASIP3_WAITABLE_STATUS_BLOCKED ((wasip3_waitable_status_t) -1) +#define WASI_CLI_TYPES_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE 1 +#define WASI_CLI_TYPES_ERROR_CODE_IO 0 +#define WASI_CLI_TYPES_ERROR_CODE_PIPE 2 +#define WCHAR_MAX (0x7fffffff+L'\0') +#define WCHAR_MIN (-1-0x7fffffff+L'\0') +#define WEOF 0xffffffffU +#define WILL 251 +#define WINT_MAX UINT32_MAX +#define WINT_MIN 0U +#define WONT 252 +#define WORD_BIT 32 +#define WRQ 02 +#define W_OK (2) +#define X_OK (1) +#define YESEXPR 0x50000 +#define YESSTR 0x50002 +#define YXDOMAIN ns_r_yxdomain +#define YXRRSET ns_r_yxrrset +#define _ALLOCA_H +#define _ALL_SOURCE 1 +#define _ARPA_FTP_H +#define _ARPA_INET_H +#define _ARPA_NAMESER_H +#define _ARPA_TELNET_H +#define _ARPA_TFTP_H +#define _AR_H +#define _BYTESWAP_H +#define _COMPLEX_H +#define _CPIO_H +#define _CRYPT_H +#define _CS_GNU_LIBC_VERSION 2 +#define _CS_GNU_LIBPTHREAD_VERSION 3 +#define _CS_PATH 0 +#define _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS 4 +#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 1116 +#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 1117 +#define _CS_POSIX_V6_ILP32_OFF32_LIBS 1118 +#define _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS 1119 +#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 1120 +#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 1121 +#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 1122 +#define _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS 1123 +#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 1124 +#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 1125 +#define _CS_POSIX_V6_LP64_OFF64_LIBS 1126 +#define _CS_POSIX_V6_LP64_OFF64_LINTFLAGS 1127 +#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 1128 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 1129 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 1130 +#define _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS 1131 +#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 1 +#define _CS_POSIX_V7_ILP32_OFF32_CFLAGS 1132 +#define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 1133 +#define _CS_POSIX_V7_ILP32_OFF32_LIBS 1134 +#define _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS 1135 +#define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 1136 +#define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 1137 +#define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 1138 +#define _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS 1139 +#define _CS_POSIX_V7_LP64_OFF64_CFLAGS 1140 +#define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 1141 +#define _CS_POSIX_V7_LP64_OFF64_LIBS 1142 +#define _CS_POSIX_V7_LP64_OFF64_LINTFLAGS 1143 +#define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 1144 +#define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 1145 +#define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 1146 +#define _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS 1147 +#define _CS_POSIX_V7_THREADS_CFLAGS 1150 +#define _CS_POSIX_V7_THREADS_LDFLAGS 1151 +#define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 5 +#define _CS_V6_ENV 1148 +#define _CS_V7_ENV 1149 +#define _CTYPE_H +#define _Complex_I (0.0f+1.0fi) +#define _DIRENT_H +#define _DIRENT_HAVE_D_TYPE +#define _DLFCN_H +#define _ENDIAN_H +#define _ERRNO_H +#define _ERR_H +#define _FCNTL_H +#define _FEATURES_H +#define _FENV_H +#define _FLOAT_H +#define _FMTMSG_H +#define _FNMATCH_H +#define _FTS_H_ +#define _FTW_H +#define _GETOPT_H +#define _GLOB_H +#define _GNU_SOURCE 1 +#define _ICONV_H +#define _IFADDRS_H +#define _ILP32 1 +#define _INTTYPES_H +#define _IOFBF 0 +#define _IOLBF 1 +#define _IONBF 2 +#define _ISO646_H +#define _LANGINFO_H +#define _LIBGEN_H +#define _LIMITS_H +#define _LOCALE_H +#define _MALLOC_H +#define _MATH_H +#define _MONETARY_H +#define _MQUEUE_H +#define _NETDB_H +#define _NETINET_ICMP6_H +#define _NETINET_IGMP_H +#define _NETINET_IN_H +#define _NETINET_IN_SYSTM_H +#define _NETINET_IP6_H +#define _NETINET_IP_H +#define _NETINET_IP_ICMP_H +#define _NETINET_TCP_H +#define _NETINET_UDP_H +#define _NETPACKET_PACKET_H +#define _NL_LOCALE_NAME(cat) (((cat)<<16) | 0xffff) +#define _NL_TYPES_H +#define _PC_2_SYMLINKS 20 +#define _PC_ALLOC_SIZE_MIN 18 +#define _PC_ASYNC_IO 10 +#define _PC_CHOWN_RESTRICTED 6 +#define _PC_FILESIZEBITS 13 +#define _PC_LINK_MAX 0 +#define _PC_MAX_CANON 1 +#define _PC_MAX_INPUT 2 +#define _PC_NAME_MAX 3 +#define _PC_NO_TRUNC 7 +#define _PC_PATH_MAX 4 +#define _PC_PIPE_BUF 5 +#define _PC_PRIO_IO 11 +#define _PC_REC_INCR_XFER_SIZE 14 +#define _PC_REC_MAX_XFER_SIZE 15 +#define _PC_REC_MIN_XFER_SIZE 16 +#define _PC_REC_XFER_ALIGN 17 +#define _PC_SOCK_MAXBUF 12 +#define _PC_SYMLINK_MAX 19 +#define _PC_SYNC_IO 9 +#define _PC_VDISABLE 8 +#define _POLL_H +#define _POSIX2_BC_BASE_MAX 99 +#define _POSIX2_BC_DIM_MAX 2048 +#define _POSIX2_BC_SCALE_MAX 99 +#define _POSIX2_BC_STRING_MAX 1000 +#define _POSIX2_CHARCLASS_NAME_MAX 14 +#define _POSIX2_COLL_WEIGHTS_MAX 2 +#define _POSIX2_C_BIND _POSIX_VERSION +#define _POSIX2_EXPR_NEST_MAX 32 +#define _POSIX2_LINE_MAX 2048 +#define _POSIX2_RE_DUP_MAX 255 +#define _POSIX2_VERSION _POSIX_VERSION +#define _POSIX_ADVISORY_INFO _POSIX_VERSION +#define _POSIX_AIO_LISTIO_MAX 2 +#define _POSIX_AIO_MAX 1 +#define _POSIX_ARG_MAX 4096 +#define _POSIX_BARRIERS _POSIX_VERSION +#define _POSIX_CHILD_MAX 25 +#define _POSIX_CHOWN_RESTRICTED 1 +#define _POSIX_CLOCKRES_MIN 20000000 +#define _POSIX_CLOCK_SELECTION _POSIX_VERSION +#define _POSIX_CPUTIME _POSIX_VERSION +#define _POSIX_DELAYTIMER_MAX 32 +#define _POSIX_FSYNC _POSIX_VERSION +#define _POSIX_HOST_NAME_MAX 255 +#define _POSIX_IPV6 _POSIX_VERSION +#define _POSIX_LINK_MAX 8 +#define _POSIX_LOGIN_NAME_MAX 9 +#define _POSIX_MAX_CANON 255 +#define _POSIX_MAX_INPUT 255 +#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION +#define _POSIX_MQ_OPEN_MAX 8 +#define _POSIX_MQ_PRIO_MAX 32 +#define _POSIX_NAME_MAX 14 +#define _POSIX_NGROUPS_MAX 8 +#define _POSIX_NO_TRUNC 1 +#define _POSIX_OPEN_MAX 20 +#define _POSIX_PATH_MAX 256 +#define _POSIX_PIPE_BUF 512 +#define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION +#define _POSIX_REALTIME_SIGNALS _POSIX_VERSION +#define _POSIX_REGEXP 1 +#define _POSIX_RE_DUP_MAX 255 +#define _POSIX_RTSIG_MAX 8 +#define _POSIX_SEM_NSEMS_MAX 256 +#define _POSIX_SEM_VALUE_MAX 32767 +#define _POSIX_SIGQUEUE_MAX 32 +#define _POSIX_SPIN_LOCKS _POSIX_VERSION +#define _POSIX_SSIZE_MAX 32767 +#define _POSIX_SS_REPL_MAX 4 +#define _POSIX_STREAM_MAX 8 +#define _POSIX_SYMLINK_MAX 255 +#define _POSIX_SYMLOOP_MAX 8 +#define _POSIX_THREADS _POSIX_VERSION +#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION +#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 +#define _POSIX_THREAD_KEYS_MAX 128 +#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION +#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION +#define _POSIX_THREAD_THREADS_MAX 64 +#define _POSIX_TIMEOUTS _POSIX_VERSION +#define _POSIX_TIMERS _POSIX_VERSION +#define _POSIX_TIMER_MAX 32 +#define _POSIX_TRACE_EVENT_NAME_MAX 30 +#define _POSIX_TRACE_NAME_MAX 8 +#define _POSIX_TRACE_SYS_MAX 8 +#define _POSIX_TRACE_USER_EVENT_MAX 32 +#define _POSIX_TTY_NAME_MAX 9 +#define _POSIX_TZNAME_MAX 6 +#define _POSIX_V6_ILP32_OFFBIG (1) +#define _POSIX_V7_ILP32_OFFBIG (1) +#define _POSIX_VDISABLE 0 +#define _POSIX_VERSION 200809L +#define _PTHREAD_H +#define _PTRDIFF_T +#define _REGEX_H +#define _SCHED_H +#define _SC_2_CHAR_TERM 95 +#define _SC_2_C_BIND 47 +#define _SC_2_C_DEV 48 +#define _SC_2_FORT_DEV 49 +#define _SC_2_FORT_RUN 50 +#define _SC_2_LOCALEDEF 52 +#define _SC_2_PBS 168 +#define _SC_2_PBS_ACCOUNTING 169 +#define _SC_2_PBS_CHECKPOINT 175 +#define _SC_2_PBS_LOCATE 170 +#define _SC_2_PBS_MESSAGE 171 +#define _SC_2_PBS_TRACK 172 +#define _SC_2_SW_DEV 51 +#define _SC_2_UPE 97 +#define _SC_2_VERSION 46 +#define _SC_ADVISORY_INFO 132 +#define _SC_AIO_LISTIO_MAX 23 +#define _SC_AIO_MAX 24 +#define _SC_AIO_PRIO_DELTA_MAX 25 +#define _SC_ARG_MAX 0 +#define _SC_ASYNCHRONOUS_IO 12 +#define _SC_ATEXIT_MAX 87 +#define _SC_AVPHYS_PAGES 86 +#define _SC_BARRIERS 133 +#define _SC_BC_BASE_MAX 36 +#define _SC_BC_DIM_MAX 37 +#define _SC_BC_SCALE_MAX 38 +#define _SC_BC_STRING_MAX 39 +#define _SC_CHILD_MAX 1 +#define _SC_CLK_TCK 2 +#define _SC_CLOCK_SELECTION 137 +#define _SC_COLL_WEIGHTS_MAX 40 +#define _SC_CPUTIME 138 +#define _SC_DELAYTIMER_MAX 26 +#define _SC_EXPR_NEST_MAX 42 +#define _SC_FSYNC 15 +#define _SC_GETGR_R_SIZE_MAX 69 +#define _SC_GETPW_R_SIZE_MAX 70 +#define _SC_HOST_NAME_MAX 180 +#define _SC_IOV_MAX 60 +#define _SC_IPV6 235 +#define _SC_JOB_CONTROL 7 +#define _SC_LINE_MAX 43 +#define _SC_LOGIN_NAME_MAX 71 +#define _SC_MAPPED_FILES 16 +#define _SC_MEMLOCK 17 +#define _SC_MEMLOCK_RANGE 18 +#define _SC_MEMORY_PROTECTION 19 +#define _SC_MESSAGE_PASSING 20 +#define _SC_MINSIGSTKSZ 249 +#define _SC_MONOTONIC_CLOCK 149 +#define _SC_MQ_OPEN_MAX 27 +#define _SC_MQ_PRIO_MAX 28 +#define _SC_NGROUPS_MAX 3 +#define _SC_NPROCESSORS_CONF 83 +#define _SC_NPROCESSORS_ONLN 84 +#define _SC_NZERO 109 +#define _SC_OPEN_MAX 4 +#define _SC_PAGESIZE 30 +#define _SC_PAGE_SIZE 30 +#define _SC_PASS_MAX 88 +#define _SC_PHYS_PAGES 85 +#define _SC_PRIORITIZED_IO 13 +#define _SC_PRIORITY_SCHEDULING 10 +#define _SC_RAW_SOCKETS 236 +#define _SC_READER_WRITER_LOCKS 153 +#define _SC_REALTIME_SIGNALS 9 +#define _SC_REGEXP 155 +#define _SC_RE_DUP_MAX 44 +#define _SC_RTSIG_MAX 31 +#define _SC_SAVED_IDS 8 +#define _SC_SEMAPHORES 21 +#define _SC_SEM_NSEMS_MAX 32 +#define _SC_SEM_VALUE_MAX 33 +#define _SC_SHARED_MEMORY_OBJECTS 22 +#define _SC_SHELL 157 +#define _SC_SIGQUEUE_MAX 34 +#define _SC_SIGSTKSZ 250 +#define _SC_SPAWN 159 +#define _SC_SPIN_LOCKS 154 +#define _SC_SPORADIC_SERVER 160 +#define _SC_SS_REPL_MAX 241 +#define _SC_STREAMS 174 +#define _SC_STREAM_MAX 5 +#define _SC_SYMLOOP_MAX 173 +#define _SC_SYNCHRONIZED_IO 14 +#define _SC_THREADS 67 +#define _SC_THREAD_ATTR_STACKADDR 77 +#define _SC_THREAD_ATTR_STACKSIZE 78 +#define _SC_THREAD_CPUTIME 139 +#define _SC_THREAD_DESTRUCTOR_ITERATIONS 73 +#define _SC_THREAD_KEYS_MAX 74 +#define _SC_THREAD_PRIORITY_SCHEDULING 79 +#define _SC_THREAD_PRIO_INHERIT 80 +#define _SC_THREAD_PRIO_PROTECT 81 +#define _SC_THREAD_PROCESS_SHARED 82 +#define _SC_THREAD_ROBUST_PRIO_INHERIT 247 +#define _SC_THREAD_ROBUST_PRIO_PROTECT 248 +#define _SC_THREAD_SAFE_FUNCTIONS 68 +#define _SC_THREAD_SPORADIC_SERVER 161 +#define _SC_THREAD_STACK_MIN 75 +#define _SC_THREAD_THREADS_MAX 76 +#define _SC_TIMEOUTS 164 +#define _SC_TIMERS 11 +#define _SC_TIMER_MAX 35 +#define _SC_TRACE 181 +#define _SC_TRACE_EVENT_FILTER 182 +#define _SC_TRACE_EVENT_NAME_MAX 242 +#define _SC_TRACE_INHERIT 183 +#define _SC_TRACE_LOG 184 +#define _SC_TRACE_NAME_MAX 243 +#define _SC_TRACE_SYS_MAX 244 +#define _SC_TRACE_USER_EVENT_MAX 245 +#define _SC_TTY_NAME_MAX 72 +#define _SC_TYPED_MEMORY_OBJECTS 165 +#define _SC_TZNAME_MAX 6 +#define _SC_UIO_MAXIOV 60 +#define _SC_V6_ILP32_OFF32 176 +#define _SC_V6_ILP32_OFFBIG 177 +#define _SC_V6_LP64_OFF64 178 +#define _SC_V6_LPBIG_OFFBIG 179 +#define _SC_V7_ILP32_OFF32 237 +#define _SC_V7_ILP32_OFFBIG 238 +#define _SC_V7_LP64_OFF64 239 +#define _SC_V7_LPBIG_OFFBIG 240 +#define _SC_VERSION 29 +#define _SC_XBS5_ILP32_OFF32 125 +#define _SC_XBS5_ILP32_OFFBIG 126 +#define _SC_XBS5_LP64_OFF64 127 +#define _SC_XBS5_LPBIG_OFFBIG 128 +#define _SC_XOPEN_CRYPT 92 +#define _SC_XOPEN_ENH_I18N 93 +#define _SC_XOPEN_LEGACY 129 +#define _SC_XOPEN_REALTIME 130 +#define _SC_XOPEN_REALTIME_THREADS 131 +#define _SC_XOPEN_SHM 94 +#define _SC_XOPEN_STREAMS 246 +#define _SC_XOPEN_UNIX 91 +#define _SC_XOPEN_VERSION 89 +#define _SC_XOPEN_XCU_VERSION 90 +#define _SC_XOPEN_XPG2 98 +#define _SC_XOPEN_XPG3 99 +#define _SC_XOPEN_XPG4 100 +#define _SEARCH_H +#define _SEMAPHORE_H +#define _SIZE_T +#define _STDALIGN_H +#define _STDBOOL_H +#define _STDC_PREDEF_H +#define _STDINT_H +#define _STDIO_EXT_H +#define _STDIO_H +#define _STDLIB_H +#define _STDNORETURN_H +#define _STRINGS_H +#define _STRING_H +#define _STROPTS_H +#define _SYSEXITS_H +#define _SYS_EVENTFD_H +#define _SYS_FILE_H +#define _SYS_IOCTL_H +#define _SYS_PARAM_H +#define _SYS_RANDOM_H +#define _SYS_REG_H +#define _SYS_SELECT_H +#define _SYS_SOCKET_H +#define _SYS_STATVFS_H +#define _SYS_STAT_H +#define _SYS_SYSCALL_H +#define _SYS_SYSINFO_H +#define _SYS_TIMEB_H +#define _SYS_TIMEX_H +#define _SYS_TIME_H +#define _SYS_TTYDEFAULTS_H +#define _SYS_TYPES_H +#define _SYS_UIO_H +#define _SYS_UN_H +#define _SYS_UTSNAME_H +#define _TAR_H +#define _TGMATH_H +#define _THREADS_H +#define _TIME_H +#define _UCHAR_H +#define _UNISTD_H +#define _UTIME_H +#define _VALUES_H +#define _VA_LIST +#define _WCHAR_H +#define _WCHAR_T +#define _WCTYPE_H +#define _WINT_T +#define _XOPEN_ENH_I18N 1 +#define _XOPEN_IOV_MAX 16 +#define _XOPEN_NAME_MAX 255 +#define _XOPEN_PATH_MAX 1024 +#define _XOPEN_UNIX 1 +#define _XOPEN_VERSION 700 +#define __ARE_4_EQUAL(a,b) (!( (0[a]-0[b]) | (1[a]-1[b]) | (2[a]-2[b]) | (3[a]-3[b]) )) +#define __ATOMIC_ACQUIRE 2 +#define __ATOMIC_ACQ_REL 4 +#define __ATOMIC_CONSUME 1 +#define __ATOMIC_RELAXED 0 +#define __ATOMIC_RELEASE 3 +#define __ATOMIC_SEQ_CST 5 +#define __BIGGEST_ALIGNMENT__ 16 +#define __BIG_ENDIAN 4321 +#define __BIND 19950621 +#define __BINDINGS_WASIP3_H +#define __BYTE_ORDER __BYTE_ORDER__ +#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__ +#define __CHAR16_TYPE__ unsigned short +#define __CHAR32_TYPE__ unsigned int +#define __CHAR_BIT__ 8 +#define __compiler_ATOMIC_BOOL_LOCK_FREE 2 +#define __compiler_ATOMIC_CHAR16_T_LOCK_FREE 2 +#define __compiler_ATOMIC_CHAR32_T_LOCK_FREE 2 +#define __compiler_ATOMIC_CHAR_LOCK_FREE 2 +#define __compiler_ATOMIC_INT_LOCK_FREE 2 +#define __compiler_ATOMIC_LLONG_LOCK_FREE 2 +#define __compiler_ATOMIC_LONG_LOCK_FREE 2 +#define __compiler_ATOMIC_POINTER_LOCK_FREE 2 +#define __compiler_ATOMIC_SHORT_LOCK_FREE 2 +#define __compiler_ATOMIC_WCHAR_T_LOCK_FREE 2 +#define __CLANG_MAX_ALIGN_T_DEFINED +#define __CMPLX(x,y,t) (__builtin_complex((t)(x), (t)(y))) +#define __CONSTANT_CFSTRINGS__ 1 +#define __DBLCX(x) (__IS_CX(x) && sizeof(x) == sizeof(double complex)) +#define __DBL_DECIMAL_DIG__ 17 +#define __DBL_DENORM_MIN__ 4.9406564584124654e-324 +#define __DBL_DIG__ 15 +#define __DBL_EPSILON__ 2.2204460492503131e-16 +#define __DBL_HAS_DENORM__ 1 +#define __DBL_HAS_INFINITY__ 1 +#define __DBL_HAS_QUIET_NAN__ 1 +#define __DBL_MANT_DIG__ 53 +#define __DBL_MAX_10_EXP__ 308 +#define __DBL_MAX_EXP__ 1024 +#define __DBL_MAX__ 1.7976931348623157e+308 +#define __DBL_MIN_10_EXP__ (-307) +#define __DBL_MIN_EXP__ (-1021) +#define __DBL_MIN__ 2.2250738585072014e-308 +#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__ +#define __DEFINED_FILE +#define __DEFINED___isoc_va_list +#define __DEFINED_blkcnt_t +#define __DEFINED_blksize_t +#define __DEFINED_clock_t +#define __DEFINED_clockid_t +#define __DEFINED_cnd_t +#define __DEFINED_dev_t +#define __DEFINED_double_t +#define __DEFINED_float_t +#define __DEFINED_fsblkcnt_t +#define __DEFINED_fsfilcnt_t +#define __DEFINED_gid_t +#define __DEFINED_id_t +#define __DEFINED_ino_t +#define __DEFINED_int16_t +#define __DEFINED_int32_t +#define __DEFINED_int64_t +#define __DEFINED_int8_t +#define __DEFINED_intmax_t +#define __DEFINED_intptr_t +#define __DEFINED_key_t +#define __DEFINED_locale_t +#define __DEFINED_mbstate_t +#define __DEFINED_mode_t +#define __DEFINED_mtx_t +#define __DEFINED_nlink_t +#define __DEFINED_off_t +#define __DEFINED_pid_t +#define __DEFINED_pthread_attr_t +#define __DEFINED_pthread_barrier_t +#define __DEFINED_pthread_barrierattr_t +#define __DEFINED_pthread_cond_t +#define __DEFINED_pthread_condattr_t +#define __DEFINED_pthread_key_t +#define __DEFINED_pthread_mutex_t +#define __DEFINED_pthread_mutexattr_t +#define __DEFINED_pthread_once_t +#define __DEFINED_pthread_rwlock_t +#define __DEFINED_pthread_rwlockattr_t +#define __DEFINED_pthread_spinlock_t +#define __DEFINED_pthread_t +#define __DEFINED_register_t +#define __DEFINED_regoff_t +#define __DEFINED_sa_family_t +#define __DEFINED_sigset_t +#define __DEFINED_size_t +#define __DEFINED_socklen_t +#define __DEFINED_ssize_t +#define __DEFINED_suseconds_t +#define __DEFINED_time_t +#define __DEFINED_timer_t +#define __DEFINED_u_int64_t +#define __DEFINED_uid_t +#define __DEFINED_uint16_t +#define __DEFINED_uint32_t +#define __DEFINED_uint64_t +#define __DEFINED_uint8_t +#define __DEFINED_uintmax_t +#define __DEFINED_uintptr_t +#define __DEFINED_useconds_t +#define __DEFINED_va_list +#define __DEFINED_wchar_t +#define __DEFINED_wctype_t +#define __DEFINED_wint_t +#define __FINITE_MATH_ONLY__ 0 +#define __FLOAT128__ 1 +#define __FLT(x) (__IS_REAL(x) && sizeof(x) == sizeof(float)) +#define __FLTCX(x) (__IS_CX(x) && sizeof(x) == sizeof(float complex)) +#define __FLT_DECIMAL_DIG__ 9 +#define __FLT_DENORM_MIN__ 1.40129846e-45F +#define __FLT_DIG__ 6 +#define __FLT_EPSILON__ 1.19209290e-7F +#define __FLT_HAS_DENORM__ 1 +#define __FLT_HAS_INFINITY__ 1 +#define __FLT_HAS_QUIET_NAN__ 1 +#define __FLT_MANT_DIG__ 24 +#define __FLT_MAX_10_EXP__ 38 +#define __FLT_MAX_EXP__ 128 +#define __FLT_MAX__ 3.40282347e+38F +#define __FLT_MIN_10_EXP__ (-37) +#define __FLT_MIN_EXP__ (-125) +#define __FLT_MIN__ 1.17549435e-38F +#define __FLT_RADIX__ 2 +#define __compiler_ATOMIC_BOOL_LOCK_FREE 2 +#define __compiler_ATOMIC_CHAR16_T_LOCK_FREE 2 +#define __compiler_ATOMIC_CHAR32_T_LOCK_FREE 2 +#define __compiler_ATOMIC_CHAR_LOCK_FREE 2 +#define __compiler_ATOMIC_INT_LOCK_FREE 2 +#define __compiler_ATOMIC_LLONG_LOCK_FREE 2 +#define __compiler_ATOMIC_LONG_LOCK_FREE 2 +#define __compiler_ATOMIC_POINTER_LOCK_FREE 2 +#define __compiler_ATOMIC_SHORT_LOCK_FREE 2 +#define __GCC_ATOMIC_TEST_AND_SET_TRUEVAL 1 +#define __compiler_ATOMIC_WCHAR_T_LOCK_FREE 2 +#define __GNUC_STDC_INLINE__ 1 +#define __GNUC_VA_LIST 1 +#define __GXX_ABI_VERSION 1002 +#define __ILP32__ 1 +#define __INT16_C_SUFFIX__ +#define __INT16_FMTd__ "hd" +#define __INT16_FMTi__ "hi" +#define __INT16_MAX__ 32767 +#define __INT16_TYPE__ short +#define __INT32_C_SUFFIX__ +#define __INT32_FMTd__ "d" +#define __INT32_FMTi__ "i" +#define __INT32_MAX__ 2147483647 +#define __INT32_TYPE__ int +#define __INT64_C_SUFFIX__ LL +#define __INT64_FMTd__ "lld" +#define __INT64_FMTi__ "lli" +#define __INT64_MAX__ 9223372036854775807LL +#define __INT64_TYPE__ long long int +#define __INT8_C_SUFFIX__ +#define __INT8_FMTd__ "hhd" +#define __INT8_FMTi__ "hhi" +#define __INT8_MAX__ 127 +#define __INT8_TYPE__ signed char +#define __INTMAX_C_SUFFIX__ LL +#define __INTMAX_FMTd__ "lld" +#define __INTMAX_FMTi__ "lli" +#define __INTMAX_MAX__ 9223372036854775807LL +#define __INTMAX_TYPE__ long long int +#define __INTMAX_WIDTH__ 64 +#define __INTPTR_FMTd__ "ld" +#define __INTPTR_FMTi__ "li" +#define __INTPTR_MAX__ 2147483647L +#define __INTPTR_TYPE__ long int +#define __INTPTR_WIDTH__ 32 +#define __INT_FAST16_FMTd__ "hd" +#define __INT_FAST16_FMTi__ "hi" +#define __INT_FAST16_MAX__ 32767 +#define __INT_FAST16_TYPE__ short +#define __INT_FAST32_FMTd__ "d" +#define __INT_FAST32_FMTi__ "i" +#define __INT_FAST32_MAX__ 2147483647 +#define __INT_FAST32_TYPE__ int +#define __INT_FAST64_FMTd__ "lld" +#define __INT_FAST64_FMTi__ "lli" +#define __INT_FAST64_MAX__ 9223372036854775807LL +#define __INT_FAST64_TYPE__ long long int +#define __INT_FAST8_FMTd__ "hhd" +#define __INT_FAST8_FMTi__ "hhi" +#define __INT_FAST8_MAX__ 127 +#define __INT_FAST8_TYPE__ signed char +#define __INT_LEAST16_FMTd__ "hd" +#define __INT_LEAST16_FMTi__ "hi" +#define __INT_LEAST16_MAX__ 32767 +#define __INT_LEAST16_TYPE__ short +#define __INT_LEAST32_FMTd__ "d" +#define __INT_LEAST32_FMTi__ "i" +#define __INT_LEAST32_MAX__ 2147483647 +#define __INT_LEAST32_TYPE__ int +#define __INT_LEAST64_FMTd__ "lld" +#define __INT_LEAST64_FMTi__ "lli" +#define __INT_LEAST64_MAX__ 9223372036854775807LL +#define __INT_LEAST64_TYPE__ long long int +#define __INT_LEAST8_FMTd__ "hhd" +#define __INT_LEAST8_FMTi__ "hhi" +#define __INT_LEAST8_MAX__ 127 +#define __INT_LEAST8_TYPE__ signed char +#define __INT_MAX__ 2147483647 +#define __IS_CX(x) (__IS_FP(x) && sizeof(x) == sizeof((x)+I)) +#define __IS_FP(x) (sizeof((x)+1ULL) == sizeof((x)+1.0f)) +#define __IS_REAL(x) (__IS_FP(x) && 2*sizeof(x) == sizeof((x)+I)) +#define __LDBL(x) (__IS_REAL(x) && sizeof(x) == sizeof(long double) && sizeof(long double) != sizeof(double)) +#define __LDBLCX(x) (__IS_CX(x) && sizeof(x) == sizeof(long double complex) && sizeof(long double) != sizeof(double)) +#define __LDBL_DECIMAL_DIG__ 36 +#define __LDBL_DENORM_MIN__ 6.47517511943802511092443895822764655e-4966L +#define __LDBL_DIG__ 33 +#define __LDBL_EPSILON__ 1.92592994438723585305597794258492732e-34L +#define __LDBL_HAS_DENORM__ 1 +#define __LDBL_HAS_INFINITY__ 1 +#define __LDBL_HAS_QUIET_NAN__ 1 +#define __LDBL_MANT_DIG__ 113 +#define __LDBL_MAX_10_EXP__ 4932 +#define __LDBL_MAX_EXP__ 16384 +#define __LDBL_MAX__ 1.18973149535723176508575932662800702e+4932L +#define __LDBL_MIN_10_EXP__ (-4931) +#define __LDBL_MIN_EXP__ (-16381) +#define __LDBL_MIN__ 3.36210314311209350626267781732175260e-4932L +#define __LITTLE_ENDIAN 1234 +#define __LITTLE_ENDIAN__ 1 +#define __LONG_LONG_MAX__ 9223372036854775807LL +#define __LONG_MAX __LONG_MAX__ +#define __LONG_MAX__ 2147483647L +#define __NAMESER 19991006 +#define __NEED_FILE +#define __NEED___isoc_va_list +#define __NEED_blkcnt_t +#define __NEED_blksize_t +#define __NEED_clock_t +#define __NEED_clockid_t +#define __NEED_cnd_t +#define __NEED_dev_t +#define __NEED_double_t +#define __NEED_float_t +#define __NEED_fsblkcnt_t +#define __NEED_fsfilcnt_t +#define __NEED_gid_t +#define __NEED_id_t +#define __NEED_ino_t +#define __NEED_int16_t +#define __NEED_int32_t +#define __NEED_int64_t +#define __NEED_int8_t +#define __NEED_intmax_t +#define __NEED_intptr_t +#define __NEED_key_t +#define __NEED_locale_t +#define __NEED_mbstate_t +#define __NEED_mode_t +#define __NEED_mtx_t +#define __NEED_nlink_t +#define __NEED_off_t +#define __NEED_pid_t +#define __NEED_pthread_attr_t +#define __NEED_pthread_barrier_t +#define __NEED_pthread_barrierattr_t +#define __NEED_pthread_cond_t +#define __NEED_pthread_condattr_t +#define __NEED_pthread_key_t +#define __NEED_pthread_mutex_t +#define __NEED_pthread_mutexattr_t +#define __NEED_pthread_once_t +#define __NEED_pthread_rwlock_t +#define __NEED_pthread_rwlockattr_t +#define __NEED_pthread_spinlock_t +#define __NEED_pthread_t +#define __NEED_register_t +#define __NEED_regoff_t +#define __NEED_sa_family_t +#define __NEED_sigset_t +#define __NEED_size_t +#define __NEED_socklen_t +#define __NEED_ssize_t +#define __NEED_struct_iovec +#define __NEED_struct_timespec +#define __NEED_struct_timeval +#define __NEED_suseconds_t +#define __NEED_time_t +#define __NEED_timer_t +#define __NEED_u_int64_t +#define __NEED_uid_t +#define __NEED_uint16_t +#define __NEED_uint32_t +#define __NEED_uint64_t +#define __NEED_uint8_t +#define __NEED_uintmax_t +#define __NEED_uintptr_t +#define __NEED_useconds_t +#define __NEED_va_list +#define __NEED_wchar_t +#define __NEED_wctype_t +#define __NEED_wint_t +#define __OBJC_BOOL_IS_BOOL 0 +#define __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES 3 +#define __OPENCL_MEMORY_SCOPE_DEVICE 2 +#define __OPENCL_MEMORY_SCOPE_SUB_GROUP 4 +#define __OPENCL_MEMORY_SCOPE_WORK_GROUP 1 +#define __OPENCL_MEMORY_SCOPE_WORK_ITEM 0 +#define __ORDER_BIG_ENDIAN__ 4321 +#define __ORDER_LITTLE_ENDIAN__ 1234 +#define __ORDER_PDP_ENDIAN__ 3412 +#define __PDP_ENDIAN 3412 +#define __POINTER_WIDTH__ 32 +#define __PRAGMA_REDEFINE_EXTNAME 1 +#define __PTRDIFF_FMTd__ "ld" +#define __PTRDIFF_FMTi__ "li" +#define __PTRDIFF_MAX__ 2147483647L +#define __PTRDIFF_TYPE__ long int +#define __PTRDIFF_WIDTH__ 32 +#define __REDIR(x,y) __typeof__(x) x __asm__(#y) +#define __RETCAST(x) +#define __RETCAST_2(x,y) +#define __RETCAST_3(x,y,z) +#define __RETCAST_CX(x) +#define __RETCAST_REAL(x) +#define __SCHAR_MAX__ 127 +#define __SHRT_MAX__ 32767 +#define __SID ('S' << 8) +#define __SIG_ATOMIC_MAX__ 2147483647L +#define __SIG_ATOMIC_WIDTH__ 32 +#define __SIZEOF_DOUBLE__ 8 +#define __SIZEOF_FLOAT__ 4 +#define __SIZEOF_INT128__ 16 +#define __SIZEOF_INT__ 4 +#define __SIZEOF_LONG_DOUBLE__ 16 +#define __SIZEOF_LONG_LONG__ 8 +#define __SIZEOF_LONG__ 4 +#define __SIZEOF_POINTER__ 4 +#define __SIZEOF_PTRDIFF_T__ 4 +#define __SIZEOF_SHORT__ 2 +#define __SIZEOF_SIZE_T__ 4 +#define __SIZEOF_WCHAR_T__ 4 +#define __SIZEOF_WINT_T__ 4 +#define __SIZE_FMTX__ "lX" +#define __SIZE_FMTo__ "lo" +#define __SIZE_FMTu__ "lu" +#define __SIZE_FMTx__ "lx" +#define __SIZE_MAX__ 4294967295UL +#define __SIZE_TYPE__ long unsigned int +#define __SIZE_WIDTH__ 32 +#define __STDARG_H +#define __STDC_HOSTED__ 1 +#define __STDC_IEC_559__ 1 +#define __STDC_ISO_10646__ 201206L +#define __STDC_UTF_16__ 1 +#define __STDC_UTF_32__ 1 +#define __STDC_VERSION__ 201710L +#define __STDC__ 1 +#define __STDDEF_H +#define __UAPI_DEF_IN6_ADDR 0 +#define __UAPI_DEF_IN6_ADDR_ALT 0 +#define __UAPI_DEF_IN6_PKTINFO 0 +#define __UAPI_DEF_IN_ADDR 0 +#define __UAPI_DEF_IN_CLASS 0 +#define __UAPI_DEF_IN_IPPROTO 0 +#define __UAPI_DEF_IN_PKTINFO 0 +#define __UAPI_DEF_IP6_MTUINFO 0 +#define __UAPI_DEF_IPHDR 0 +#define __UAPI_DEF_IPPROTO_V6 0 +#define __UAPI_DEF_IPV6_MREQ 0 +#define __UAPI_DEF_IPV6_OPTIONS 0 +#define __UAPI_DEF_IP_MREQ 0 +#define __UAPI_DEF_SOCKADDR_IN 0 +#define __UAPI_DEF_SOCKADDR_IN6 0 +#define __UINT16_C_SUFFIX__ +#define __UINT16_FMTX__ "hX" +#define __UINT16_FMTo__ "ho" +#define __UINT16_FMTu__ "hu" +#define __UINT16_FMTx__ "hx" +#define __UINT16_MAX__ 65535 +#define __UINT16_TYPE__ unsigned short +#define __UINT32_C_SUFFIX__ U +#define __UINT32_FMTX__ "X" +#define __UINT32_FMTo__ "o" +#define __UINT32_FMTu__ "u" +#define __UINT32_FMTx__ "x" +#define __UINT32_MAX__ 4294967295U +#define __UINT32_TYPE__ unsigned int +#define __UINT64_C_SUFFIX__ ULL +#define __UINT64_FMTX__ "llX" +#define __UINT64_FMTo__ "llo" +#define __UINT64_FMTu__ "llu" +#define __UINT64_FMTx__ "llx" +#define __UINT64_MAX__ 18446744073709551615ULL +#define __UINT64_TYPE__ long long unsigned int +#define __UINT8_C_SUFFIX__ +#define __UINT8_FMTX__ "hhX" +#define __UINT8_FMTo__ "hho" +#define __UINT8_FMTu__ "hhu" +#define __UINT8_FMTx__ "hhx" +#define __UINT8_MAX__ 255 +#define __UINT8_TYPE__ unsigned char +#define __UINTMAX_C_SUFFIX__ ULL +#define __UINTMAX_FMTX__ "llX" +#define __UINTMAX_FMTo__ "llo" +#define __UINTMAX_FMTu__ "llu" +#define __UINTMAX_FMTx__ "llx" +#define __UINTMAX_MAX__ 18446744073709551615ULL +#define __UINTMAX_TYPE__ long long unsigned int +#define __UINTMAX_WIDTH__ 64 +#define __UINTPTR_FMTX__ "lX" +#define __UINTPTR_FMTo__ "lo" +#define __UINTPTR_FMTu__ "lu" +#define __UINTPTR_FMTx__ "lx" +#define __UINTPTR_MAX__ 4294967295UL +#define __UINTPTR_TYPE__ long unsigned int +#define __UINTPTR_WIDTH__ 32 +#define __UINT_FAST16_FMTX__ "hX" +#define __UINT_FAST16_FMTo__ "ho" +#define __UINT_FAST16_FMTu__ "hu" +#define __UINT_FAST16_FMTx__ "hx" +#define __UINT_FAST16_MAX__ 65535 +#define __UINT_FAST16_TYPE__ unsigned short +#define __UINT_FAST32_FMTX__ "X" +#define __UINT_FAST32_FMTo__ "o" +#define __UINT_FAST32_FMTu__ "u" +#define __UINT_FAST32_FMTx__ "x" +#define __UINT_FAST32_MAX__ 4294967295U +#define __UINT_FAST32_TYPE__ unsigned int +#define __UINT_FAST64_FMTX__ "llX" +#define __UINT_FAST64_FMTo__ "llo" +#define __UINT_FAST64_FMTu__ "llu" +#define __UINT_FAST64_FMTx__ "llx" +#define __UINT_FAST64_MAX__ 18446744073709551615ULL +#define __UINT_FAST64_TYPE__ long long unsigned int +#define __UINT_FAST8_FMTX__ "hhX" +#define __UINT_FAST8_FMTo__ "hho" +#define __UINT_FAST8_FMTu__ "hhu" +#define __UINT_FAST8_FMTx__ "hhx" +#define __UINT_FAST8_MAX__ 255 +#define __UINT_FAST8_TYPE__ unsigned char +#define __UINT_LEAST16_FMTX__ "hX" +#define __UINT_LEAST16_FMTo__ "ho" +#define __UINT_LEAST16_FMTu__ "hu" +#define __UINT_LEAST16_FMTx__ "hx" +#define __UINT_LEAST16_MAX__ 65535 +#define __UINT_LEAST16_TYPE__ unsigned short +#define __UINT_LEAST32_FMTX__ "X" +#define __UINT_LEAST32_FMTo__ "o" +#define __UINT_LEAST32_FMTu__ "u" +#define __UINT_LEAST32_FMTx__ "x" +#define __UINT_LEAST32_MAX__ 4294967295U +#define __UINT_LEAST32_TYPE__ unsigned int +#define __UINT_LEAST64_FMTX__ "llX" +#define __UINT_LEAST64_FMTo__ "llo" +#define __UINT_LEAST64_FMTu__ "llu" +#define __UINT_LEAST64_FMTx__ "llx" +#define __UINT_LEAST64_MAX__ 18446744073709551615ULL +#define __UINT_LEAST64_TYPE__ long long unsigned int +#define __UINT_LEAST8_FMTX__ "hhX" +#define __UINT_LEAST8_FMTo__ "hho" +#define __UINT_LEAST8_FMTu__ "hhu" +#define __UINT_LEAST8_FMTx__ "hhx" +#define __UINT_LEAST8_MAX__ 255 +#define __UINT_LEAST8_TYPE__ unsigned char +#define __USER_LABEL_PREFIX__ +#define __USE_TIME_BITS64 1 +#define __WASI_VERSION_H +#define __WASI_WASIP2_H +#define __WASI_WASIP3_H +#define __WCHAR_MAX__ 2147483647 +#define __WCHAR_TYPE__ int +#define __WCHAR_WIDTH__ 32 +#define __WINT_MAX__ 2147483647 +#define __WINT_TYPE__ int +#define __WINT_WIDTH__ 32 +#define __WORDSIZE 64 +#define __alignas_is_defined 1 +#define __alignof_is_defined 1 +#define __bitop(x,i,o) ((x)[(i)/8] o (1<<(i)%8)) +#define __bool_true_false_are_defined 1 +#define __fts_dev_t dev_t +#define __fts_ino_t ino_t +#define __fts_length_t unsigned int +#define __fts_level_t int +#define __fts_nlink_t nlink_t +#define __fts_number_t int64_t +#define __fts_stat_t struct stat +#define __inline inline +#define __restrict restrict +#define __tg_complex(fun,x) (__RETCAST_CX(x)( __FLTCX((x)+I) && __IS_FP(x) ? fun ## f (x) : __LDBLCX((x)+I) ? fun ## l (x) : fun(x) )) +#define __tg_complex_retreal(fun,x) (__RETCAST_REAL(x)( __FLTCX((x)+I) && __IS_FP(x) ? fun ## f (x) : __LDBLCX((x)+I) ? fun ## l (x) : fun(x) )) +#define __tg_real(fun,x) (__RETCAST(x)__tg_real_nocast(fun, x)) +#define __tg_real_2(fun,x,y) (__RETCAST_2(x, y)( __FLT(x) && __FLT(y) ? fun ## f (x, y) : __LDBL((x)+(y)) ? fun ## l (x, y) : fun(x, y) )) +#define __tg_real_2_1(fun,x,y) (__RETCAST(x)( __FLT(x) ? fun ## f (x, y) : __LDBL(x) ? fun ## l (x, y) : fun(x, y) )) +#define __tg_real_complex(fun,x) (__RETCAST(x)( __FLTCX(x) ? c ## fun ## f (x) : __DBLCX(x) ? c ## fun (x) : __LDBLCX(x) ? c ## fun ## l (x) : __FLT(x) ? fun ## f (x) : __LDBL(x) ? fun ## l (x) : fun(x) )) +#define __tg_real_complex_fabs(x) (__RETCAST_REAL(x)( __FLTCX(x) ? cabsf(x) : __DBLCX(x) ? cabs(x) : __LDBLCX(x) ? cabsl(x) : __FLT(x) ? fabsf(x) : __LDBL(x) ? fabsl(x) : fabs(x) )) +#define __tg_real_complex_pow(x,y) (__RETCAST_2(x, y)( __FLTCX((x)+(y)) && __IS_FP(x) && __IS_FP(y) ? cpowf(x, y) : __FLTCX((x)+(y)) ? cpow(x, y) : __DBLCX((x)+(y)) ? cpow(x, y) : __LDBLCX((x)+(y)) ? cpowl(x, y) : __FLT(x) && __FLT(y) ? powf(x, y) : __LDBL((x)+(y)) ? powl(x, y) : pow(x, y) )) +#define __tg_real_fma(x,y,z) (__RETCAST_3(x, y, z)( __FLT(x) && __FLT(y) && __FLT(z) ? fmaf(x, y, z) : __LDBL((x)+(y)+(z)) ? fmal(x, y, z) : fma(x, y, z) )) +#define __tg_real_nocast(fun,x) ( __FLT(x) ? fun ## f (x) : __LDBL(x) ? fun ## l (x) : fun(x) ) +#define __tg_real_remquo(x,y,z) (__RETCAST_2(x, y)( __FLT(x) && __FLT(y) ? remquof(x, y, z) : __LDBL((x)+(y)) ? remquol(x, y, z) : remquo(x, y, z) )) +#define __tm_gmtoff tm_gmtoff +#define __tm_zone tm_zone +#define __va_copy(d,s) __builtin_va_copy(d, s) +#define __wasi__ 1 +#define __wasi_api_h +#define __wasi_libc_busywait_h +#define __wasi_libc_environ_h +#define __wasi_libc_find_relpath_h +#define __wasi_libc_h +#define __wasi_libc_nocwd_h +#define __wasi_wasip1_h +#define __wasilibc___errno_h +#define __wasilibc___errno_values_h +#define __wasilibc___fd_set_h +#define __wasilibc___function___isatty_h +#define __wasilibc___functions_malloc_h +#define __wasilibc___functions_memcpy_h +#define __wasilibc___header_dirent_h +#define __wasilibc___header_fcntl_h +#define __wasilibc___header_netinet_in_h +#define __wasilibc___header_poll_h +#define __wasilibc___header_stdlib_h +#define __wasilibc___header_string_h +#define __wasilibc___header_sys_ioctl_h +#define __wasilibc___header_sys_resource_h +#define __wasilibc___header_sys_socket_h +#define __wasilibc___header_sys_stat_h +#define __wasilibc___header_time_h +#define __wasilibc___header_unistd_h +#define __wasilibc___include_inttypes_h +#define __wasilibc___macro_FD_SETSIZE_h +#define __wasilibc___macro_PAGESIZE_h +#define __wasilibc___mode_t_h +#define __wasilibc___seek_h +#define __wasilibc___struct_dirent_h +#define __wasilibc___struct_in6_addr_h +#define __wasilibc___struct_in_addr_h +#define __wasilibc___struct_iovec_h +#define __wasilibc___struct_msghdr_h +#define __wasilibc___struct_pollfd_h +#define __wasilibc___struct_rusage_h +#define __wasilibc___struct_sockaddr_h +#define __wasilibc___struct_sockaddr_in6_h +#define __wasilibc___struct_sockaddr_in_h +#define __wasilibc___struct_sockaddr_storage_h +#define __wasilibc___struct_sockaddr_un_h +#define __wasilibc___struct_stat_h +#define __wasilibc___struct_timespec_h +#define __wasilibc___struct_timeval_h +#define __wasilibc___struct_tm_h +#define __wasilibc___struct_tms_h +#define __wasilibc___typedef_DIR_h +#define __wasilibc___typedef_blkcnt_t_h +#define __wasilibc___typedef_blksize_t_h +#define __wasilibc___typedef_clock_t_h +#define __wasilibc___typedef_clockid_t_h +#define __wasilibc___typedef_dev_t_h +#define __wasilibc___typedef_fd_set_h +#define __wasilibc___typedef_gid_t_h +#define __wasilibc___typedef_in_addr_t_h +#define __wasilibc___typedef_in_port_t_h +#define __wasilibc___typedef_ino_t_h +#define __wasilibc___typedef_mode_t_h +#define __wasilibc___typedef_nfds_t_h +#define __wasilibc___typedef_nlink_t_h +#define __wasilibc___typedef_off_t_h +#define __wasilibc___typedef_sa_family_t_h +#define __wasilibc___typedef_sigset_t_h +#define __wasilibc___typedef_socklen_t_h +#define __wasilibc___typedef_ssize_t_h +#define __wasilibc___typedef_suseconds_t_h +#define __wasilibc___typedef_time_t_h +#define __wasilibc___typedef_uid_t_h +#define __wasip3__ +#define __wasm 1 +#define __wasm32 1 +#define __wasm32__ 1 +#define __wasm__ 1 +#define _tolower(a) ((a)|0x20) +#define _toupper(a) ((a)&0x5f) +#define acos(x) __tg_real_complex(acos, (x)) +#define acosh(x) __tg_real_complex(acosh, (x)) +#define alignas _Alignas +#define alignof _Alignof +#define alloca __builtin_alloca +#define alphasort64 alphasort +#define and && +#define and_eq &= +#define asin(x) __tg_real_complex(asin, (x)) +#define asinh(x) __tg_real_complex(asinh, (x)) +#define atan(x) __tg_real_complex(atan, (x)) +#define atan2(x,y) __tg_real_2(atan2, (x), (y)) +#define atanh(x) __tg_real_complex(atanh, (x)) +#define be16toh(x) __bswap16(x) +#define be32toh(x) __bswap32(x) +#define be64toh(x) __bswap64(x) +#define betoh16(x) __bswap16(x) +#define betoh32(x) __bswap32(x) +#define betoh64(x) __bswap64(x) +#define bitand & +#define bitor | +#define blkcnt64_t blkcnt_t +#define bool _Bool +#define bswap_16(x) __bswap_16(x) +#define bswap_32(x) __bswap_32(x) +#define bswap_64(x) __bswap_64(x) +#define carg(x) __tg_complex_retreal(carg, (x)) +#define cbrt(x) __tg_real(cbrt, (x)) +#define ceil(x) __tg_real(ceil, (x)) +#define cimag(x) __tg_complex_retreal(cimag, (x)) +#define cimagf(x) (__builtin_cimagf(x)) +#define cimagl(x) (__builtin_cimagl(x)) +#define clrbit(x,i) __bitop(x,i,&=~) +#define compl ~ +#define complex _Complex +#define conj(x) __tg_complex(conj, (x)) +#define copysign(x,y) __tg_real_2(copysign, (x), (y)) +#define cos(x) __tg_real_complex(cos, (x)) +#define cosh(x) __tg_real_complex(cosh, (x)) +#define cproj(x) __tg_complex(cproj, (x)) +#define creal(x) __tg_complex_retreal(creal, (x)) +#define crealf(x) (__builtin_crealf(x)) +#define creall(x) (__builtin_creall(x)) +#define creat64 creat +#define d_fileno d_ino +#define direct dirent +#define dirent64 dirent +#define erf(x) __tg_real(erf, (x)) +#define erfc(x) __tg_real(erfc, (x)) +#define errno errno +#define exp(x) __tg_real_complex(exp, (x)) +#define exp2(x) __tg_real(exp2, (x)) +#define expm1(x) __tg_real(expm1, (x)) +#define fabs(x) __tg_real_complex_fabs(x) +#define false 0 +#define fdim(x,y) __tg_real_2(fdim, (x), (y)) +#define fgetpos64 fgetpos +#define floor(x) __tg_real(floor, (x)) +#define fma(x,y,z) __tg_real_fma((x), (y), (z)) +#define fmax(x,y) __tg_real_2(fmax, (x), (y)) +#define fmin(x,y) __tg_real_2(fmin, (x), (y)) +#define fmod(x,y) __tg_real_2(fmod, (x), (y)) +#define fopen64 fopen +#define fpclassify(x) (__builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)) +#define fpos64_t fpos_t +#define freopen64 freopen +#define frexp(x,y) __tg_real_2_1(frexp, (x), (y)) +#define fsblkcnt64_t fsblkcnt_t +#define fseeko64 fseeko +#define fsetpos64 fsetpos +#define fsfilcnt64_t fsfilcnt_t +#define fstat64 fstat +#define fstatat64 fstatat +#define fstatvfs64 fstatvfs +#define ftello64 ftello +#define ftruncate64 ftruncate +#define getdents64 getdents +#define glob64 glob +#define glob64_t glob_t +#define globfree64 globfree +#define h_addr h_addr_list[0] +#define h_errno h_errno +#define howmany(n,d) (((n)+((d)-1))/(d)) +#define htobe16(x) __bswap16(x) +#define htobe32(x) __bswap32(x) +#define htobe64(x) __bswap64(x) +#define htole16(x) (uint16_t)(x) +#define htole32(x) (uint32_t)(x) +#define htole64(x) (uint64_t)(x) +#define hypot(x,y) __tg_real_2(hypot, (x), (y)) +#define icmp6_data16 icmp6_dataun.icmp6_un_data16 +#define icmp6_data32 icmp6_dataun.icmp6_un_data32 +#define icmp6_data8 icmp6_dataun.icmp6_un_data8 +#define icmp6_id icmp6_data16[0] +#define icmp6_maxdelay icmp6_data16[0] +#define icmp6_mtu icmp6_data32[0] +#define icmp6_pptr icmp6_data32[0] +#define icmp6_seq icmp6_data16[1] +#define icmp_data icmp_dun.id_data +#define icmp_gwaddr icmp_hun.ih_gwaddr +#define icmp_id icmp_hun.ih_idseq.icd_id +#define icmp_ip icmp_dun.id_ip.idi_ip +#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime +#define icmp_mask icmp_dun.id_mask +#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu +#define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs +#define icmp_otime icmp_dun.id_ts.its_otime +#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void +#define icmp_pptr icmp_hun.ih_pptr +#define icmp_radv icmp_dun.id_radv +#define icmp_rtime icmp_dun.id_ts.its_rtime +#define icmp_seq icmp_hun.ih_idseq.icd_seq +#define icmp_ttime icmp_dun.id_ts.its_ttime +#define icmp_void icmp_hun.ih_void +#define icmp_wpa icmp_hun.ih_rtradv.irt_wpa +#define ifa_broadaddr ifa_ifu.ifu_broadaddr +#define ifa_dstaddr ifa_ifu.ifu_dstaddr +#define ilogb(x) __tg_real_nocast(ilogb, (x)) +#define ino64_t ino_t +#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow +#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim +#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim +#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt +#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen +#define ip6_vfc ip6_ctlun.ip6_un2_vfc +#define isalpha(a) (0 ? isalpha(a) : (((unsigned)(a)|32)-'a') < 26) +#define isascii(a) (0 ? isascii(a) : (unsigned)(a) < 128) +#define isclr(x,i) !isset(x,i) +#define isdigit(a) (0 ? isdigit(a) : ((unsigned)(a)-'0') < 10) +#define isfinite(x) (__builtin_isfinite(x)) +#define isgraph(a) (0 ? isgraph(a) : ((unsigned)(a)-0x21) < 0x5e) +#define isgreater(x,y) (__builtin_isgreater(x, y)) +#define isgreaterequal(x,y) (__builtin_isgreaterequal(x, y)) +#define isinf(x) (__builtin_isinf(x)) +#define isless(x,y) (__builtin_isless(x, y)) +#define islessequal(x,y) (__builtin_islessequal(x, y)) +#define islessgreater(x,y) (__builtin_islessgreater(x, y)) +#define islower(a) (0 ? islower(a) : ((unsigned)(a)-'a') < 26) +#define isnan(x) (__builtin_isnan(x)) +#define isnormal(x) (__builtin_isnormal(x)) +#define isprint(a) (0 ? isprint(a) : ((unsigned)(a)-0x20) < 0x5f) +#define isset(x,i) __bitop(x,i,&) +#define isspace(a) __isspace(a) +#define isunordered(x,y) (__builtin_isunordered(x, y)) +#define isupper(a) (0 ? isupper(a) : ((unsigned)(a)-'A') < 26) +#define iswdigit(a) (0 ? iswdigit(a) : ((unsigned)(a)-'0') < 10) +#define ldexp(x,y) __tg_real_2_1(ldexp, (x), (y)) +#define le16toh(x) (uint16_t)(x) +#define le32toh(x) (uint32_t)(x) +#define le64toh(x) (uint64_t)(x) +#define letoh16(x) (uint16_t)(x) +#define letoh32(x) (uint32_t)(x) +#define letoh64(x) (uint64_t)(x) +#define lgamma(x) __tg_real(lgamma, (x)) +#define llrint(x) __tg_real_nocast(llrint, (x)) +#define llround(x) __tg_real_nocast(llround, (x)) +#define loff_t off_t +#define log(x) __tg_real_complex(log, (x)) +#define log10(x) __tg_real(log10, (x)) +#define log1p(x) __tg_real(log1p, (x)) +#define log2(x) __tg_real(log2, (x)) +#define logb(x) __tg_real(logb, (x)) +#define lrint(x) __tg_real_nocast(lrint, (x)) +#define lround(x) __tg_real_nocast(lround, (x)) +#define lseek(fd,offset,whence) ({ off_t __f = (fd); off_t __o = (offset); off_t __w = (whence); __builtin_constant_p((offset)) && __builtin_constant_p((whence)) && __o == 0 && __w == SEEK_CUR ? __wasilibc_tell(__f) : lseek(__f, __o, __w); }) +#define lseek64 lseek +#define lstat64 lstat +#define math_errhandling 2 +#define mld_cksum mld_icmp6_hdr.icmp6_cksum +#define mld_code mld_icmp6_hdr.icmp6_code +#define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0] +#define mld_reserved mld_icmp6_hdr.icmp6_data16[1] +#define mld_type mld_icmp6_hdr.icmp6_type +#define nd_na_cksum nd_na_hdr.icmp6_cksum +#define nd_na_code nd_na_hdr.icmp6_code +#define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0] +#define nd_na_type nd_na_hdr.icmp6_type +#define nd_ns_cksum nd_ns_hdr.icmp6_cksum +#define nd_ns_code nd_ns_hdr.icmp6_code +#define nd_ns_reserved nd_ns_hdr.icmp6_data32[0] +#define nd_ns_type nd_ns_hdr.icmp6_type +#define nd_ra_cksum nd_ra_hdr.icmp6_cksum +#define nd_ra_code nd_ra_hdr.icmp6_code +#define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0] +#define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1] +#define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1] +#define nd_ra_type nd_ra_hdr.icmp6_type +#define nd_rd_cksum nd_rd_hdr.icmp6_cksum +#define nd_rd_code nd_rd_hdr.icmp6_code +#define nd_rd_reserved nd_rd_hdr.icmp6_data32[0] +#define nd_rd_type nd_rd_hdr.icmp6_type +#define nd_rs_cksum nd_rs_hdr.icmp6_cksum +#define nd_rs_code nd_rs_hdr.icmp6_code +#define nd_rs_reserved nd_rs_hdr.icmp6_data32[0] +#define nd_rs_type nd_rs_hdr.icmp6_type +#define nearbyint(x) __tg_real(nearbyint, (x)) +#define nextafter(x,y) __tg_real_2(nextafter, (x), (y)) +#define nexttoward(x,y) __tg_real_2(nexttoward, (x), (y)) +#define nftw64 nftw +#define no_argument 0 +#define noreturn _Noreturn +#define not ! +#define not_eq != +#define ns_msg_base(handle) ((handle)._msg + 0) +#define ns_msg_count(handle,section) ((handle)._counts[section] + 0) +#define ns_msg_end(handle) ((handle)._eom + 0) +#define ns_msg_getflag(handle,flag) (((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift) +#define ns_msg_id(handle) ((handle)._id + 0) +#define ns_msg_size(handle) ((handle)._eom - (handle)._msg) +#define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0)) +#define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") +#define ns_rr_rdata(rr) ((rr).rdata + 0) +#define ns_rr_rdlen(rr) ((rr).rdlength + 0) +#define ns_rr_ttl(rr) ((rr).ttl + 0) +#define ns_rr_type(rr) ((ns_type)((rr).type + 0)) +#define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt) +#define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || (t) == ns_t_mailb || (t) == ns_t_maila) +#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t)) +#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr) +#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || (t) == ns_t_zxfr) +#define off64_t off_t +#define offsetof(t,d) __builtin_offsetof(t, d) +#define open64 open +#define openat64 openat +#define optional_argument 2 +#define or || +#define or_eq |= +#define posix_fadvise64 posix_fadvise +#define posix_fallocate64 posix_fallocate +#define pow(x,y) __tg_real_complex_pow((x), (y)) +#define powerof2(n) !(((n)-1) & (n)) +#define pread64 pread +#define preadv64 preadv +#define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0) +#define pthread_cleanup_push(f,x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x); +#define pthread_equal(x,y) ((x)==(y)) +#define pwrite64 pwrite +#define pwritev64 pwritev +#define readdir64 readdir +#define remainder(x,y) __tg_real_2(remainder, (x), (y)) +#define remquo(x,y,z) __tg_real_remquo((x), (y), (z)) +#define required_argument 1 +#define rint(x) __tg_real(rint, (x)) +#define round(x) __tg_real(round, (x)) +#define roundup(n,d) (howmany(n,d)*(d)) +#define rr_cksum rr_hdr.icmp6_cksum +#define rr_code rr_hdr.icmp6_code +#define rr_seqnum rr_hdr.icmp6_data32[0] +#define rr_type rr_hdr.icmp6_type +#define scalbln(x,y) __tg_real_2_1(scalbln, (x), (y)) +#define scalbn(x,y) __tg_real_2_1(scalbn, (x), (y)) +#define scandir64 scandir +#define setbit(x,i) __bitop(x,i,|=) +#define signbit(x) (__builtin_signbit(x)) +#define sin(x) __tg_real_complex(sin, (x)) +#define sinh(x) __tg_real_complex(sinh, (x)) +#define sqrt(x) __tg_real_complex(sqrt, (x)) +#define st_atime st_atim.tv_sec +#define st_ctime st_ctim.tv_sec +#define st_mtime st_mtim.tv_sec +#define stat64 stat +#define static_assert _Static_assert +#define statvfs64 statvfs +#define stderr (stderr) +#define stdin (stdin) +#define stdout (stdout) +#define strdupa(x) strcpy(alloca(strlen(x)+1),x) +#define tan(x) __tg_real_complex(tan, (x)) +#define tanh(x) __tg_real_complex(tanh, (x)) +#define telcmds ((char [][6]){ "EOF", "SUSP", "ABORT", "EOR", "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0 }) +#define tgamma(x) __tg_real(tgamma, (x)) +#define th_block th_u.tu_block +#define th_code th_u.tu_code +#define th_msg th_data +#define th_stuff th_u.tu_stuff +#define thrd_equal(A,B) ((A) == (B)) +#define thread_local _Thread_local +#define timeradd(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && ((a)->tv_usec -= 1000000, (a)->tv_sec++) ) +#define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0) +#define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? (s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec) +#define timerisset(t) ((t)->tv_sec || (t)->tv_usec) +#define timersub(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && ((a)->tv_usec += 1000000, (a)->tv_sec--) ) +#define true 1 +#define trunc(x) __tg_real(trunc, (x)) +#define uh_dport dest +#define uh_sport source +#define uh_sum check +#define uh_ulen len +#define va_arg(ap,type) __builtin_va_arg(ap, type) +#define va_copy(dest,src) __builtin_va_copy(dest, src) +#define va_end(ap) __builtin_va_end(ap) +#define va_start(ap,param) __builtin_va_start(ap, param) +#define versionsort64 versionsort +#define xEOF 236 +#define xor ^ +#define xor_eq ^= diff --git a/expected/wasm32-wasip3/undefined-symbols.txt b/expected/wasm32-wasip3/undefined-symbols.txt new file mode 100644 index 000000000..ec4a54a33 --- /dev/null +++ b/expected/wasm32-wasip3/undefined-symbols.txt @@ -0,0 +1,189 @@ +__addtf3 +__backpressure_dec +__backpressure_inc +__backpressure_set +__context_get +__context_set +__data_end +__divtf3 +__eqtf2 +__extenddftf2 +__extendsftf2 +__fixtfdi +__fixtfsi +__fixunstfsi +__floatsitf +__floatunsitf +__getf2 +__global_base +__gttf2 +__heap_base +__heap_end +__letf2 +__lttf2 +__netf2 +__stack_pointer +__subtask_cancel +__subtask_drop +__subtf3 +__task_cancel +__thread_yield +__thread_yield_cancellable +__trunctfdf2 +__trunctfsf2 +__unordtf2 +__waitable_join +__waitable_set_drop +__waitable_set_new +__waitable_set_poll +__waitable_set_wait +__wasm_call_ctors +__wasm_import_environment_get_arguments +__wasm_import_environment_get_environment +__wasm_import_environment_get_initial_cwd +__wasm_import_exit_exit +__wasm_import_filesystem_descriptor_drop +__wasm_import_filesystem_method_descriptor_advise +__wasm_import_filesystem_method_descriptor_append_via_stream +__wasm_import_filesystem_method_descriptor_create_directory_at +__wasm_import_filesystem_method_descriptor_get_flags +__wasm_import_filesystem_method_descriptor_get_type +__wasm_import_filesystem_method_descriptor_is_same_object +__wasm_import_filesystem_method_descriptor_link_at +__wasm_import_filesystem_method_descriptor_metadata_hash +__wasm_import_filesystem_method_descriptor_metadata_hash_at +__wasm_import_filesystem_method_descriptor_open_at +__wasm_import_filesystem_method_descriptor_read_directory +__wasm_import_filesystem_method_descriptor_read_via_stream +__wasm_import_filesystem_method_descriptor_readlink_at +__wasm_import_filesystem_method_descriptor_remove_directory_at +__wasm_import_filesystem_method_descriptor_rename_at +__wasm_import_filesystem_method_descriptor_set_size +__wasm_import_filesystem_method_descriptor_set_times +__wasm_import_filesystem_method_descriptor_set_times_at +__wasm_import_filesystem_method_descriptor_stat +__wasm_import_filesystem_method_descriptor_stat_at +__wasm_import_filesystem_method_descriptor_symlink_at +__wasm_import_filesystem_method_descriptor_sync +__wasm_import_filesystem_method_descriptor_sync_data +__wasm_import_filesystem_method_descriptor_unlink_file_at +__wasm_import_filesystem_method_descriptor_write_via_stream +__wasm_import_filesystem_preopens_get_directories +__wasm_import_ip_name_lookup_resolve_addresses +__wasm_import_monotonic_clock_get_resolution +__wasm_import_monotonic_clock_now +__wasm_import_monotonic_clock_wait_for +__wasm_import_monotonic_clock_wait_until +__wasm_import_random_get_random_bytes +__wasm_import_random_get_random_u64 +__wasm_import_random_insecure_get_insecure_random_bytes +__wasm_import_random_insecure_get_insecure_random_u64 +__wasm_import_random_insecure_seed_get_insecure_seed +__wasm_import_sockets_method_tcp_socket_bind +__wasm_import_sockets_method_tcp_socket_connect +__wasm_import_sockets_method_tcp_socket_get_address_family +__wasm_import_sockets_method_tcp_socket_get_hop_limit +__wasm_import_sockets_method_tcp_socket_get_is_listening +__wasm_import_sockets_method_tcp_socket_get_keep_alive_count +__wasm_import_sockets_method_tcp_socket_get_keep_alive_enabled +__wasm_import_sockets_method_tcp_socket_get_keep_alive_idle_time +__wasm_import_sockets_method_tcp_socket_get_keep_alive_interval +__wasm_import_sockets_method_tcp_socket_get_local_address +__wasm_import_sockets_method_tcp_socket_get_receive_buffer_size +__wasm_import_sockets_method_tcp_socket_get_remote_address +__wasm_import_sockets_method_tcp_socket_get_send_buffer_size +__wasm_import_sockets_method_tcp_socket_listen +__wasm_import_sockets_method_tcp_socket_receive +__wasm_import_sockets_method_tcp_socket_send +__wasm_import_sockets_method_tcp_socket_set_hop_limit +__wasm_import_sockets_method_tcp_socket_set_keep_alive_count +__wasm_import_sockets_method_tcp_socket_set_keep_alive_enabled +__wasm_import_sockets_method_tcp_socket_set_keep_alive_idle_time +__wasm_import_sockets_method_tcp_socket_set_keep_alive_interval +__wasm_import_sockets_method_tcp_socket_set_listen_backlog_size +__wasm_import_sockets_method_tcp_socket_set_receive_buffer_size +__wasm_import_sockets_method_tcp_socket_set_send_buffer_size +__wasm_import_sockets_method_udp_socket_bind +__wasm_import_sockets_method_udp_socket_connect +__wasm_import_sockets_method_udp_socket_disconnect +__wasm_import_sockets_method_udp_socket_get_address_family +__wasm_import_sockets_method_udp_socket_get_local_address +__wasm_import_sockets_method_udp_socket_get_receive_buffer_size +__wasm_import_sockets_method_udp_socket_get_remote_address +__wasm_import_sockets_method_udp_socket_get_send_buffer_size +__wasm_import_sockets_method_udp_socket_get_unicast_hop_limit +__wasm_import_sockets_method_udp_socket_receive +__wasm_import_sockets_method_udp_socket_send +__wasm_import_sockets_method_udp_socket_set_receive_buffer_size +__wasm_import_sockets_method_udp_socket_set_send_buffer_size +__wasm_import_sockets_method_udp_socket_set_unicast_hop_limit +__wasm_import_sockets_static_tcp_socket_create +__wasm_import_sockets_static_udp_socket_create +__wasm_import_sockets_tcp_socket_drop +__wasm_import_sockets_udp_socket_drop +__wasm_import_stderr_write_via_stream +__wasm_import_stdin_read_via_stream +__wasm_import_stdout_write_via_stream +__wasm_import_terminal_input_terminal_input_drop +__wasm_import_terminal_output_terminal_output_drop +__wasm_import_terminal_stderr_get_terminal_stderr +__wasm_import_terminal_stdin_get_terminal_stdin +__wasm_import_terminal_stdout_get_terminal_stdout +__wasm_import_wall_clock_get_resolution +__wasm_import_wall_clock_now +filesystem_future_result_void_error_code__cancel_read +filesystem_future_result_void_error_code__cancel_write +filesystem_future_result_void_error_code__drop_readable +filesystem_future_result_void_error_code__drop_writable +filesystem_future_result_void_error_code__new +filesystem_future_result_void_error_code__read +filesystem_future_result_void_error_code__write +filesystem_stream_directory_entry__cancel_read +filesystem_stream_directory_entry__cancel_write +filesystem_stream_directory_entry__drop_readable +filesystem_stream_directory_entry__drop_writable +filesystem_stream_directory_entry__new +filesystem_stream_directory_entry__read +filesystem_stream_directory_entry__write +filesystem_stream_u8__cancel_read +filesystem_stream_u8__cancel_write +filesystem_stream_u8__drop_readable +filesystem_stream_u8__drop_writable +filesystem_stream_u8__new +filesystem_stream_u8__read +filesystem_stream_u8__write +sockets_future_result_void_error_code__cancel_read +sockets_future_result_void_error_code__cancel_write +sockets_future_result_void_error_code__drop_readable +sockets_future_result_void_error_code__drop_writable +sockets_future_result_void_error_code__new +sockets_future_result_void_error_code__read +sockets_future_result_void_error_code__write +sockets_stream_own_tcp_socket__cancel_read +sockets_stream_own_tcp_socket__cancel_write +sockets_stream_own_tcp_socket__drop_readable +sockets_stream_own_tcp_socket__drop_writable +sockets_stream_own_tcp_socket__new +sockets_stream_own_tcp_socket__read +sockets_stream_own_tcp_socket__write +sockets_stream_u8__cancel_read +sockets_stream_u8__cancel_write +sockets_stream_u8__drop_readable +sockets_stream_u8__drop_writable +sockets_stream_u8__new +sockets_stream_u8__read +sockets_stream_u8__write +stdin_future_result_void_error_code__cancel_read +stdin_future_result_void_error_code__cancel_write +stdin_future_result_void_error_code__drop_readable +stdin_future_result_void_error_code__drop_writable +stdin_future_result_void_error_code__new +stdin_future_result_void_error_code__read +stdin_future_result_void_error_code__write +stdin_stream_u8__cancel_read +stdin_stream_u8__cancel_write +stdin_stream_u8__drop_readable +stdin_stream_u8__drop_writable +stdin_stream_u8__new +stdin_stream_u8__read +stdin_stream_u8__write diff --git a/libc-bottom-half/CMakeLists.txt b/libc-bottom-half/CMakeLists.txt index bd1cb009e..84c1d5b5a 100644 --- a/libc-bottom-half/CMakeLists.txt +++ b/libc-bottom-half/CMakeLists.txt @@ -17,8 +17,12 @@ file( headers/public/*.h ) -if (WASI STREQUAL "p1") - list(REMOVE_ITEM globbed_headers headers/public/wasi/wasip2.h) +if (NOT (WASI STREQUAL "p2")) + list(REMOVE_ITEM globbed_headers headers/public/wasi/__generated_wasip2.h) +endif() + +if (NOT (WASI STREQUAL "p3")) + list(REMOVE_ITEM globbed_headers headers/public/wasi/__generated_wasip3.h) endif() foreach(header ${globbed_headers}) @@ -121,21 +125,26 @@ if (WASI STREQUAL "p1") cloudlibc/src/libc/sys/socket/shutdown.c sources/accept-wasip1.c ) -elseif(WASI STREQUAL "p2") +else() list(APPEND bottom_half_sources - sources/accept-wasip2.c + sources/accept.c sources/bind.c sources/connect.c sources/descriptor_table.c sources/getsockpeername.c sources/listen.c - sources/netdb.c sources/recv.c sources/send.c sources/shutdown.c sources/socket.c sources/sockets_utils.c sources/sockopt.c + ) +endif() + +if(WASI STREQUAL "p2") + list(APPEND bottom_half_sources + sources/netdb.c sources/wasip2.c sources/wasip2_file.c sources/wasip2_file_utils.c @@ -145,6 +154,16 @@ elseif(WASI STREQUAL "p2") ) endif() +if (WASI STREQUAL "p3") + list(APPEND bottom_half_sources + sources/wasip3.c + sources/wasip3_file.c + sources/wasip3_stdio.c + sources/wasip3_tcp.c + sources/wasip3_udp.c + ) +endif() + add_object_library(bottom-half ${bottom_half_sources}) foreach(obj bottom-half-shared bottom-half-static) target_link_libraries(${obj} PUBLIC musl-top-half-interface) diff --git a/libc-bottom-half/clocks/clock.c b/libc-bottom-half/clocks/clock.c index b73b0cb3d..16d97e365 100644 --- a/libc-bottom-half/clocks/clock.c +++ b/libc-bottom-half/clocks/clock.c @@ -29,7 +29,7 @@ clock_t __clock(void) { return now - start; } -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) // Snapshot of the monotonic clock at the start of the program. static monotonic_clock_instant_t start; diff --git a/libc-bottom-half/clocks/getrusage.c b/libc-bottom-half/clocks/getrusage.c index 4f5670096..a77cf4299 100644 --- a/libc-bottom-half/clocks/getrusage.c +++ b/libc-bottom-half/clocks/getrusage.c @@ -15,7 +15,7 @@ int getrusage(int who, struct rusage *r_usage) { #if defined(__wasip1__) __wasi_timestamp_t usertime = __clock(); *r_usage = (struct rusage){.ru_utime = timestamp_to_timeval(usertime)}; -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) clock_t usertime = __clock(); *r_usage = (struct rusage){.ru_utime = instant_to_timeval(usertime)}; #else diff --git a/libc-bottom-half/clocks/times.c b/libc-bottom-half/clocks/times.c index d2d303824..1d1e86c7d 100644 --- a/libc-bottom-half/clocks/times.c +++ b/libc-bottom-half/clocks/times.c @@ -21,7 +21,7 @@ clock_t times(struct tms *buffer) { __wasi_timestamp_t realtime = 0; (void)__wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC, 0, &realtime); -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) clock_t user = __clock(); *buffer = (struct tms){ .tms_utime = user, diff --git a/libc-bottom-half/cloudlibc/src/common/time.h b/libc-bottom-half/cloudlibc/src/common/time.h index 66cc6812e..ece306e5a 100644 --- a/libc-bottom-half/cloudlibc/src/common/time.h +++ b/libc-bottom-half/cloudlibc/src/common/time.h @@ -18,7 +18,7 @@ #if defined(__wasip1__) typedef __wasi_timestamp_t wasilibc_timestamp_t; -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) typedef wall_clock_datetime_t wasilibc_timestamp_t; #else # error "Unknown WASI version" @@ -38,7 +38,7 @@ static inline bool timespec_to_timestamp_exact( // Make sure our timestamp does not overflow. return !__builtin_mul_overflow(timespec->tv_sec, NSEC_PER_SEC, timestamp) && !__builtin_add_overflow(*timestamp, timespec->tv_nsec, timestamp); -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) timestamp->seconds = timespec->tv_sec; timestamp->nanoseconds = timespec->tv_nsec; return true; @@ -62,7 +62,7 @@ static inline bool timespec_to_timestamp_clamp( // Make sure our timestamp does not overflow. *timestamp = NUMERIC_MAX(__wasi_timestamp_t); } -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) if (timespec->tv_sec < 0) { // Timestamps before the Epoch are not supported. timestamp->seconds = 0; @@ -92,7 +92,7 @@ static inline struct timeval timestamp_to_timeval( return (struct timeval){.tv_sec = ts.tv_sec, ts.tv_nsec / 1000}; } -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) static inline struct timespec timestamp_to_timespec( wall_clock_datetime_t *timestamp) { diff --git a/libc-bottom-half/cloudlibc/src/libc/dirent/dirent_impl.h b/libc-bottom-half/cloudlibc/src/libc/dirent/dirent_impl.h index 7169be075..a76205e58 100644 --- a/libc-bottom-half/cloudlibc/src/libc/dirent/dirent_impl.h +++ b/libc-bottom-half/cloudlibc/src/libc/dirent/dirent_impl.h @@ -27,6 +27,10 @@ struct _DIR { filesystem_own_directory_entry_stream_t stream; size_t skip; size_t offset; +#elif defined(__wasip3__) + filesystem_stream_directory_entry_t stream; + size_t skip; + size_t offset; #else # error "Unknown WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/dirent/fdclosedir.c b/libc-bottom-half/cloudlibc/src/libc/dirent/fdclosedir.c index 4b5a9e545..c4fc4c434 100644 --- a/libc-bottom-half/cloudlibc/src/libc/dirent/fdclosedir.c +++ b/libc-bottom-half/cloudlibc/src/libc/dirent/fdclosedir.c @@ -14,6 +14,9 @@ int fdclosedir(DIR *dirp) { #elif defined(__wasip2__) if (dirp->stream.__handle != 0) filesystem_directory_entry_stream_drop_own(dirp->stream); +#elif defined(__wasip3__) + if (dirp->stream != 0) + filesystem_stream_directory_entry_drop_readable(dirp->stream); #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c b/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c index 5caea66fd..624bc83bf 100644 --- a/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c +++ b/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c @@ -76,6 +76,11 @@ DIR *fdopendir(int fd) { dirp->dirent = NULL; dirp->dirent_size = 1; return dirp; +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + free(dirp); + return NULL; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c b/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c index 5aa5c71a9..a1cbe06bd 100644 --- a/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c +++ b/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c @@ -251,6 +251,13 @@ struct dirent *readdir(DIR *dirp) { } return result; } +#elif defined(__wasip3__) +struct dirent *readdir(DIR *dirp) { + // TODO(wasip3) + errno = ENOTSUP; + free(dirp); + return NULL; +} #else # error "Unknown WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/dirent/rewinddir.c b/libc-bottom-half/cloudlibc/src/libc/dirent/rewinddir.c index 2325f9541..e92b143e5 100644 --- a/libc-bottom-half/cloudlibc/src/libc/dirent/rewinddir.c +++ b/libc-bottom-half/cloudlibc/src/libc/dirent/rewinddir.c @@ -17,6 +17,10 @@ void rewinddir(DIR *dirp) { dirp->stream.__handle = 0; dirp->skip = 0; dirp->offset = 0; +#elif defined(__wasip3__) + dirp->stream = 0; + dirp->skip = 0; + dirp->offset = 0; #else # error "Unknown WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/dirent/seekdir.c b/libc-bottom-half/cloudlibc/src/libc/dirent/seekdir.c index 3f516b1e6..80f76abdf 100644 --- a/libc-bottom-half/cloudlibc/src/libc/dirent/seekdir.c +++ b/libc-bottom-half/cloudlibc/src/libc/dirent/seekdir.c @@ -17,6 +17,10 @@ void seekdir(DIR *dirp, long loc) { dirp->stream.__handle = 0; dirp->skip = loc; dirp->offset = 0; +#elif defined(__wasip3__) + dirp->stream = 0; + dirp->skip = loc; + dirp->offset = 0; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/dirent/telldir.c b/libc-bottom-half/cloudlibc/src/libc/dirent/telldir.c index 50598ad28..66e3d9f3c 100644 --- a/libc-bottom-half/cloudlibc/src/libc/dirent/telldir.c +++ b/libc-bottom-half/cloudlibc/src/libc/dirent/telldir.c @@ -8,7 +8,7 @@ long telldir(DIR *dirp) { #if defined(__wasip1__) return dirp->cookie; -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) return dirp->offset + dirp->skip; #else # error "Unsupported WASI version" diff --git a/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c b/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c index 858e661e3..55ce46bbd 100644 --- a/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c +++ b/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c @@ -13,7 +13,7 @@ #endif int fcntl(int fildes, int cmd, ...) { -#ifndef __wasip1__ +#ifdef __wasip2__ descriptor_table_entry_t *entry = descriptor_table_get_ref(fildes); if (entry == NULL) return -1; @@ -57,6 +57,10 @@ int fcntl(int fildes, int cmd, ...) { return -1; } return entry->vtable->fcntl_getfl(entry->data); +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unknown WASI version" #endif @@ -82,6 +86,10 @@ int fcntl(int fildes, int cmd, ...) { return -1; } return entry->vtable->fcntl_setfl(entry->data, flags); +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unknown WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c b/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c index c92f33a68..0f6b5047a 100644 --- a/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c +++ b/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c @@ -161,6 +161,10 @@ int __wasilibc_nocwd_openat_nomode(int fd, const char *path, int oflag) { // Update the descriptor table with the new handle return __wasilibc_add_file(new_handle, oflag); +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c b/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c index d39a26f53..b7602972e 100644 --- a/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c +++ b/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c @@ -71,6 +71,10 @@ int posix_fadvise(int fd, off_t offset, off_t len, int advice) { return errno; } return 0; +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return ENOTSUP; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c b/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c index 3bec2b210..fa85dbb19 100644 --- a/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c +++ b/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c @@ -11,7 +11,7 @@ int posix_fallocate(int fd, off_t offset, off_t len) { if (offset < 0 || len < 0) return EINVAL; return __wasi_fd_allocate(fd, offset, len); -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) // Note: this operation isn't supported in wasip2 return ENOTSUP; #else diff --git a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c index 0fc044d13..e7963f6c2 100644 --- a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c +++ b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c @@ -283,6 +283,14 @@ static int poll_impl(struct pollfd *fds, size_t nfds, int timeout) { return state.event_count; } +#elif defined(__wasip3__) + +static int poll_impl(struct pollfd *fds, size_t nfds, int timeout) { + // TODO(wasip3) + errno = ENOTSUP; + return -1; +} + #else # error "Unknown WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c b/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c index 7553fa2a3..fc13322b6 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c +++ b/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c @@ -2,14 +2,12 @@ // // SPDX-License-Identifier: BSD-2-Clause -#ifndef __wasip2__ #include -#endif #include #include int sched_yield(void) { -#ifndef __wasip2__ +#ifdef __wasip1__ __wasi_errno_t error = __wasi_sched_yield(); if (error != 0) { errno = error; diff --git a/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c b/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c index 09ae0b0e5..979ca4915 100644 --- a/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c +++ b/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c @@ -47,6 +47,10 @@ int __wasilibc_nocwd_renameat(int oldfd, const char *old, int newfd, const char translate_error(error_code); return -1; } +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unknown WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c b/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c index 11729a9e1..ace4bcd9c 100644 --- a/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c +++ b/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c @@ -10,7 +10,7 @@ noreturn void _Exit(int status) { #if defined(__wasip1__) __wasi_proc_exit(status); -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) exit_result_void_void_t exit_status = { .is_err = status != 0 }; exit_exit(&exit_status); #else diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c b/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c index f6922be45..7b78d3224 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c @@ -55,8 +55,8 @@ int ioctl(int fildes, int request, ...) { // No data available for reading. *result = 0; return 0; -#elif defined(__wasip2__) - // wasip2 doesn't support this operation +#elif defined(__wasip2__) || defined(__wasip3__) + // wasip{2,3} doesn't support this operation errno = ENOTSUP; return -1; #else @@ -101,6 +101,10 @@ int ioctl(int fildes, int request, ...) { return -1; } return entry->vtable->set_blocking(entry->data, blocking); +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unknown WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c b/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c index 1efa65602..a95378b40 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c @@ -64,7 +64,7 @@ int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, uint64_t timeout_u64; #if defined(__wasip1__) if (!timespec_to_timestamp_clamp(timeout, &timeout_u64) ) { -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) if (!timespec_to_instant_clamp(timeout, &timeout_u64) ) { #else # error "Unknown WASI version" diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c b/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c index 6b2db18a8..1a159aba3 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c @@ -24,6 +24,10 @@ int fstat(int fildes, struct stat *buf) { if (!entry) return -1; return entry->vtable->fstat(entry->data, buf); +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c b/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c index 8812d9444..bcdf37a35 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c @@ -80,6 +80,10 @@ int __wasilibc_nocwd_fstatat(int fd, const char *restrict path, struct stat *res // Convert the internal data to an external struct to_public_stat(&metadata, &internal_stat, buf); return 0; +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c b/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c index 2325f0a5a..2904b1088 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c @@ -52,6 +52,10 @@ int futimens(int fd, const struct timespec *times) { translate_error(error); return -1; } +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c b/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c index 4bd91ab03..d4da3fba8 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c @@ -40,6 +40,10 @@ int __wasilibc_nocwd_mkdirat_nomode(int fd, const char *path) { return -1; } return 0; +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h b/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h index e5a84a72f..504b6ba7e 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h @@ -65,7 +65,7 @@ static inline void to_public_stat(const __wasi_filestat_t *in, break; } } -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) static inline void to_public_stat(const filesystem_metadata_hash_value_t *metadata, const filesystem_descriptor_stat_t *in, struct stat *out) { @@ -167,7 +167,7 @@ static inline bool utimens_get_timestamps(const struct timespec *times, } return true; } -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) static inline bool utimens_get_timestamp(const struct timespec *time, filesystem_new_timestamp_t *out) { switch (time->tv_nsec) { diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c b/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c index 528f1a28a..906d0069d 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c @@ -74,6 +74,10 @@ int __wasilibc_nocwd_utimensat(int fd, const char *path, const struct timespec t translate_error(error); return -1; } +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c b/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c index f840ec8c7..08592fe92 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c @@ -12,7 +12,7 @@ int gettimeofday(struct timeval *restrict tp, void *tz) { __wasi_timestamp_t ts = 0; (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts); *tp = timestamp_to_timeval(ts); -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) wall_clock_datetime_t time_result; wall_clock_now(&time_result); *tp = timestamp_to_timeval(&time_result); diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/uio/preadv.c b/libc-bottom-half/cloudlibc/src/libc/sys/uio/preadv.c index c993a34ab..c33eb3fd2 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/uio/preadv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/uio/preadv.c @@ -26,7 +26,7 @@ ssize_t preadv(int fildes, const struct iovec *iov, int iovcnt, off_t offset) { errno = error; return -1; } -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) // Skip empty iovecs and then delegate to `pread` with the first non-empty // iovec. while (iovcnt) { diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/uio/pwritev.c b/libc-bottom-half/cloudlibc/src/libc/sys/uio/pwritev.c index 30c1a894b..37042502c 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/uio/pwritev.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/uio/pwritev.c @@ -27,7 +27,7 @@ ssize_t pwritev(int fildes, const struct iovec *iov, int iovcnt, off_t offset) { return -1; } return bytes_written; -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) // Skip empty iovecs and then delegate to `pwrite` with the first non-empty // iovec. while (iovcnt) { diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c b/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c index ef3cec4d2..90ed31a9d 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c @@ -41,7 +41,7 @@ ssize_t readv(int fildes, const struct iovec *iov, int iovcnt) { return -1; } return bytes_read; -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) // Skip empty iovecs and then delegate to `read` with the first non-empty // iovec. while (iovcnt) { diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c b/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c index 485d32770..00fe632d8 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c @@ -46,7 +46,7 @@ ssize_t writev(int fildes, const struct iovec *iov, int iovcnt) { return -1; } return bytes_written; -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) // Skip empty iovecs and then delegate to `read` with the first non-empty // iovec. while (iovcnt) { diff --git a/libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c b/libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c index 6f58c8e2b..aeb1cafac 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c @@ -31,6 +31,10 @@ int clock_getres(clockid_t clock_id, struct timespec *res) { return -1; } } +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c b/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c index 41c32c173..4619c169e 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c @@ -17,7 +17,7 @@ int __clock_gettime(clockid_t clock_id, struct timespec *tp) { return -1; } *tp = timestamp_to_timespec(ts); -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) if (tp == NULL) return 0; diff --git a/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c b/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c index a82d11081..6f3ad9d1a 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c @@ -56,6 +56,10 @@ int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, poll_pollable_drop_own(pollable); return 0; +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/time/time.c b/libc-bottom-half/cloudlibc/src/libc/time/time.c index b2711e9f0..96c09b35a 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/time.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/time.c @@ -10,7 +10,7 @@ time_t time(time_t *tloc) { #if defined(__wasip1__) __wasi_timestamp_t ts = 0; (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, NSEC_PER_SEC, &ts); -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) wall_clock_datetime_t res; wall_clock_now(&res); uint64_t ts = (res.seconds * NSEC_PER_SEC) + res.nanoseconds; diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c b/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c index 16c3db96b..8380ca597 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c @@ -109,6 +109,10 @@ int __wasilibc_nocwd_faccessat(int fd, const char *path, int amode, int flag) { return -1; } } +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c b/libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c index b8407d567..89f36b771 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c @@ -31,6 +31,10 @@ int fdatasync(int fildes) { translate_error(error_code); return -1; } +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/fsync.c b/libc-bottom-half/cloudlibc/src/libc/unistd/fsync.c index 9c2eb9aac..1ffe76f70 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/fsync.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/fsync.c @@ -30,6 +30,10 @@ int fsync(int fildes) { translate_error(error_code); return -1; } +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c b/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c index b20ffeff9..2dd8ede0b 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c @@ -35,6 +35,10 @@ int ftruncate(int fildes, off_t length) { translate_error(error_code); return -1; } +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c b/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c index b2a27b2e0..dafcaa88c 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c @@ -53,6 +53,10 @@ int __wasilibc_nocwd_linkat(int fd1, const char *path1, int fd2, const char *pat translate_error(error_code); return -1; } +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c b/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c index 5939253c4..f48e372b4 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c @@ -39,6 +39,10 @@ off_t __lseek(int fildes, off_t offset, int whence) { return -1; } return entry->vtable->seek(entry->data, offset, whence); +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unknown WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c b/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c index a84cced13..ae29e1729 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c @@ -65,6 +65,10 @@ ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset) { } return bytes_read; +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unknown WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c b/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c index 3b89ef83b..3373d97af 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c @@ -61,6 +61,10 @@ ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) { } return bytes_written; +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/read.c b/libc-bottom-half/cloudlibc/src/libc/unistd/read.c index 2db2fa8b8..eb842976f 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/read.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/read.c @@ -52,6 +52,10 @@ ssize_t read(int fildes, void *buf, size_t nbyte) { if (off) *off += contents.len; return contents.len; +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c b/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c index 911d9238c..9ff82d184 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c @@ -49,6 +49,10 @@ ssize_t __wasilibc_nocwd_readlinkat(int fd, const char *restrict path, char *res bufused = bufsize < link_source.len ? bufsize : link_source.len; memcpy(buf, link_source.ptr, bufused); wasip2_string_free(&link_source); +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c b/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c index e3bd6be82..4f270ab43 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c @@ -44,6 +44,10 @@ int __wasilibc_nocwd_symlinkat(const char *path1, int fd, const char *path2) { translate_error(error_code); return -1; } +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c b/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c index f00933f5b..6af5e80da 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c @@ -12,9 +12,9 @@ int usleep(useconds_t useconds) { .tv_nsec = useconds % 1000000 * 1000}; #if defined(__wasip1__) clockid_t clock_id = CLOCK_REALTIME; -#elif defined(__wasip2__) - // FIXME(WebAssembly/WASI#857): wasip2 only supports the monotonic clock for - // sleeping. +#elif defined(__wasip2__) || defined(__wasip3__) + // FIXME(WebAssembly/WASI#857): wasip2/p3 only supports the monotonic clock + // for sleeping. clockid_t clock_id = CLOCK_MONOTONIC; #else # error "Unsupported WASI version" diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/write.c b/libc-bottom-half/cloudlibc/src/libc/unistd/write.c index 96b03ab1c..0f2f9275f 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/write.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/write.c @@ -71,6 +71,10 @@ ssize_t write(int fildes, const void *buf, size_t nbyte) { if (off) *off += contents.len; return contents.len; +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else # error "Unknown WASI version" #endif diff --git a/libc-bottom-half/crt/crt1-command.c b/libc-bottom-half/crt/crt1-command.c index 0f5d30211..69f340f4b 100644 --- a/libc-bottom-half/crt/crt1-command.c +++ b/libc-bottom-half/crt/crt1-command.c @@ -51,7 +51,7 @@ void _start(void) { if (r != 0) { __wasi_proc_exit(r); } -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) if (r != 0) { exit_result_void_void_t status = { .is_err = true }; exit_exit(&status); diff --git a/libc-bottom-half/headers/private/wasi/descriptor_table.h b/libc-bottom-half/headers/private/wasi/descriptor_table.h index 7727b3603..217728215 100644 --- a/libc-bottom-half/headers/private/wasi/descriptor_table.h +++ b/libc-bottom-half/headers/private/wasi/descriptor_table.h @@ -27,6 +27,7 @@ typedef struct descriptor_vtable_t { // ===================================================================== // Generic I/O +#ifdef __wasip2__ /// Looks up a `wasi:io/streams.input-stream` object and stores it in /// the first argument. If provide also stores a pointer to the internal /// `off_t` offset and `pollable` for this object. The returned pointers @@ -35,6 +36,7 @@ typedef struct descriptor_vtable_t { /// Same as `get_read_stream`, but for output streams. int (*get_write_stream)(void*, streams_borrow_output_stream_t*, off_t**, poll_own_pollable_t**); +#endif /// Sets the nonblocking flag for this object to the specified value. int (*set_blocking)(void*, bool); diff --git a/libc-bottom-half/headers/private/wasi/file.h b/libc-bottom-half/headers/private/wasi/file.h index fa2ee940c..c34df76ee 100644 --- a/libc-bottom-half/headers/private/wasi/file.h +++ b/libc-bottom-half/headers/private/wasi/file.h @@ -3,9 +3,9 @@ #include -#ifdef __wasip2__ +#ifndef __wasip1__ -#include +#include // Adds a new file handle to the descriptor table, returning the new `fd`. int __wasilibc_add_file(filesystem_own_descriptor_t file_handle, int oflag); diff --git a/libc-bottom-half/headers/private/wasi/poll.h b/libc-bottom-half/headers/private/wasi/poll.h index 451707b13..c3e23de7c 100644 --- a/libc-bottom-half/headers/private/wasi/poll.h +++ b/libc-bottom-half/headers/private/wasi/poll.h @@ -3,14 +3,23 @@ #include -#ifdef __wasip2__ +#ifndef __wasip1__ #include -#include /// Opaque state that the `poll` function manages for itself. typedef struct poll_state_t poll_state_t; +/// Indicates that the `pollfd` which `state` refers to is ready with `events`. +/// +/// If called during `poll_register` then `wasi:io/poll.poll` won't be invoked, +/// and otherwise sets the `revents` field after `poll` has run. +void __wasilibc_poll_ready(poll_state_t *state, short events); + +#ifdef __wasip2__ + +#include + /// Adds the `pollable` to the `state` provided. /// /// This will add a `pollable` to get passed to `wasi:io/poll.poll`. If that @@ -22,12 +31,6 @@ int __wasilibc_poll_add(poll_state_t *state, short events, poll_borrow_pollable_t pollable); -/// Indicates that the `pollfd` which `state` refers to is ready with `events`. -/// -/// If called during `poll_register` then `wasi:io/poll.poll` won't be invoked, -/// and otherwise sets the `revents` field after `poll` has run. -void __wasilibc_poll_ready(poll_state_t *state, short events); - /// Helper function to lazily subscribe to an input stream and call /// `__wasilibc_poll_add`. static int __wasilibc_poll_add_input_stream( @@ -52,4 +55,6 @@ static int __wasilibc_poll_add_output_stream( #endif // __wasip2__ +#endif // not(__wasip1__) + #endif // WASI_POLL_H diff --git a/libc-bottom-half/headers/private/wasi/sockets_utils.h b/libc-bottom-half/headers/private/wasi/sockets_utils.h index 318918fd9..3abb37568 100644 --- a/libc-bottom-half/headers/private/wasi/sockets_utils.h +++ b/libc-bottom-half/headers/private/wasi/sockets_utils.h @@ -3,6 +3,21 @@ #include #include +#include + +#ifndef __wasip1__ + +#if defined(__wasip2__) +typedef network_error_code_t sockets_error_code_t; +typedef network_ip_address_family_t sockets_ip_address_family_t; +typedef network_ip_socket_address_t sockets_ip_socket_address_t; +typedef tcp_own_tcp_socket_t sockets_own_tcp_socket_t; +typedef udp_own_udp_socket_t sockets_own_udp_socket_t; +#elif defined(__wasip3__) +// already defines `sockets_*` types +#else +# error "Unsupported WASI version" +#endif typedef struct { enum { @@ -36,21 +51,26 @@ typedef enum { SERVICE_PROTOCOL_UDP = 2 } service_protocol_e; +#ifdef __wasip2__ network_borrow_network_t __wasi_sockets_utils__borrow_network(); -int __wasi_sockets_utils__map_error(network_error_code_t wasi_error); +#endif + +int __wasi_sockets_utils__map_error(sockets_error_code_t wasi_error); bool __wasi_sockets_utils__parse_address( - network_ip_address_family_t expected_family, + sockets_ip_address_family_t expected_family, const struct sockaddr *address, socklen_t len, - network_ip_socket_address_t *result, int *error); + sockets_ip_socket_address_t *result, int *error); bool __wasi_sockets_utils__output_addr_validate( - network_ip_address_family_t expected_family, struct sockaddr *addr, + sockets_ip_address_family_t expected_family, struct sockaddr *addr, socklen_t *addrlen, output_sockaddr_t *result); void __wasi_sockets_utils__output_addr_write( - const network_ip_socket_address_t input, output_sockaddr_t *output); -int __wasi_sockets_utils__posix_family(network_ip_address_family_t wasi_family); -network_ip_socket_address_t __wasi_sockets_utils__any_addr(network_ip_address_family_t family); + const sockets_ip_socket_address_t input, output_sockaddr_t *output); +int __wasi_sockets_utils__posix_family(sockets_ip_address_family_t wasi_family); +sockets_ip_socket_address_t __wasi_sockets_utils__any_addr(sockets_ip_address_family_t family); int __wasi_sockets_utils__parse_port(const char *port); const service_entry_t *__wasi_sockets_utils__get_service_entry_by_name(const char *name); const service_entry_t *__wasi_sockets_utils__get_service_entry_by_port(const uint16_t port); -#endif +#endif // not(__wasip1__) + +#endif // __wasi_sockets_utils_h diff --git a/libc-bottom-half/headers/private/wasi/stdio.h b/libc-bottom-half/headers/private/wasi/stdio.h index 00fb8ae4f..fdbeafd2d 100644 --- a/libc-bottom-half/headers/private/wasi/stdio.h +++ b/libc-bottom-half/headers/private/wasi/stdio.h @@ -3,12 +3,12 @@ #include -#ifdef __wasip2__ +#ifndef __wasip1__ /// Initialization hook which adds stdin/stdout/stderr fds to the descriptor /// table. int __wasilibc_init_stdio(void); -#endif // __wasip2__ +#endif // not(__wasip1__) #endif // WASI_STDIO_H diff --git a/libc-bottom-half/headers/private/wasi/tcp.h b/libc-bottom-half/headers/private/wasi/tcp.h index 9c1a23929..daf443dd1 100644 --- a/libc-bottom-half/headers/private/wasi/tcp.h +++ b/libc-bottom-half/headers/private/wasi/tcp.h @@ -3,16 +3,16 @@ #include -#ifdef __wasip2__ +#ifndef __wasip1__ -#include +#include /// Adds the provided TCP socket to the descriptor table, returning the /// corresponding file descriptor. -int __wasilibc_add_tcp_socket(tcp_own_tcp_socket_t socket, - network_ip_address_family_t family, +int __wasilibc_add_tcp_socket(sockets_own_tcp_socket_t socket, + sockets_ip_address_family_t family, bool blocking); -#endif // __wasip2__ +#endif // not(__wasip1__) #endif // WASI_TCP_H diff --git a/libc-bottom-half/headers/private/wasi/udp.h b/libc-bottom-half/headers/private/wasi/udp.h index 1ce67217a..487411836 100644 --- a/libc-bottom-half/headers/private/wasi/udp.h +++ b/libc-bottom-half/headers/private/wasi/udp.h @@ -3,16 +3,16 @@ #include -#ifdef __wasip2__ +#ifndef __wasip1__ -#include +#include /// Adds the provided UDP socket to the descriptor table, returning the /// corresponding file descriptor. -int __wasilibc_add_udp_socket(udp_own_udp_socket_t socket, - network_ip_address_family_t family, +int __wasilibc_add_udp_socket(sockets_own_udp_socket_t socket, + sockets_ip_address_family_t family, bool blocking); -#endif // __wasip2__ +#endif // not(__wasip1__) #endif // WASI_UDP_H diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index ab2c8e518..a7ee66e08 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -11,7 +11,12 @@ #define SHUT_WR 2 #define SHUT_RDWR (SHUT_RD | SHUT_WR) -#ifdef __wasip2__ +#if defined(__wasip1__) +#include +#define MSG_PEEK __WASI_RIFLAGS_RECV_PEEK +#define MSG_WAITALL __WASI_RIFLAGS_RECV_WAITALL +#define MSG_TRUNC __WASI_ROFLAGS_RECV_DATA_TRUNCATED +#elif defined(__wasip2__) || defined(__wasip3__) #define MSG_DONTWAIT 0x0040 #define MSG_NOSIGNAL 0x4000 #define MSG_PEEK 0x0002 @@ -42,12 +47,9 @@ #define SO_SNDTIMEO 21 #endif -#else // __wasip2__ -#include -#define MSG_PEEK __WASI_RIFLAGS_RECV_PEEK -#define MSG_WAITALL __WASI_RIFLAGS_RECV_WAITALL -#define MSG_TRUNC __WASI_ROFLAGS_RECV_DATA_TRUNCATED -#endif // __wasip2__ +#else +#error "Unknown WASI version" +#endif #define SOCK_DGRAM 5 #define SOCK_STREAM 6 diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip2.h b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h new file mode 100644 index 000000000..54ffac264 --- /dev/null +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h @@ -0,0 +1,2457 @@ +// Generated by `wit-bindgen` 0.48.0. DO NOT EDIT! +#ifndef __BINDINGS_WASIP2_H +#define __BINDINGS_WASIP2_H +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +typedef struct wasip2_string_t { + uint8_t*ptr; + size_t len; +} wasip2_string_t; + +typedef struct { + wasip2_string_t f0; + wasip2_string_t f1; +} wasip2_tuple2_string_string_t; + +typedef struct { + wasip2_tuple2_string_string_t *ptr; + size_t len; +} wasip2_list_tuple2_string_string_t; + +typedef struct { + wasip2_string_t *ptr; + size_t len; +} wasip2_list_string_t; + +typedef struct { + bool is_some; + wasip2_string_t val; +} wasip2_option_string_t; + +typedef struct { + bool is_err; +} exit_result_void_void_t; + +typedef struct io_error_own_error_t { + int32_t __handle; +} io_error_own_error_t; + +typedef struct io_error_borrow_error_t { + int32_t __handle; +} io_error_borrow_error_t; + +typedef struct poll_own_pollable_t { + int32_t __handle; +} poll_own_pollable_t; + +typedef struct poll_borrow_pollable_t { + int32_t __handle; +} poll_borrow_pollable_t; + +typedef struct { + poll_borrow_pollable_t *ptr; + size_t len; +} poll_list_borrow_pollable_t; + +typedef struct { + uint32_t *ptr; + size_t len; +} wasip2_list_u32_t; + +typedef io_error_own_error_t streams_own_error_t; + +// An error for input-stream and output-stream operations. +typedef struct streams_stream_error_t { + uint8_t tag; + union { + streams_own_error_t last_operation_failed; + } val; +} streams_stream_error_t; + +// The last operation (a write or flush) failed before completion. +// +// More information is available in the `error` payload. +#define STREAMS_STREAM_ERROR_LAST_OPERATION_FAILED 0 +// The stream is closed: no more input will be accepted by the +// stream. A closed output-stream will return this error on all +// future operations. +#define STREAMS_STREAM_ERROR_CLOSED 1 + +typedef struct streams_own_input_stream_t { + int32_t __handle; +} streams_own_input_stream_t; + +typedef struct streams_borrow_input_stream_t { + int32_t __handle; +} streams_borrow_input_stream_t; + +typedef struct streams_own_output_stream_t { + int32_t __handle; +} streams_own_output_stream_t; + +typedef struct streams_borrow_output_stream_t { + int32_t __handle; +} streams_borrow_output_stream_t; + +typedef struct { + uint8_t *ptr; + size_t len; +} wasip2_list_u8_t; + +typedef struct { + bool is_err; + union { + wasip2_list_u8_t ok; + streams_stream_error_t err; + } val; +} streams_result_list_u8_stream_error_t; + +typedef struct { + bool is_err; + union { + uint64_t ok; + streams_stream_error_t err; + } val; +} streams_result_u64_stream_error_t; + +typedef poll_own_pollable_t streams_own_pollable_t; + +typedef struct { + bool is_err; + union { + streams_stream_error_t err; + } val; +} streams_result_void_stream_error_t; + +typedef streams_own_input_stream_t stdin_own_input_stream_t; + +typedef streams_own_output_stream_t stdout_own_output_stream_t; + +typedef streams_own_output_stream_t stderr_own_output_stream_t; + +typedef struct terminal_input_own_terminal_input_t { + int32_t __handle; +} terminal_input_own_terminal_input_t; + +typedef struct terminal_input_borrow_terminal_input_t { + int32_t __handle; +} terminal_input_borrow_terminal_input_t; + +typedef struct terminal_output_own_terminal_output_t { + int32_t __handle; +} terminal_output_own_terminal_output_t; + +typedef struct terminal_output_borrow_terminal_output_t { + int32_t __handle; +} terminal_output_borrow_terminal_output_t; + +typedef terminal_input_own_terminal_input_t terminal_stdin_own_terminal_input_t; + +typedef struct { + bool is_some; + terminal_stdin_own_terminal_input_t val; +} terminal_stdin_option_own_terminal_input_t; + +typedef terminal_output_own_terminal_output_t terminal_stdout_own_terminal_output_t; + +typedef struct { + bool is_some; + terminal_stdout_own_terminal_output_t val; +} terminal_stdout_option_own_terminal_output_t; + +typedef terminal_output_own_terminal_output_t terminal_stderr_own_terminal_output_t; + +typedef struct { + bool is_some; + terminal_stderr_own_terminal_output_t val; +} terminal_stderr_option_own_terminal_output_t; + +// An instant in time, in nanoseconds. An instant is relative to an +// unspecified initial value, and can only be compared to instances from +// the same monotonic-clock. +typedef uint64_t monotonic_clock_instant_t; + +// A duration of time, in nanoseconds. +typedef uint64_t monotonic_clock_duration_t; + +typedef poll_own_pollable_t monotonic_clock_own_pollable_t; + +// A time and date in seconds plus nanoseconds. +typedef struct wall_clock_datetime_t { + uint64_t seconds; + uint32_t nanoseconds; +} wall_clock_datetime_t; + +typedef wall_clock_datetime_t filesystem_datetime_t; + +// File size or length of a region within a file. +typedef uint64_t filesystem_filesize_t; + +// The type of a filesystem object referenced by a descriptor. +// +// Note: This was called `filetype` in earlier versions of WASI. +typedef uint8_t filesystem_descriptor_type_t; + +// The type of the descriptor or file is unknown or is different from +// any of the other types specified. +#define FILESYSTEM_DESCRIPTOR_TYPE_UNKNOWN 0 +// The descriptor refers to a block device inode. +#define FILESYSTEM_DESCRIPTOR_TYPE_BLOCK_DEVICE 1 +// The descriptor refers to a character device inode. +#define FILESYSTEM_DESCRIPTOR_TYPE_CHARACTER_DEVICE 2 +// The descriptor refers to a directory inode. +#define FILESYSTEM_DESCRIPTOR_TYPE_DIRECTORY 3 +// The descriptor refers to a named pipe. +#define FILESYSTEM_DESCRIPTOR_TYPE_FIFO 4 +// The file refers to a symbolic link inode. +#define FILESYSTEM_DESCRIPTOR_TYPE_SYMBOLIC_LINK 5 +// The descriptor refers to a regular file inode. +#define FILESYSTEM_DESCRIPTOR_TYPE_REGULAR_FILE 6 +// The descriptor refers to a socket. +#define FILESYSTEM_DESCRIPTOR_TYPE_SOCKET 7 + +// Descriptor flags. +// +// Note: This was called `fdflags` in earlier versions of WASI. +typedef uint8_t filesystem_descriptor_flags_t; + +// Read mode: Data can be read. +#define FILESYSTEM_DESCRIPTOR_FLAGS_READ (1 << 0) +// Write mode: Data can be written to. +#define FILESYSTEM_DESCRIPTOR_FLAGS_WRITE (1 << 1) +// Request that writes be performed according to synchronized I/O file +// integrity completion. The data stored in the file and the file's +// metadata are synchronized. This is similar to `O_SYNC` in POSIX. +// +// The precise semantics of this operation have not yet been defined for +// WASI. At this time, it should be interpreted as a request, and not a +// requirement. +#define FILESYSTEM_DESCRIPTOR_FLAGS_FILE_INTEGRITY_SYNC (1 << 2) +// Request that writes be performed according to synchronized I/O data +// integrity completion. Only the data stored in the file is +// synchronized. This is similar to `O_DSYNC` in POSIX. +// +// The precise semantics of this operation have not yet been defined for +// WASI. At this time, it should be interpreted as a request, and not a +// requirement. +#define FILESYSTEM_DESCRIPTOR_FLAGS_DATA_INTEGRITY_SYNC (1 << 3) +// Requests that reads be performed at the same level of integrety +// requested for writes. This is similar to `O_RSYNC` in POSIX. +// +// The precise semantics of this operation have not yet been defined for +// WASI. At this time, it should be interpreted as a request, and not a +// requirement. +#define FILESYSTEM_DESCRIPTOR_FLAGS_REQUESTED_WRITE_SYNC (1 << 4) +// Mutating directories mode: Directory contents may be mutated. +// +// When this flag is unset on a descriptor, operations using the +// descriptor which would create, rename, delete, modify the data or +// metadata of filesystem objects, or obtain another handle which +// would permit any of those, shall fail with `error-code::read-only` if +// they would otherwise succeed. +// +// This may only be set on directories. +#define FILESYSTEM_DESCRIPTOR_FLAGS_MUTATE_DIRECTORY (1 << 5) + +// Flags determining the method of how paths are resolved. +typedef uint8_t filesystem_path_flags_t; + +// As long as the resolved path corresponds to a symbolic link, it is +// expanded. +#define FILESYSTEM_PATH_FLAGS_SYMLINK_FOLLOW (1 << 0) + +// Open flags used by `open-at`. +typedef uint8_t filesystem_open_flags_t; + +// Create file if it does not exist, similar to `O_CREAT` in POSIX. +#define FILESYSTEM_OPEN_FLAGS_CREATE (1 << 0) +// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. +#define FILESYSTEM_OPEN_FLAGS_DIRECTORY (1 << 1) +// Fail if file already exists, similar to `O_EXCL` in POSIX. +#define FILESYSTEM_OPEN_FLAGS_EXCLUSIVE (1 << 2) +// Truncate file to size 0, similar to `O_TRUNC` in POSIX. +#define FILESYSTEM_OPEN_FLAGS_TRUNCATE (1 << 3) + +// Number of hard links to an inode. +typedef uint64_t filesystem_link_count_t; + +typedef struct { + bool is_some; + filesystem_datetime_t val; +} filesystem_option_datetime_t; + +// File attributes. +// +// Note: This was called `filestat` in earlier versions of WASI. +typedef struct filesystem_descriptor_stat_t { + // File type. + filesystem_descriptor_type_t type; + // Number of hard links to the file. + filesystem_link_count_t link_count; + // For regular files, the file size in bytes. For symbolic links, the + // length in bytes of the pathname contained in the symbolic link. + filesystem_filesize_t size; + // Last data access timestamp. + // + // If the `option` is none, the platform doesn't maintain an access + // timestamp for this file. + filesystem_option_datetime_t data_access_timestamp; + // Last data modification timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // modification timestamp for this file. + filesystem_option_datetime_t data_modification_timestamp; + // Last file status-change timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // status-change timestamp for this file. + filesystem_option_datetime_t status_change_timestamp; +} filesystem_descriptor_stat_t; + +// When setting a timestamp, this gives the value to set it to. +typedef struct filesystem_new_timestamp_t { + uint8_t tag; + union { + filesystem_datetime_t timestamp; + } val; +} filesystem_new_timestamp_t; + +// Leave the timestamp set to its previous value. +#define FILESYSTEM_NEW_TIMESTAMP_NO_CHANGE 0 +// Set the timestamp to the current time of the system clock associated +// with the filesystem. +#define FILESYSTEM_NEW_TIMESTAMP_NOW 1 +// Set the timestamp to the given value. +#define FILESYSTEM_NEW_TIMESTAMP_TIMESTAMP 2 + +// A directory entry. +typedef struct filesystem_directory_entry_t { + // The type of the file referred to by this directory entry. + filesystem_descriptor_type_t type; + // The name of the object. + wasip2_string_t name; +} filesystem_directory_entry_t; + +// Error codes returned by functions, similar to `errno` in POSIX. +// Not all of these error codes are returned by the functions provided by this +// API; some are used in higher-level library layers, and others are provided +// merely for alignment with POSIX. +typedef uint8_t filesystem_error_code_t; + +// Permission denied, similar to `EACCES` in POSIX. +#define FILESYSTEM_ERROR_CODE_ACCESS 0 +// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. +#define FILESYSTEM_ERROR_CODE_WOULD_BLOCK 1 +// Connection already in progress, similar to `EALREADY` in POSIX. +#define FILESYSTEM_ERROR_CODE_ALREADY 2 +// Bad descriptor, similar to `EBADF` in POSIX. +#define FILESYSTEM_ERROR_CODE_BAD_DESCRIPTOR 3 +// Device or resource busy, similar to `EBUSY` in POSIX. +#define FILESYSTEM_ERROR_CODE_BUSY 4 +// Resource deadlock would occur, similar to `EDEADLK` in POSIX. +#define FILESYSTEM_ERROR_CODE_DEADLOCK 5 +// Storage quota exceeded, similar to `EDQUOT` in POSIX. +#define FILESYSTEM_ERROR_CODE_QUOTA 6 +// File exists, similar to `EEXIST` in POSIX. +#define FILESYSTEM_ERROR_CODE_EXIST 7 +// File too large, similar to `EFBIG` in POSIX. +#define FILESYSTEM_ERROR_CODE_FILE_TOO_LARGE 8 +// Illegal byte sequence, similar to `EILSEQ` in POSIX. +#define FILESYSTEM_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE 9 +// Operation in progress, similar to `EINPROGRESS` in POSIX. +#define FILESYSTEM_ERROR_CODE_IN_PROGRESS 10 +// Interrupted function, similar to `EINTR` in POSIX. +#define FILESYSTEM_ERROR_CODE_INTERRUPTED 11 +// Invalid argument, similar to `EINVAL` in POSIX. +#define FILESYSTEM_ERROR_CODE_INVALID 12 +// I/O error, similar to `EIO` in POSIX. +#define FILESYSTEM_ERROR_CODE_IO 13 +// Is a directory, similar to `EISDIR` in POSIX. +#define FILESYSTEM_ERROR_CODE_IS_DIRECTORY 14 +// Too many levels of symbolic links, similar to `ELOOP` in POSIX. +#define FILESYSTEM_ERROR_CODE_LOOP 15 +// Too many links, similar to `EMLINK` in POSIX. +#define FILESYSTEM_ERROR_CODE_TOO_MANY_LINKS 16 +// Message too large, similar to `EMSGSIZE` in POSIX. +#define FILESYSTEM_ERROR_CODE_MESSAGE_SIZE 17 +// Filename too long, similar to `ENAMETOOLONG` in POSIX. +#define FILESYSTEM_ERROR_CODE_NAME_TOO_LONG 18 +// No such device, similar to `ENODEV` in POSIX. +#define FILESYSTEM_ERROR_CODE_NO_DEVICE 19 +// No such file or directory, similar to `ENOENT` in POSIX. +#define FILESYSTEM_ERROR_CODE_NO_ENTRY 20 +// No locks available, similar to `ENOLCK` in POSIX. +#define FILESYSTEM_ERROR_CODE_NO_LOCK 21 +// Not enough space, similar to `ENOMEM` in POSIX. +#define FILESYSTEM_ERROR_CODE_INSUFFICIENT_MEMORY 22 +// No space left on device, similar to `ENOSPC` in POSIX. +#define FILESYSTEM_ERROR_CODE_INSUFFICIENT_SPACE 23 +// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. +#define FILESYSTEM_ERROR_CODE_NOT_DIRECTORY 24 +// Directory not empty, similar to `ENOTEMPTY` in POSIX. +#define FILESYSTEM_ERROR_CODE_NOT_EMPTY 25 +// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. +#define FILESYSTEM_ERROR_CODE_NOT_RECOVERABLE 26 +// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. +#define FILESYSTEM_ERROR_CODE_UNSUPPORTED 27 +// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. +#define FILESYSTEM_ERROR_CODE_NO_TTY 28 +// No such device or address, similar to `ENXIO` in POSIX. +#define FILESYSTEM_ERROR_CODE_NO_SUCH_DEVICE 29 +// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. +#define FILESYSTEM_ERROR_CODE_OVERFLOW 30 +// Operation not permitted, similar to `EPERM` in POSIX. +#define FILESYSTEM_ERROR_CODE_NOT_PERMITTED 31 +// Broken pipe, similar to `EPIPE` in POSIX. +#define FILESYSTEM_ERROR_CODE_PIPE 32 +// Read-only file system, similar to `EROFS` in POSIX. +#define FILESYSTEM_ERROR_CODE_READ_ONLY 33 +// Invalid seek, similar to `ESPIPE` in POSIX. +#define FILESYSTEM_ERROR_CODE_INVALID_SEEK 34 +// Text file busy, similar to `ETXTBSY` in POSIX. +#define FILESYSTEM_ERROR_CODE_TEXT_FILE_BUSY 35 +// Cross-device link, similar to `EXDEV` in POSIX. +#define FILESYSTEM_ERROR_CODE_CROSS_DEVICE 36 + +// File or memory access pattern advisory information. +typedef uint8_t filesystem_advice_t; + +// The application has no advice to give on its behavior with respect +// to the specified data. +#define FILESYSTEM_ADVICE_NORMAL 0 +// The application expects to access the specified data sequentially +// from lower offsets to higher offsets. +#define FILESYSTEM_ADVICE_SEQUENTIAL 1 +// The application expects to access the specified data in a random +// order. +#define FILESYSTEM_ADVICE_RANDOM 2 +// The application expects to access the specified data in the near +// future. +#define FILESYSTEM_ADVICE_WILL_NEED 3 +// The application expects that it will not access the specified data +// in the near future. +#define FILESYSTEM_ADVICE_DONT_NEED 4 +// The application expects to access the specified data once and then +// not reuse it thereafter. +#define FILESYSTEM_ADVICE_NO_REUSE 5 + +// A 128-bit hash value, split into parts because wasm doesn't have a +// 128-bit integer type. +typedef struct filesystem_metadata_hash_value_t { + // 64 bits of a 128-bit hash value. + uint64_t lower; + // Another 64 bits of a 128-bit hash value. + uint64_t upper; +} filesystem_metadata_hash_value_t; + +typedef struct filesystem_own_descriptor_t { + int32_t __handle; +} filesystem_own_descriptor_t; + +typedef struct filesystem_borrow_descriptor_t { + int32_t __handle; +} filesystem_borrow_descriptor_t; + +typedef struct filesystem_own_directory_entry_stream_t { + int32_t __handle; +} filesystem_own_directory_entry_stream_t; + +typedef struct filesystem_borrow_directory_entry_stream_t { + int32_t __handle; +} filesystem_borrow_directory_entry_stream_t; + +typedef streams_own_input_stream_t filesystem_own_input_stream_t; + +typedef struct { + bool is_err; + union { + filesystem_own_input_stream_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_own_input_stream_error_code_t; + +typedef streams_own_output_stream_t filesystem_own_output_stream_t; + +typedef struct { + bool is_err; + union { + filesystem_own_output_stream_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_own_output_stream_error_code_t; + +typedef struct { + bool is_err; + union { + filesystem_error_code_t err; + } val; +} filesystem_result_void_error_code_t; + +typedef struct { + bool is_err; + union { + filesystem_descriptor_flags_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_descriptor_flags_error_code_t; + +typedef struct { + bool is_err; + union { + filesystem_descriptor_type_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_descriptor_type_error_code_t; + +typedef struct { + wasip2_list_u8_t f0; + bool f1; +} wasip2_tuple2_list_u8_bool_t; + +typedef struct { + bool is_err; + union { + wasip2_tuple2_list_u8_bool_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_tuple2_list_u8_bool_error_code_t; + +typedef struct { + bool is_err; + union { + filesystem_filesize_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_filesize_error_code_t; + +typedef struct { + bool is_err; + union { + filesystem_own_directory_entry_stream_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_own_directory_entry_stream_error_code_t; + +typedef struct { + bool is_err; + union { + filesystem_descriptor_stat_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_descriptor_stat_error_code_t; + +typedef struct { + bool is_err; + union { + filesystem_own_descriptor_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_own_descriptor_error_code_t; + +typedef struct { + bool is_err; + union { + wasip2_string_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_string_error_code_t; + +typedef struct { + bool is_err; + union { + filesystem_metadata_hash_value_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_metadata_hash_value_error_code_t; + +typedef struct { + bool is_some; + filesystem_directory_entry_t val; +} filesystem_option_directory_entry_t; + +typedef struct { + bool is_err; + union { + filesystem_option_directory_entry_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_option_directory_entry_error_code_t; + +typedef io_error_borrow_error_t filesystem_borrow_error_t; + +typedef struct { + bool is_some; + filesystem_error_code_t val; +} filesystem_option_error_code_t; + +typedef filesystem_own_descriptor_t filesystem_preopens_own_descriptor_t; + +typedef struct { + filesystem_preopens_own_descriptor_t f0; + wasip2_string_t f1; +} filesystem_preopens_tuple2_own_descriptor_string_t; + +typedef struct { + filesystem_preopens_tuple2_own_descriptor_string_t *ptr; + size_t len; +} filesystem_preopens_list_tuple2_own_descriptor_string_t; + +typedef struct network_own_network_t { + int32_t __handle; +} network_own_network_t; + +typedef struct network_borrow_network_t { + int32_t __handle; +} network_borrow_network_t; + +// Error codes. +// +// In theory, every API can return any error code. +// In practice, API's typically only return the errors documented per API +// combined with a couple of errors that are always possible: +// - `unknown` +// - `access-denied` +// - `not-supported` +// - `out-of-memory` +// - `concurrency-conflict` +// +// See each individual API for what the POSIX equivalents are. They sometimes differ per API. +typedef uint8_t network_error_code_t; + +// Unknown error +#define NETWORK_ERROR_CODE_UNKNOWN 0 +// Access denied. +// +// POSIX equivalent: EACCES, EPERM +#define NETWORK_ERROR_CODE_ACCESS_DENIED 1 +// The operation is not supported. +// +// POSIX equivalent: EOPNOTSUPP +#define NETWORK_ERROR_CODE_NOT_SUPPORTED 2 +// One of the arguments is invalid. +// +// POSIX equivalent: EINVAL +#define NETWORK_ERROR_CODE_INVALID_ARGUMENT 3 +// Not enough memory to complete the operation. +// +// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY +#define NETWORK_ERROR_CODE_OUT_OF_MEMORY 4 +// The operation timed out before it could finish completely. +#define NETWORK_ERROR_CODE_TIMEOUT 5 +// This operation is incompatible with another asynchronous operation that is already in progress. +// +// POSIX equivalent: EALREADY +#define NETWORK_ERROR_CODE_CONCURRENCY_CONFLICT 6 +// Trying to finish an asynchronous operation that: +// - has not been started yet, or: +// - was already finished by a previous `finish-*` call. +// +// Note: this is scheduled to be removed when `future`s are natively supported. +#define NETWORK_ERROR_CODE_NOT_IN_PROGRESS 7 +// The operation has been aborted because it could not be completed immediately. +// +// Note: this is scheduled to be removed when `future`s are natively supported. +#define NETWORK_ERROR_CODE_WOULD_BLOCK 8 +// The operation is not valid in the socket's current state. +#define NETWORK_ERROR_CODE_INVALID_STATE 9 +// A new socket resource could not be created because of a system limit. +#define NETWORK_ERROR_CODE_NEW_SOCKET_LIMIT 10 +// A bind operation failed because the provided address is not an address that the `network` can bind to. +#define NETWORK_ERROR_CODE_ADDRESS_NOT_BINDABLE 11 +// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. +#define NETWORK_ERROR_CODE_ADDRESS_IN_USE 12 +// The remote address is not reachable +#define NETWORK_ERROR_CODE_REMOTE_UNREACHABLE 13 +// The TCP connection was forcefully rejected +#define NETWORK_ERROR_CODE_CONNECTION_REFUSED 14 +// The TCP connection was reset. +#define NETWORK_ERROR_CODE_CONNECTION_RESET 15 +// A TCP connection was aborted. +#define NETWORK_ERROR_CODE_CONNECTION_ABORTED 16 +// The size of a datagram sent to a UDP socket exceeded the maximum +// supported size. +#define NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE 17 +// Name does not exist or has no suitable associated IP addresses. +#define NETWORK_ERROR_CODE_NAME_UNRESOLVABLE 18 +// A temporary failure in name resolution occurred. +#define NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE 19 +// A permanent failure in name resolution occurred. +#define NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE 20 + +typedef uint8_t network_ip_address_family_t; + +// Similar to `AF_INET` in POSIX. +#define NETWORK_IP_ADDRESS_FAMILY_IPV4 0 +// Similar to `AF_INET6` in POSIX. +#define NETWORK_IP_ADDRESS_FAMILY_IPV6 1 + +typedef struct network_ipv4_address_t { + uint8_t f0; + uint8_t f1; + uint8_t f2; + uint8_t f3; +} network_ipv4_address_t; + +typedef struct network_ipv6_address_t { + uint16_t f0; + uint16_t f1; + uint16_t f2; + uint16_t f3; + uint16_t f4; + uint16_t f5; + uint16_t f6; + uint16_t f7; +} network_ipv6_address_t; + +typedef struct network_ip_address_t { + uint8_t tag; + union { + network_ipv4_address_t ipv4; + network_ipv6_address_t ipv6; + } val; +} network_ip_address_t; + +#define NETWORK_IP_ADDRESS_IPV4 0 +#define NETWORK_IP_ADDRESS_IPV6 1 + +typedef struct network_ipv4_socket_address_t { + // sin_port + uint16_t port; + // sin_addr + network_ipv4_address_t address; +} network_ipv4_socket_address_t; + +typedef struct network_ipv6_socket_address_t { + // sin6_port + uint16_t port; + // sin6_flowinfo + uint32_t flow_info; + // sin6_addr + network_ipv6_address_t address; + // sin6_scope_id + uint32_t scope_id; +} network_ipv6_socket_address_t; + +typedef struct network_ip_socket_address_t { + uint8_t tag; + union { + network_ipv4_socket_address_t ipv4; + network_ipv6_socket_address_t ipv6; + } val; +} network_ip_socket_address_t; + +#define NETWORK_IP_SOCKET_ADDRESS_IPV4 0 +#define NETWORK_IP_SOCKET_ADDRESS_IPV6 1 + +typedef network_own_network_t instance_network_own_network_t; + +typedef network_error_code_t udp_error_code_t; + +typedef network_ip_socket_address_t udp_ip_socket_address_t; + +typedef network_ip_address_family_t udp_ip_address_family_t; + +// A received datagram. +typedef struct udp_incoming_datagram_t { + // The payload. + // + // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. + wasip2_list_u8_t data; + // The source address. + // + // This field is guaranteed to match the remote address the stream was initialized with, if any. + // + // Equivalent to the `src_addr` out parameter of `recvfrom`. + udp_ip_socket_address_t remote_address; +} udp_incoming_datagram_t; + +typedef struct { + bool is_some; + udp_ip_socket_address_t val; +} udp_option_ip_socket_address_t; + +// A datagram to be sent out. +typedef struct udp_outgoing_datagram_t { + // The payload. + wasip2_list_u8_t data; + // The destination address. + // + // The requirements on this field depend on how the stream was initialized: + // - with a remote address: this field must be None or match the stream's remote address exactly. + // - without a remote address: this field is required. + // + // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`. + udp_option_ip_socket_address_t remote_address; +} udp_outgoing_datagram_t; + +typedef struct udp_own_udp_socket_t { + int32_t __handle; +} udp_own_udp_socket_t; + +typedef struct udp_borrow_udp_socket_t { + int32_t __handle; +} udp_borrow_udp_socket_t; + +typedef struct udp_own_incoming_datagram_stream_t { + int32_t __handle; +} udp_own_incoming_datagram_stream_t; + +typedef struct udp_borrow_incoming_datagram_stream_t { + int32_t __handle; +} udp_borrow_incoming_datagram_stream_t; + +typedef struct udp_own_outgoing_datagram_stream_t { + int32_t __handle; +} udp_own_outgoing_datagram_stream_t; + +typedef struct udp_borrow_outgoing_datagram_stream_t { + int32_t __handle; +} udp_borrow_outgoing_datagram_stream_t; + +typedef network_borrow_network_t udp_borrow_network_t; + +typedef struct { + bool is_err; + union { + udp_error_code_t err; + } val; +} udp_result_void_error_code_t; + +typedef struct { + udp_own_incoming_datagram_stream_t f0; + udp_own_outgoing_datagram_stream_t f1; +} udp_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_t; + +typedef struct { + bool is_err; + union { + udp_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_t ok; + udp_error_code_t err; + } val; +} udp_result_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_error_code_t; + +typedef struct { + bool is_err; + union { + udp_ip_socket_address_t ok; + udp_error_code_t err; + } val; +} udp_result_ip_socket_address_error_code_t; + +typedef struct { + bool is_err; + union { + uint8_t ok; + udp_error_code_t err; + } val; +} udp_result_u8_error_code_t; + +typedef struct { + bool is_err; + union { + uint64_t ok; + udp_error_code_t err; + } val; +} udp_result_u64_error_code_t; + +typedef poll_own_pollable_t udp_own_pollable_t; + +typedef struct { + udp_incoming_datagram_t *ptr; + size_t len; +} udp_list_incoming_datagram_t; + +typedef struct { + bool is_err; + union { + udp_list_incoming_datagram_t ok; + udp_error_code_t err; + } val; +} udp_result_list_incoming_datagram_error_code_t; + +typedef struct { + udp_outgoing_datagram_t *ptr; + size_t len; +} udp_list_outgoing_datagram_t; + +typedef network_error_code_t udp_create_socket_error_code_t; + +typedef network_ip_address_family_t udp_create_socket_ip_address_family_t; + +typedef udp_own_udp_socket_t udp_create_socket_own_udp_socket_t; + +typedef struct { + bool is_err; + union { + udp_create_socket_own_udp_socket_t ok; + udp_create_socket_error_code_t err; + } val; +} udp_create_socket_result_own_udp_socket_error_code_t; + +typedef monotonic_clock_duration_t tcp_duration_t; + +typedef network_error_code_t tcp_error_code_t; + +typedef network_ip_socket_address_t tcp_ip_socket_address_t; + +typedef network_ip_address_family_t tcp_ip_address_family_t; + +typedef uint8_t tcp_shutdown_type_t; + +// Similar to `SHUT_RD` in POSIX. +#define TCP_SHUTDOWN_TYPE_RECEIVE 0 +// Similar to `SHUT_WR` in POSIX. +#define TCP_SHUTDOWN_TYPE_SEND 1 +// Similar to `SHUT_RDWR` in POSIX. +#define TCP_SHUTDOWN_TYPE_BOTH 2 + +typedef struct tcp_own_tcp_socket_t { + int32_t __handle; +} tcp_own_tcp_socket_t; + +typedef struct tcp_borrow_tcp_socket_t { + int32_t __handle; +} tcp_borrow_tcp_socket_t; + +typedef network_borrow_network_t tcp_borrow_network_t; + +typedef struct { + bool is_err; + union { + tcp_error_code_t err; + } val; +} tcp_result_void_error_code_t; + +typedef streams_own_input_stream_t tcp_own_input_stream_t; + +typedef streams_own_output_stream_t tcp_own_output_stream_t; + +typedef struct { + tcp_own_input_stream_t f0; + tcp_own_output_stream_t f1; +} tcp_tuple2_own_input_stream_own_output_stream_t; + +typedef struct { + bool is_err; + union { + tcp_tuple2_own_input_stream_own_output_stream_t ok; + tcp_error_code_t err; + } val; +} tcp_result_tuple2_own_input_stream_own_output_stream_error_code_t; + +typedef struct { + tcp_own_tcp_socket_t f0; + tcp_own_input_stream_t f1; + tcp_own_output_stream_t f2; +} tcp_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t; + +typedef struct { + bool is_err; + union { + tcp_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t ok; + tcp_error_code_t err; + } val; +} tcp_result_tuple3_own_tcp_socket_own_input_stream_own_output_stream_error_code_t; + +typedef struct { + bool is_err; + union { + tcp_ip_socket_address_t ok; + tcp_error_code_t err; + } val; +} tcp_result_ip_socket_address_error_code_t; + +typedef struct { + bool is_err; + union { + bool ok; + tcp_error_code_t err; + } val; +} tcp_result_bool_error_code_t; + +typedef struct { + bool is_err; + union { + tcp_duration_t ok; + tcp_error_code_t err; + } val; +} tcp_result_duration_error_code_t; + +typedef struct { + bool is_err; + union { + uint32_t ok; + tcp_error_code_t err; + } val; +} tcp_result_u32_error_code_t; + +typedef struct { + bool is_err; + union { + uint8_t ok; + tcp_error_code_t err; + } val; +} tcp_result_u8_error_code_t; + +typedef struct { + bool is_err; + union { + uint64_t ok; + tcp_error_code_t err; + } val; +} tcp_result_u64_error_code_t; + +typedef poll_own_pollable_t tcp_own_pollable_t; + +typedef network_error_code_t tcp_create_socket_error_code_t; + +typedef network_ip_address_family_t tcp_create_socket_ip_address_family_t; + +typedef tcp_own_tcp_socket_t tcp_create_socket_own_tcp_socket_t; + +typedef struct { + bool is_err; + union { + tcp_create_socket_own_tcp_socket_t ok; + tcp_create_socket_error_code_t err; + } val; +} tcp_create_socket_result_own_tcp_socket_error_code_t; + +typedef network_error_code_t ip_name_lookup_error_code_t; + +typedef network_ip_address_t ip_name_lookup_ip_address_t; + +typedef struct ip_name_lookup_own_resolve_address_stream_t { + int32_t __handle; +} ip_name_lookup_own_resolve_address_stream_t; + +typedef struct ip_name_lookup_borrow_resolve_address_stream_t { + int32_t __handle; +} ip_name_lookup_borrow_resolve_address_stream_t; + +typedef network_borrow_network_t ip_name_lookup_borrow_network_t; + +typedef struct { + bool is_err; + union { + ip_name_lookup_own_resolve_address_stream_t ok; + ip_name_lookup_error_code_t err; + } val; +} ip_name_lookup_result_own_resolve_address_stream_error_code_t; + +typedef struct { + bool is_some; + ip_name_lookup_ip_address_t val; +} ip_name_lookup_option_ip_address_t; + +typedef struct { + bool is_err; + union { + ip_name_lookup_option_ip_address_t ok; + ip_name_lookup_error_code_t err; + } val; +} ip_name_lookup_result_option_ip_address_error_code_t; + +typedef poll_own_pollable_t ip_name_lookup_own_pollable_t; + +typedef struct { + uint64_t f0; + uint64_t f1; +} wasip2_tuple2_u64_u64_t; + +// Imported Functions from `wasi:cli/environment@0.2.0` +// Get the POSIX-style environment variables. +// +// Each environment variable is provided as a pair of string variable names +// and string value. +// +// Morally, these are a value import, but until value imports are available +// in the component model, this import function should return the same +// values each time it is called. +extern void environment_get_environment(wasip2_list_tuple2_string_string_t *ret); +// Get the POSIX-style arguments to the program. +extern void environment_get_arguments(wasip2_list_string_t *ret); +// Return a path that programs should use as their initial current working +// directory, interpreting `.` as shorthand for this. +extern bool environment_initial_cwd(wasip2_string_t *ret); + +// Imported Functions from `wasi:cli/exit@0.2.0` +// Exit the current instance and any linked instances. +_Noreturn extern void exit_exit(exit_result_void_void_t *status); + +// Imported Functions from `wasi:io/error@0.2.0` +// Returns a string that is suitable to assist humans in debugging +// this error. +// +// WARNING: The returned string should not be consumed mechanically! +// It may change across platforms, hosts, or other implementation +// details. Parsing this string is a major platform-compatibility +// hazard. +extern void io_error_method_error_to_debug_string(io_error_borrow_error_t self, wasip2_string_t *ret); + +// Imported Functions from `wasi:io/poll@0.2.0` +// Return the readiness of a pollable. This function never blocks. +// +// Returns `true` when the pollable is ready, and `false` otherwise. +extern bool poll_method_pollable_ready(poll_borrow_pollable_t self); +// `block` returns immediately if the pollable is ready, and otherwise +// blocks until ready. +// +// This function is equivalent to calling `poll.poll` on a list +// containing only this pollable. +extern void poll_method_pollable_block(poll_borrow_pollable_t self); +// Poll for completion on a set of pollables. +// +// This function takes a list of pollables, which identify I/O sources of +// interest, and waits until one or more of the events is ready for I/O. +// +// The result `list` contains one or more indices of handles in the +// argument list that is ready for I/O. +// +// If the list contains more elements than can be indexed with a `u32` +// value, this function traps. +// +// A timeout can be implemented by adding a pollable from the +// wasi-clocks API to the list. +// +// This function does not return a `result`; polling in itself does not +// do any I/O so it doesn't fail. If any of the I/O sources identified by +// the pollables has an error, it is indicated by marking the source as +// being reaedy for I/O. +extern void poll_poll(poll_list_borrow_pollable_t *in, wasip2_list_u32_t *ret); + +// Imported Functions from `wasi:io/streams@0.2.0` +// Perform a non-blocking read from the stream. +// +// When the source of a `read` is binary data, the bytes from the source +// are returned verbatim. When the source of a `read` is known to the +// implementation to be text, bytes containing the UTF-8 encoding of the +// text are returned. +// +// This function returns a list of bytes containing the read data, +// when successful. The returned list will contain up to `len` bytes; +// it may return fewer than requested, but not more. The list is +// empty when no bytes are available for reading at this time. The +// pollable given by `subscribe` will be ready when more bytes are +// available. +// +// This function fails with a `stream-error` when the operation +// encounters an error, giving `last-operation-failed`, or when the +// stream is closed, giving `closed`. +// +// When the caller gives a `len` of 0, it represents a request to +// read 0 bytes. If the stream is still open, this call should +// succeed and return an empty list, or otherwise fail with `closed`. +// +// The `len` parameter is a `u64`, which could represent a list of u8 which +// is not possible to allocate in wasm32, or not desirable to allocate as +// as a return value by the callee. The callee may return a list of bytes +// less than `len` in size while more bytes are available for reading. +extern bool streams_method_input_stream_read(streams_borrow_input_stream_t self, uint64_t len, wasip2_list_u8_t *ret, streams_stream_error_t *err); +// Read bytes from a stream, after blocking until at least one byte can +// be read. Except for blocking, behavior is identical to `read`. +extern bool streams_method_input_stream_blocking_read(streams_borrow_input_stream_t self, uint64_t len, wasip2_list_u8_t *ret, streams_stream_error_t *err); +// Skip bytes from a stream. Returns number of bytes skipped. +// +// Behaves identical to `read`, except instead of returning a list +// of bytes, returns the number of bytes consumed from the stream. +extern bool streams_method_input_stream_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err); +// Skip bytes from a stream, after blocking until at least one byte +// can be skipped. Except for blocking behavior, identical to `skip`. +extern bool streams_method_input_stream_blocking_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err); +// Create a `pollable` which will resolve once either the specified stream +// has bytes available to read or the other end of the stream has been +// closed. +// The created `pollable` is a child resource of the `input-stream`. +// Implementations may trap if the `input-stream` is dropped before +// all derived `pollable`s created with this function are dropped. +extern streams_own_pollable_t streams_method_input_stream_subscribe(streams_borrow_input_stream_t self); +// Check readiness for writing. This function never blocks. +// +// Returns the number of bytes permitted for the next call to `write`, +// or an error. Calling `write` with more bytes than this function has +// permitted will trap. +// +// When this function returns 0 bytes, the `subscribe` pollable will +// become ready when this function will report at least 1 byte, or an +// error. +extern bool streams_method_output_stream_check_write(streams_borrow_output_stream_t self, uint64_t *ret, streams_stream_error_t *err); +// Perform a write. This function never blocks. +// +// When the destination of a `write` is binary data, the bytes from +// `contents` are written verbatim. When the destination of a `write` is +// known to the implementation to be text, the bytes of `contents` are +// transcoded from UTF-8 into the encoding of the destination and then +// written. +// +// Precondition: check-write gave permit of Ok(n) and contents has a +// length of less than or equal to n. Otherwise, this function will trap. +// +// returns Err(closed) without writing if the stream has closed since +// the last call to check-write provided a permit. +extern bool streams_method_output_stream_write(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err); +// Perform a write of up to 4096 bytes, and then flush the stream. Block +// until all of these operations are complete, or an error occurs. +// +// This is a convenience wrapper around the use of `check-write`, +// `subscribe`, `write`, and `flush`, and is implemented with the +// following pseudo-code: +// +// ```text +// let pollable = this.subscribe(); +// while !contents.is_empty() { +// // Wait for the stream to become writable +// pollable.block(); +// let Ok(n) = this.check-write(); // eliding error handling +// let len = min(n, contents.len()); +// let (chunk, rest) = contents.split_at(len); +// this.write(chunk ); // eliding error handling +// contents = rest; +// } +// this.flush(); +// // Wait for completion of `flush` +// pollable.block(); +// // Check for any errors that arose during `flush` +// let _ = this.check-write(); // eliding error handling +// ``` +extern bool streams_method_output_stream_blocking_write_and_flush(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err); +// Request to flush buffered output. This function never blocks. +// +// This tells the output-stream that the caller intends any buffered +// output to be flushed. the output which is expected to be flushed +// is all that has been passed to `write` prior to this call. +// +// Upon calling this function, the `output-stream` will not accept any +// writes (`check-write` will return `ok(0)`) until the flush has +// completed. The `subscribe` pollable will become ready when the +// flush has completed and the stream can accept more writes. +extern bool streams_method_output_stream_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err); +// Request to flush buffered output, and block until flush completes +// and stream is ready for writing again. +extern bool streams_method_output_stream_blocking_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err); +// Create a `pollable` which will resolve once the output-stream +// is ready for more writing, or an error has occured. When this +// pollable is ready, `check-write` will return `ok(n)` with n>0, or an +// error. +// +// If the stream is closed, this pollable is always ready immediately. +// +// The created `pollable` is a child resource of the `output-stream`. +// Implementations may trap if the `output-stream` is dropped before +// all derived `pollable`s created with this function are dropped. +extern streams_own_pollable_t streams_method_output_stream_subscribe(streams_borrow_output_stream_t self); +// Write zeroes to a stream. +// +// This should be used precisely like `write` with the exact same +// preconditions (must use check-write first), but instead of +// passing a list of bytes, you simply pass the number of zero-bytes +// that should be written. +extern bool streams_method_output_stream_write_zeroes(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err); +// Perform a write of up to 4096 zeroes, and then flush the stream. +// Block until all of these operations are complete, or an error +// occurs. +// +// This is a convenience wrapper around the use of `check-write`, +// `subscribe`, `write-zeroes`, and `flush`, and is implemented with +// the following pseudo-code: +// +// ```text +// let pollable = this.subscribe(); +// while num_zeroes != 0 { +// // Wait for the stream to become writable +// pollable.block(); +// let Ok(n) = this.check-write(); // eliding error handling +// let len = min(n, num_zeroes); +// this.write-zeroes(len); // eliding error handling +// num_zeroes -= len; +// } +// this.flush(); +// // Wait for completion of `flush` +// pollable.block(); +// // Check for any errors that arose during `flush` +// let _ = this.check-write(); // eliding error handling +// ``` +extern bool streams_method_output_stream_blocking_write_zeroes_and_flush(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err); +// Read from one stream and write to another. +// +// The behavior of splice is equivelant to: +// 1. calling `check-write` on the `output-stream` +// 2. calling `read` on the `input-stream` with the smaller of the +// `check-write` permitted length and the `len` provided to `splice` +// 3. calling `write` on the `output-stream` with that read data. +// +// Any error reported by the call to `check-write`, `read`, or +// `write` ends the splice and reports that error. +// +// This function returns the number of bytes transferred; it may be less +// than `len`. +extern bool streams_method_output_stream_splice(streams_borrow_output_stream_t self, streams_borrow_input_stream_t src, uint64_t len, uint64_t *ret, streams_stream_error_t *err); +// Read from one stream and write to another, with blocking. +// +// This is similar to `splice`, except that it blocks until the +// `output-stream` is ready for writing, and the `input-stream` +// is ready for reading, before performing the `splice`. +extern bool streams_method_output_stream_blocking_splice(streams_borrow_output_stream_t self, streams_borrow_input_stream_t src, uint64_t len, uint64_t *ret, streams_stream_error_t *err); + +// Imported Functions from `wasi:cli/stdin@0.2.0` +extern stdin_own_input_stream_t stdin_get_stdin(void); + +// Imported Functions from `wasi:cli/stdout@0.2.0` +extern stdout_own_output_stream_t stdout_get_stdout(void); + +// Imported Functions from `wasi:cli/stderr@0.2.0` +extern stderr_own_output_stream_t stderr_get_stderr(void); + +// Imported Functions from `wasi:cli/terminal-stdin@0.2.0` +// If stdin is connected to a terminal, return a `terminal-input` handle +// allowing further interaction with it. +extern bool terminal_stdin_get_terminal_stdin(terminal_stdin_own_terminal_input_t *ret); + +// Imported Functions from `wasi:cli/terminal-stdout@0.2.0` +// If stdout is connected to a terminal, return a `terminal-output` handle +// allowing further interaction with it. +extern bool terminal_stdout_get_terminal_stdout(terminal_stdout_own_terminal_output_t *ret); + +// Imported Functions from `wasi:cli/terminal-stderr@0.2.0` +// If stderr is connected to a terminal, return a `terminal-output` handle +// allowing further interaction with it. +extern bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t *ret); + +// Imported Functions from `wasi:clocks/monotonic-clock@0.2.0` +// Read the current value of the clock. +// +// The clock is monotonic, therefore calling this function repeatedly will +// produce a sequence of non-decreasing values. +extern monotonic_clock_instant_t monotonic_clock_now(void); +// Query the resolution of the clock. Returns the duration of time +// corresponding to a clock tick. +extern monotonic_clock_duration_t monotonic_clock_resolution(void); +// Create a `pollable` which will resolve once the specified instant +// occured. +extern monotonic_clock_own_pollable_t monotonic_clock_subscribe_instant(monotonic_clock_instant_t when); +// Create a `pollable` which will resolve once the given duration has +// elapsed, starting at the time at which this function was called. +// occured. +extern monotonic_clock_own_pollable_t monotonic_clock_subscribe_duration(monotonic_clock_duration_t when); + +// Imported Functions from `wasi:clocks/wall-clock@0.2.0` +// Read the current value of the clock. +// +// This clock is not monotonic, therefore calling this function repeatedly +// will not necessarily produce a sequence of non-decreasing values. +// +// The returned timestamps represent the number of seconds since +// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], +// also known as [Unix Time]. +// +// The nanoseconds field of the output is always less than 1000000000. +// +// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 +// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time +extern void wall_clock_now(wall_clock_datetime_t *ret); +// Query the resolution of the clock. +// +// The nanoseconds field of the output is always less than 1000000000. +extern void wall_clock_resolution(wall_clock_datetime_t *ret); + +// Imported Functions from `wasi:filesystem/types@0.2.0` +// Return a stream for reading from a file, if available. +// +// May fail with an error-code describing why the file cannot be read. +// +// Multiple read, write, and append streams may be active on the same open +// file and they do not interfere with each other. +// +// Note: This allows using `read-stream`, which is similar to `read` in POSIX. +extern bool filesystem_method_descriptor_read_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_own_input_stream_t *ret, filesystem_error_code_t *err); +// Return a stream for writing to a file, if available. +// +// May fail with an error-code describing why the file cannot be written. +// +// Note: This allows using `write-stream`, which is similar to `write` in +// POSIX. +extern bool filesystem_method_descriptor_write_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_own_output_stream_t *ret, filesystem_error_code_t *err); +// Return a stream for appending to a file, if available. +// +// May fail with an error-code describing why the file cannot be appended. +// +// Note: This allows using `write-stream`, which is similar to `write` with +// `O_APPEND` in in POSIX. +extern bool filesystem_method_descriptor_append_via_stream(filesystem_borrow_descriptor_t self, filesystem_own_output_stream_t *ret, filesystem_error_code_t *err); +// Provide file advisory information on a descriptor. +// +// This is similar to `posix_fadvise` in POSIX. +extern bool filesystem_method_descriptor_advise(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_filesize_t length, filesystem_advice_t advice, filesystem_error_code_t *err); +// Synchronize the data of a file to disk. +// +// This function succeeds with no effect if the file descriptor is not +// opened for writing. +// +// Note: This is similar to `fdatasync` in POSIX. +extern bool filesystem_method_descriptor_sync_data(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err); +// Get flags associated with a descriptor. +// +// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. +// +// Note: This returns the value that was the `fs_flags` value returned +// from `fdstat_get` in earlier versions of WASI. +extern bool filesystem_method_descriptor_get_flags(filesystem_borrow_descriptor_t self, filesystem_descriptor_flags_t *ret, filesystem_error_code_t *err); +// Get the dynamic type of a descriptor. +// +// Note: This returns the same value as the `type` field of the `fd-stat` +// returned by `stat`, `stat-at` and similar. +// +// Note: This returns similar flags to the `st_mode & S_IFMT` value provided +// by `fstat` in POSIX. +// +// Note: This returns the value that was the `fs_filetype` value returned +// from `fdstat_get` in earlier versions of WASI. +extern bool filesystem_method_descriptor_get_type(filesystem_borrow_descriptor_t self, filesystem_descriptor_type_t *ret, filesystem_error_code_t *err); +// Adjust the size of an open file. If this increases the file's size, the +// extra bytes are filled with zeros. +// +// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. +extern bool filesystem_method_descriptor_set_size(filesystem_borrow_descriptor_t self, filesystem_filesize_t size, filesystem_error_code_t *err); +// Adjust the timestamps of an open file or directory. +// +// Note: This is similar to `futimens` in POSIX. +// +// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. +extern bool filesystem_method_descriptor_set_times(filesystem_borrow_descriptor_t self, filesystem_new_timestamp_t *data_access_timestamp, filesystem_new_timestamp_t *data_modification_timestamp, filesystem_error_code_t *err); +// Read from a descriptor, without using and updating the descriptor's offset. +// +// This function returns a list of bytes containing the data that was +// read, along with a bool which, when true, indicates that the end of the +// file was reached. The returned list will contain up to `length` bytes; it +// may return fewer than requested, if the end of the file is reached or +// if the I/O operation is interrupted. +// +// In the future, this may change to return a `stream`. +// +// Note: This is similar to `pread` in POSIX. +extern bool filesystem_method_descriptor_read(filesystem_borrow_descriptor_t self, filesystem_filesize_t length, filesystem_filesize_t offset, wasip2_tuple2_list_u8_bool_t *ret, filesystem_error_code_t *err); +// Write to a descriptor, without using and updating the descriptor's offset. +// +// It is valid to write past the end of a file; the file is extended to the +// extent of the write, with bytes between the previous end and the start of +// the write set to zero. +// +// In the future, this may change to take a `stream`. +// +// Note: This is similar to `pwrite` in POSIX. +extern bool filesystem_method_descriptor_write(filesystem_borrow_descriptor_t self, wasip2_list_u8_t *buffer, filesystem_filesize_t offset, filesystem_filesize_t *ret, filesystem_error_code_t *err); +// Read directory entries from a directory. +// +// On filesystems where directories contain entries referring to themselves +// and their parents, often named `.` and `..` respectively, these entries +// are omitted. +// +// This always returns a new stream which starts at the beginning of the +// directory. Multiple streams may be active on the same directory, and they +// do not interfere with each other. +extern bool filesystem_method_descriptor_read_directory(filesystem_borrow_descriptor_t self, filesystem_own_directory_entry_stream_t *ret, filesystem_error_code_t *err); +// Synchronize the data and metadata of a file to disk. +// +// This function succeeds with no effect if the file descriptor is not +// opened for writing. +// +// Note: This is similar to `fsync` in POSIX. +extern bool filesystem_method_descriptor_sync(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err); +// Create a directory. +// +// Note: This is similar to `mkdirat` in POSIX. +extern bool filesystem_method_descriptor_create_directory_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); +// Return the attributes of an open file or directory. +// +// Note: This is similar to `fstat` in POSIX, except that it does not return +// device and inode information. For testing whether two descriptors refer to +// the same underlying filesystem object, use `is-same-object`. To obtain +// additional data that can be used do determine whether a file has been +// modified, use `metadata-hash`. +// +// Note: This was called `fd_filestat_get` in earlier versions of WASI. +extern bool filesystem_method_descriptor_stat(filesystem_borrow_descriptor_t self, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err); +// Return the attributes of a file or directory. +// +// Note: This is similar to `fstatat` in POSIX, except that it does not +// return device and inode information. See the `stat` description for a +// discussion of alternatives. +// +// Note: This was called `path_filestat_get` in earlier versions of WASI. +extern bool filesystem_method_descriptor_stat_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err); +// Adjust the timestamps of a file or directory. +// +// Note: This is similar to `utimensat` in POSIX. +// +// Note: This was called `path_filestat_set_times` in earlier versions of +// WASI. +extern bool filesystem_method_descriptor_set_times_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_new_timestamp_t *data_access_timestamp, filesystem_new_timestamp_t *data_modification_timestamp, filesystem_error_code_t *err); +// Create a hard link. +// +// Note: This is similar to `linkat` in POSIX. +extern bool filesystem_method_descriptor_link_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t old_path_flags, wasip2_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, wasip2_string_t *new_path, filesystem_error_code_t *err); +// Open a file or directory. +// +// The returned descriptor is not guaranteed to be the lowest-numbered +// 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 descriptor is +// guaranteed to be less than 2**31. +// +// If `flags` contains `descriptor-flags::mutate-directory`, and the base +// descriptor doesn't have `descriptor-flags::mutate-directory` set, +// `open-at` fails with `error-code::read-only`. +// +// If `flags` contains `write` or `mutate-directory`, or `open-flags` +// contains `truncate` or `create`, and the base descriptor doesn't have +// `descriptor-flags::mutate-directory` set, `open-at` fails with +// `error-code::read-only`. +// +// Note: This is similar to `openat` in POSIX. +extern bool filesystem_method_descriptor_open_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_open_flags_t open_flags, filesystem_descriptor_flags_t flags, filesystem_own_descriptor_t *ret, filesystem_error_code_t *err); +// Read the contents of a symbolic link. +// +// If the contents contain an absolute or rooted path in the underlying +// filesystem, this function fails with `error-code::not-permitted`. +// +// Note: This is similar to `readlinkat` in POSIX. +extern bool filesystem_method_descriptor_readlink_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, wasip2_string_t *ret, filesystem_error_code_t *err); +// Remove a directory. +// +// Return `error-code::not-empty` if the directory is not empty. +// +// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. +extern bool filesystem_method_descriptor_remove_directory_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); +// Rename a filesystem object. +// +// Note: This is similar to `renameat` in POSIX. +extern bool filesystem_method_descriptor_rename_at(filesystem_borrow_descriptor_t self, wasip2_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, wasip2_string_t *new_path, filesystem_error_code_t *err); +// Create a symbolic link (also known as a "symlink"). +// +// If `old-path` starts with `/`, the function fails with +// `error-code::not-permitted`. +// +// Note: This is similar to `symlinkat` in POSIX. +extern bool filesystem_method_descriptor_symlink_at(filesystem_borrow_descriptor_t self, wasip2_string_t *old_path, wasip2_string_t *new_path, filesystem_error_code_t *err); +// Unlink a filesystem object that is not a directory. +// +// Return `error-code::is-directory` if the path refers to a directory. +// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. +extern bool filesystem_method_descriptor_unlink_file_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); +// Test whether two descriptors refer to the same filesystem object. +// +// In POSIX, this corresponds to testing whether the two descriptors have the +// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. +// wasi-filesystem does not expose device and inode numbers, so this function +// may be used instead. +extern bool filesystem_method_descriptor_is_same_object(filesystem_borrow_descriptor_t self, filesystem_borrow_descriptor_t other); +// Return a hash of the metadata associated with a filesystem object referred +// to by a descriptor. +// +// This returns a hash of the last-modification timestamp and file size, and +// may also include the inode number, device number, birth timestamp, and +// other metadata fields that may change when the file is modified or +// replaced. It may also include a secret value chosen by the +// implementation and not otherwise exposed. +// +// Implementations are encourated to provide the following properties: +// +// - If the file is not modified or replaced, the computed hash value should +// usually not change. +// - If the object is modified or replaced, the computed hash value should +// usually change. +// - The inputs to the hash should not be easily computable from the +// computed hash. +// +// However, none of these is required. +extern bool filesystem_method_descriptor_metadata_hash(filesystem_borrow_descriptor_t self, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err); +// Return a hash of the metadata associated with a filesystem object referred +// to by a directory descriptor and a relative path. +// +// This performs the same hash computation as `metadata-hash`. +extern bool filesystem_method_descriptor_metadata_hash_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err); +// Read a single directory entry from a `directory-entry-stream`. +extern bool filesystem_method_directory_entry_stream_read_directory_entry(filesystem_borrow_directory_entry_stream_t self, filesystem_option_directory_entry_t *ret, filesystem_error_code_t *err); +// Attempts to extract a filesystem-related `error-code` from the stream +// `error` provided. +// +// Stream operations which return `stream-error::last-operation-failed` +// have a payload with more information about the operation that failed. +// This payload can be passed through to this function to see if there's +// filesystem-related information about the error to return. +// +// Note that this function is fallible because not all stream-related +// errors are filesystem-related errors. +extern bool filesystem_filesystem_error_code(filesystem_borrow_error_t err_, filesystem_error_code_t *ret); + +// Imported Functions from `wasi:filesystem/preopens@0.2.0` +// Return the set of preopened directories, and their path. +extern void filesystem_preopens_get_directories(filesystem_preopens_list_tuple2_own_descriptor_string_t *ret); + +// Imported Functions from `wasi:sockets/instance-network@0.2.0` +// Get a handle to the default network. +extern instance_network_own_network_t instance_network_instance_network(void); + +// Imported Functions from `wasi:sockets/udp@0.2.0` +// Bind the socket to a specific network on the provided IP address and port. +// +// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which +// network interface(s) to bind to. +// If the port is zero, the socket will be bound to a random free port. +// +// # Typical errors +// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) +// - `invalid-state`: The socket is already bound. (EINVAL) +// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) +// - `address-in-use`: Address is already in use. (EADDRINUSE) +// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) +// - `not-in-progress`: A `bind` operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// Unlike in POSIX, in WASI the bind operation is async. This enables +// interactive WASI hosts to inject permission prompts. Runtimes that +// don't want to make use of this ability can simply call the native +// `bind` as part of either `start-bind` or `finish-bind`. +// +// # References +// - +// - +// - +// - +extern bool udp_method_udp_socket_start_bind(udp_borrow_udp_socket_t self, udp_borrow_network_t network, udp_ip_socket_address_t *local_address, udp_error_code_t *err); +extern bool udp_method_udp_socket_finish_bind(udp_borrow_udp_socket_t self, udp_error_code_t *err); +// Set up inbound & outbound communication channels, optionally to a specific peer. +// +// This function only changes the local socket configuration and does not generate any network traffic. +// On success, the `remote-address` of the socket is updated. The `local-address` may be updated as well, +// based on the best network path to `remote-address`. +// +// When a `remote-address` is provided, the returned streams are limited to communicating with that specific peer: +// - `send` can only be used to send to this destination. +// - `receive` will only return datagrams sent from the provided `remote-address`. +// +// This method may be called multiple times on the same socket to change its association, but +// only the most recently returned pair of streams will be operational. Implementations may trap if +// the streams returned by a previous invocation haven't been dropped yet before calling `stream` again. +// +// The POSIX equivalent in pseudo-code is: +// ```text +// if (was previously connected) { +// connect(s, AF_UNSPEC) +// } +// if (remote_address is Some) { +// connect(s, remote_address) +// } +// ``` +// +// Unlike in POSIX, the socket must already be explicitly bound. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-state`: The socket is not bound. +// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// +// # References +// - +// - +// - +// - +extern bool udp_method_udp_socket_stream(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *maybe_remote_address, udp_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_t *ret, udp_error_code_t *err); +// Get the current bound address. +// +// POSIX mentions: +// > If the socket has not been bound to a local name, the value +// > stored in the object pointed to by `address` is unspecified. +// +// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. +// +// # References +// - +// - +// - +// - +extern bool udp_method_udp_socket_local_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err); +// Get the address the socket is currently streaming to. +// +// # Typical errors +// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) +// +// # References +// - +// - +// - +// - +extern bool udp_method_udp_socket_remote_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err); +// Whether this is a IPv4 or IPv6 socket. +// +// Equivalent to the SO_DOMAIN socket option. +extern udp_ip_address_family_t udp_method_udp_socket_address_family(udp_borrow_udp_socket_t self); +// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// +// # Typical errors +// - `invalid-argument`: (set) The TTL value must be 1 or higher. +extern bool udp_method_udp_socket_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t *ret, udp_error_code_t *err); +extern bool udp_method_udp_socket_set_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t value, udp_error_code_t *err); +// The kernel buffer space reserved for sends/receives on this socket. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +extern bool udp_method_udp_socket_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err); +extern bool udp_method_udp_socket_set_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err); +extern bool udp_method_udp_socket_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err); +extern bool udp_method_udp_socket_set_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err); +// Create a `pollable` which will resolve once the socket is ready for I/O. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. +extern udp_own_pollable_t udp_method_udp_socket_subscribe(udp_borrow_udp_socket_t self); +// Receive messages on the socket. +// +// This function attempts to receive up to `max-results` datagrams on the socket without blocking. +// The returned list may contain fewer elements than requested, but never more. +// +// This function returns successfully with an empty list when either: +// - `max-results` is 0, or: +// - `max-results` is greater than 0, but no results are immediately available. +// This function never returns `error(would-block)`. +// +// # Typical errors +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// +// # References +// - +// - +// - +// - +// - +// - +// - +// - +extern bool udp_method_incoming_datagram_stream_receive(udp_borrow_incoming_datagram_stream_t self, uint64_t max_results, udp_list_incoming_datagram_t *ret, udp_error_code_t *err); +// Create a `pollable` which will resolve once the stream is ready to receive again. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. +extern udp_own_pollable_t udp_method_incoming_datagram_stream_subscribe(udp_borrow_incoming_datagram_stream_t self); +// Check readiness for sending. This function never blocks. +// +// Returns the number of datagrams permitted for the next call to `send`, +// or an error. Calling `send` with more datagrams than this function has +// permitted will trap. +// +// When this function returns ok(0), the `subscribe` pollable will +// become ready when this function will report at least ok(1), or an +// error. +// +// Never returns `would-block`. +extern bool udp_method_outgoing_datagram_stream_check_send(udp_borrow_outgoing_datagram_stream_t self, uint64_t *ret, udp_error_code_t *err); +// Send messages on the socket. +// +// This function attempts to send all provided `datagrams` on the socket without blocking and +// returns how many messages were actually sent (or queued for sending). This function never +// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned. +// +// This function semantically behaves the same as iterating the `datagrams` list and sequentially +// sending each individual datagram until either the end of the list has been reached or the first error occurred. +// If at least one datagram has been sent successfully, this function never returns an error. +// +// If the input list is empty, the function returns `ok(0)`. +// +// Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if +// either `check-send` was not called or `datagrams` contains more items than `check-send` permitted. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN) +// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ) +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) +// +// # References +// - +// - +// - +// - +// - +// - +// - +// - +extern bool udp_method_outgoing_datagram_stream_send(udp_borrow_outgoing_datagram_stream_t self, udp_list_outgoing_datagram_t *datagrams, uint64_t *ret, udp_error_code_t *err); +// Create a `pollable` which will resolve once the stream is ready to send again. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. +extern udp_own_pollable_t udp_method_outgoing_datagram_stream_subscribe(udp_borrow_outgoing_datagram_stream_t self); + +// Imported Functions from `wasi:sockets/udp-create-socket@0.2.0` +// Create a new UDP socket. +// +// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX. +// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. +// +// This function does not require a network capability handle. This is considered to be safe because +// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind` is called, +// the socket is effectively an in-memory configuration object, unable to communicate with the outside world. +// +// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. +// +// # Typical errors +// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) +// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) +// +// # References: +// - +// - +// - +// - +extern bool udp_create_socket_create_udp_socket(udp_create_socket_ip_address_family_t address_family, udp_create_socket_own_udp_socket_t *ret, udp_create_socket_error_code_t *err); + +// Imported Functions from `wasi:sockets/tcp@0.2.0` +// Bind the socket to a specific network on the provided IP address and port. +// +// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which +// network interface(s) to bind to. +// If the TCP/UDP port is zero, the socket will be bound to a random free port. +// +// Bind can be attempted multiple times on the same socket, even with +// different arguments on each iteration. But never concurrently and +// only as long as the previous bind failed. Once a bind succeeds, the +// binding can't be changed anymore. +// +// # Typical errors +// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) +// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) +// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL) +// - `invalid-state`: The socket is already bound. (EINVAL) +// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) +// - `address-in-use`: Address is already in use. (EADDRINUSE) +// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) +// - `not-in-progress`: A `bind` operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT +// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR +// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior +// and SO_REUSEADDR performs something different entirely. +// +// Unlike in POSIX, in WASI the bind operation is async. This enables +// interactive WASI hosts to inject permission prompts. Runtimes that +// don't want to make use of this ability can simply call the native +// `bind` as part of either `start-bind` or `finish-bind`. +// +// # References +// - +// - +// - +// - +extern bool tcp_method_tcp_socket_start_bind(tcp_borrow_tcp_socket_t self, tcp_borrow_network_t network, tcp_ip_socket_address_t *local_address, tcp_error_code_t *err); +extern bool tcp_method_tcp_socket_finish_bind(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); +// Connect to a remote endpoint. +// +// On success: +// - the socket is transitioned into the `connection` state. +// - a pair of streams is returned that can be used to read & write to the connection +// +// After a failed connection attempt, the socket will be in the `closed` +// state and the only valid action left is to `drop` the socket. A single +// socket can not be used to connect more than once. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) +// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) +// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows) +// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. +// - `invalid-state`: The socket is already in the `connected` state. (EISCONN) +// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows) +// - `timeout`: Connection timed out. (ETIMEDOUT) +// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) +// - `connection-reset`: The connection was reset. (ECONNRESET) +// - `connection-aborted`: The connection was aborted. (ECONNABORTED) +// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) +// - `not-in-progress`: A connect operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// The POSIX equivalent of `start-connect` is the regular `connect` syscall. +// Because all WASI sockets are non-blocking this is expected to return +// EINPROGRESS, which should be translated to `ok()` in WASI. +// +// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` +// with a timeout of 0 on the socket descriptor. Followed by a check for +// the `SO_ERROR` socket option, in case the poll signaled readiness. +// +// # References +// - +// - +// - +// - +extern bool tcp_method_tcp_socket_start_connect(tcp_borrow_tcp_socket_t self, tcp_borrow_network_t network, tcp_ip_socket_address_t *remote_address, tcp_error_code_t *err); +extern bool tcp_method_tcp_socket_finish_connect(tcp_borrow_tcp_socket_t self, tcp_tuple2_own_input_stream_own_output_stream_t *ret, tcp_error_code_t *err); +// Start listening for new connections. +// +// Transitions the socket into the `listening` state. +// +// Unlike POSIX, the socket must already be explicitly bound. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) +// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD) +// - `invalid-state`: The socket is already in the `listening` state. +// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE) +// - `not-in-progress`: A listen operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// Unlike in POSIX, in WASI the listen operation is async. This enables +// interactive WASI hosts to inject permission prompts. Runtimes that +// don't want to make use of this ability can simply call the native +// `listen` as part of either `start-listen` or `finish-listen`. +// +// # References +// - +// - +// - +// - +extern bool tcp_method_tcp_socket_start_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); +extern bool tcp_method_tcp_socket_finish_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); +// Accept a new client socket. +// +// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket: +// - `address-family` +// - `keep-alive-enabled` +// - `keep-alive-idle-time` +// - `keep-alive-interval` +// - `keep-alive-count` +// - `hop-limit` +// - `receive-buffer-size` +// - `send-buffer-size` +// +// On success, this function returns the newly accepted client socket along with +// a pair of streams that can be used to read & write to the connection. +// +// # Typical errors +// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) +// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) +// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED) +// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) +// +// # References +// - +// - +// - +// - +extern bool tcp_method_tcp_socket_accept(tcp_borrow_tcp_socket_t self, tcp_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ret, tcp_error_code_t *err); +// Get the bound local address. +// +// POSIX mentions: +// > If the socket has not been bound to a local name, the value +// > stored in the object pointed to by `address` is unspecified. +// +// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. +// +// # References +// - +// - +// - +// - +extern bool tcp_method_tcp_socket_local_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err); +// Get the remote address. +// +// # Typical errors +// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) +// +// # References +// - +// - +// - +// - +extern bool tcp_method_tcp_socket_remote_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err); +// Whether the socket is in the `listening` state. +// +// Equivalent to the SO_ACCEPTCONN socket option. +extern bool tcp_method_tcp_socket_is_listening(tcp_borrow_tcp_socket_t self); +// Whether this is a IPv4 or IPv6 socket. +// +// Equivalent to the SO_DOMAIN socket option. +extern tcp_ip_address_family_t tcp_method_tcp_socket_address_family(tcp_borrow_tcp_socket_t self); +// Hints the desired listen queue size. Implementations are free to ignore this. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// +// # Typical errors +// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. +// - `invalid-argument`: (set) The provided value was 0. +// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state. +extern bool tcp_method_tcp_socket_set_listen_backlog_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); +// Enables or disables keepalive. +// +// The keepalive behavior can be adjusted using: +// - `keep-alive-idle-time` +// - `keep-alive-interval` +// - `keep-alive-count` +// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. +// +// Equivalent to the SO_KEEPALIVE socket option. +extern bool tcp_method_tcp_socket_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool *ret, tcp_error_code_t *err); +extern bool tcp_method_tcp_socket_set_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool value, tcp_error_code_t *err); +// Amount of time the connection has to be idle before TCP starts sending keepalive packets. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +extern bool tcp_method_tcp_socket_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err); +extern bool tcp_method_tcp_socket_set_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err); +// The time between keepalive packets. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the TCP_KEEPINTVL socket option. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +extern bool tcp_method_tcp_socket_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err); +extern bool tcp_method_tcp_socket_set_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err); +// The maximum amount of keepalive packets TCP should send before aborting the connection. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the TCP_KEEPCNT socket option. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +extern bool tcp_method_tcp_socket_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t *ret, tcp_error_code_t *err); +extern bool tcp_method_tcp_socket_set_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t value, tcp_error_code_t *err); +// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// +// # Typical errors +// - `invalid-argument`: (set) The TTL value must be 1 or higher. +extern bool tcp_method_tcp_socket_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t *ret, tcp_error_code_t *err); +extern bool tcp_method_tcp_socket_set_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t value, tcp_error_code_t *err); +// The kernel buffer space reserved for sends/receives on this socket. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +extern bool tcp_method_tcp_socket_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err); +extern bool tcp_method_tcp_socket_set_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); +extern bool tcp_method_tcp_socket_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err); +extern bool tcp_method_tcp_socket_set_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); +// Create a `pollable` which can be used to poll for, or block on, +// completion of any of the asynchronous operations of this socket. +// +// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` +// return `error(would-block)`, this pollable can be used to wait for +// their success or failure, after which the method can be retried. +// +// The pollable is not limited to the async operation that happens to be +// in progress at the time of calling `subscribe` (if any). Theoretically, +// `subscribe` only has to be called once per socket and can then be +// (re)used for the remainder of the socket's lifetime. +// +// See +// for a more information. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. +extern tcp_own_pollable_t tcp_method_tcp_socket_subscribe(tcp_borrow_tcp_socket_t self); +// Initiate a graceful shutdown. +// +// - `receive`: The socket is not expecting to receive any data from +// the peer. The `input-stream` associated with this socket will be +// closed. Any data still in the receive queue at time of calling +// this method will be discarded. +// - `send`: The socket has no more data to send to the peer. The `output-stream` +// associated with this socket will be closed and a FIN packet will be sent. +// - `both`: Same effect as `receive` & `send` combined. +// +// This function is idempotent. Shutting a down a direction more than once +// has no effect and returns `ok`. +// +// The shutdown function does not close (drop) the socket. +// +// # Typical errors +// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) +// +// # References +// - +// - +// - +// - +extern bool tcp_method_tcp_socket_shutdown(tcp_borrow_tcp_socket_t self, tcp_shutdown_type_t shutdown_type, tcp_error_code_t *err); + +// Imported Functions from `wasi:sockets/tcp-create-socket@0.2.0` +// Create a new TCP socket. +// +// Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. +// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. +// +// This function does not require a network capability handle. This is considered to be safe because +// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`connect` +// is called, the socket is effectively an in-memory configuration object, unable to communicate with the outside world. +// +// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. +// +// # Typical errors +// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) +// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) +// +// # References +// - +// - +// - +// - +extern bool tcp_create_socket_create_tcp_socket(tcp_create_socket_ip_address_family_t address_family, tcp_create_socket_own_tcp_socket_t *ret, tcp_create_socket_error_code_t *err); + +// Imported Functions from `wasi:sockets/ip-name-lookup@0.2.0` +// Resolve an internet host name to a list of IP addresses. +// +// Unicode domain names are automatically converted to ASCII using IDNA encoding. +// If the input is an IP address string, the address is parsed and returned +// as-is without making any external requests. +// +// See the wasi-socket proposal README.md for a comparison with getaddrinfo. +// +// This function never blocks. It either immediately fails or immediately +// returns successfully with a `resolve-address-stream` that can be used +// to (asynchronously) fetch the results. +// +// # Typical errors +// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. +// +// # References: +// - +// - +// - +// - +extern bool ip_name_lookup_resolve_addresses(ip_name_lookup_borrow_network_t network, wasip2_string_t *name, ip_name_lookup_own_resolve_address_stream_t *ret, ip_name_lookup_error_code_t *err); +// Returns the next address from the resolver. +// +// This function should be called multiple times. On each call, it will +// return the next address in connection order preference. If all +// addresses have been exhausted, this function returns `none`. +// +// This function never returns IPv4-mapped IPv6 addresses. +// +// # Typical errors +// - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) +// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN) +// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL) +// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) +extern bool ip_name_lookup_method_resolve_address_stream_resolve_next_address(ip_name_lookup_borrow_resolve_address_stream_t self, ip_name_lookup_option_ip_address_t *ret, ip_name_lookup_error_code_t *err); +// Create a `pollable` which will resolve once the stream is ready for I/O. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. +extern ip_name_lookup_own_pollable_t ip_name_lookup_method_resolve_address_stream_subscribe(ip_name_lookup_borrow_resolve_address_stream_t self); + +// Imported Functions from `wasi:random/random@0.2.0` +// Return `len` cryptographically-secure random or pseudo-random bytes. +// +// This function must produce data at least as cryptographically secure and +// fast as an adequately seeded cryptographically-secure pseudo-random +// number generator (CSPRNG). It must not block, from the perspective of +// the calling program, under any circumstances, including on the first +// request and on requests for numbers of bytes. The returned data must +// always be unpredictable. +// +// This function must always return fresh data. Deterministic environments +// must omit this function, rather than implementing it with deterministic +// data. +extern void random_get_random_bytes(uint64_t len, wasip2_list_u8_t *ret); +// Return a cryptographically-secure random or pseudo-random `u64` value. +// +// This function returns the same type of data as `get-random-bytes`, +// represented as a `u64`. +extern uint64_t random_get_random_u64(void); + +// Imported Functions from `wasi:random/insecure@0.2.0` +// Return `len` insecure pseudo-random bytes. +// +// This function is not cryptographically secure. Do not use it for +// anything related to security. +// +// There are no requirements on the values of the returned bytes, however +// implementations are encouraged to return evenly distributed values with +// a long period. +extern void random_insecure_get_insecure_random_bytes(uint64_t len, wasip2_list_u8_t *ret); +// Return an insecure pseudo-random `u64` value. +// +// This function returns the same type of pseudo-random data as +// `get-insecure-random-bytes`, represented as a `u64`. +extern uint64_t random_insecure_get_insecure_random_u64(void); + +// Imported Functions from `wasi:random/insecure-seed@0.2.0` +// Return a 128-bit value that may contain a pseudo-random value. +// +// The returned value is not required to be computed from a CSPRNG, and may +// even be entirely deterministic. Host implementations are encouraged to +// provide pseudo-random values to any program exposed to +// attacker-controlled content, to enable DoS protection built into many +// languages' hash-map implementations. +// +// This function is intended to only be called once, by a source language +// to initialize Denial Of Service (DoS) protection in its hash-map +// implementation. +// +// # Expected future evolution +// +// This will likely be changed to a value import, to prevent it from being +// called multiple times and potentially used for purposes other than DoS +// protection. +extern void random_insecure_seed_insecure_seed(wasip2_tuple2_u64_u64_t *ret); + +// Helper Functions + +void wasip2_tuple2_string_string_free(wasip2_tuple2_string_string_t *ptr); + +void wasip2_list_tuple2_string_string_free(wasip2_list_tuple2_string_string_t *ptr); + +void wasip2_list_string_free(wasip2_list_string_t *ptr); + +void wasip2_option_string_free(wasip2_option_string_t *ptr); + +void exit_result_void_void_free(exit_result_void_void_t *ptr); + +extern void io_error_error_drop_own(io_error_own_error_t handle); + +extern io_error_borrow_error_t io_error_borrow_error(io_error_own_error_t handle); + +extern void poll_pollable_drop_own(poll_own_pollable_t handle); + +extern poll_borrow_pollable_t poll_borrow_pollable(poll_own_pollable_t handle); + +void poll_list_borrow_pollable_free(poll_list_borrow_pollable_t *ptr); + +void wasip2_list_u32_free(wasip2_list_u32_t *ptr); + +void streams_stream_error_free(streams_stream_error_t *ptr); + +extern void streams_input_stream_drop_own(streams_own_input_stream_t handle); + +extern streams_borrow_input_stream_t streams_borrow_input_stream(streams_own_input_stream_t handle); + +extern void streams_output_stream_drop_own(streams_own_output_stream_t handle); + +extern streams_borrow_output_stream_t streams_borrow_output_stream(streams_own_output_stream_t handle); + +void wasip2_list_u8_free(wasip2_list_u8_t *ptr); + +void streams_result_list_u8_stream_error_free(streams_result_list_u8_stream_error_t *ptr); + +void streams_result_u64_stream_error_free(streams_result_u64_stream_error_t *ptr); + +void streams_result_void_stream_error_free(streams_result_void_stream_error_t *ptr); + +extern void terminal_input_terminal_input_drop_own(terminal_input_own_terminal_input_t handle); + +extern terminal_input_borrow_terminal_input_t terminal_input_borrow_terminal_input(terminal_input_own_terminal_input_t handle); + +extern void terminal_output_terminal_output_drop_own(terminal_output_own_terminal_output_t handle); + +extern terminal_output_borrow_terminal_output_t terminal_output_borrow_terminal_output(terminal_output_own_terminal_output_t handle); + +void terminal_stdin_option_own_terminal_input_free(terminal_stdin_option_own_terminal_input_t *ptr); + +void terminal_stdout_option_own_terminal_output_free(terminal_stdout_option_own_terminal_output_t *ptr); + +void terminal_stderr_option_own_terminal_output_free(terminal_stderr_option_own_terminal_output_t *ptr); + +void filesystem_option_datetime_free(filesystem_option_datetime_t *ptr); + +void filesystem_descriptor_stat_free(filesystem_descriptor_stat_t *ptr); + +void filesystem_new_timestamp_free(filesystem_new_timestamp_t *ptr); + +void filesystem_directory_entry_free(filesystem_directory_entry_t *ptr); + +extern void filesystem_descriptor_drop_own(filesystem_own_descriptor_t handle); + +extern filesystem_borrow_descriptor_t filesystem_borrow_descriptor(filesystem_own_descriptor_t handle); + +extern void filesystem_directory_entry_stream_drop_own(filesystem_own_directory_entry_stream_t handle); + +extern filesystem_borrow_directory_entry_stream_t filesystem_borrow_directory_entry_stream(filesystem_own_directory_entry_stream_t handle); + +void filesystem_result_own_input_stream_error_code_free(filesystem_result_own_input_stream_error_code_t *ptr); + +void filesystem_result_own_output_stream_error_code_free(filesystem_result_own_output_stream_error_code_t *ptr); + +void filesystem_result_void_error_code_free(filesystem_result_void_error_code_t *ptr); + +void filesystem_result_descriptor_flags_error_code_free(filesystem_result_descriptor_flags_error_code_t *ptr); + +void filesystem_result_descriptor_type_error_code_free(filesystem_result_descriptor_type_error_code_t *ptr); + +void filesystem_result_tuple2_list_u8_bool_error_code_free(filesystem_result_tuple2_list_u8_bool_error_code_t *ptr); + +void filesystem_result_filesize_error_code_free(filesystem_result_filesize_error_code_t *ptr); + +void filesystem_result_own_directory_entry_stream_error_code_free(filesystem_result_own_directory_entry_stream_error_code_t *ptr); + +void filesystem_result_descriptor_stat_error_code_free(filesystem_result_descriptor_stat_error_code_t *ptr); + +void filesystem_result_own_descriptor_error_code_free(filesystem_result_own_descriptor_error_code_t *ptr); + +void filesystem_result_string_error_code_free(filesystem_result_string_error_code_t *ptr); + +void filesystem_result_metadata_hash_value_error_code_free(filesystem_result_metadata_hash_value_error_code_t *ptr); + +void filesystem_option_directory_entry_free(filesystem_option_directory_entry_t *ptr); + +void filesystem_result_option_directory_entry_error_code_free(filesystem_result_option_directory_entry_error_code_t *ptr); + +void filesystem_option_error_code_free(filesystem_option_error_code_t *ptr); + +void filesystem_preopens_tuple2_own_descriptor_string_free(filesystem_preopens_tuple2_own_descriptor_string_t *ptr); + +void filesystem_preopens_list_tuple2_own_descriptor_string_free(filesystem_preopens_list_tuple2_own_descriptor_string_t *ptr); + +extern void network_network_drop_own(network_own_network_t handle); + +extern network_borrow_network_t network_borrow_network(network_own_network_t handle); + +void network_ip_address_free(network_ip_address_t *ptr); + +void network_ip_socket_address_free(network_ip_socket_address_t *ptr); + +void udp_ip_socket_address_free(udp_ip_socket_address_t *ptr); + +void udp_incoming_datagram_free(udp_incoming_datagram_t *ptr); + +void udp_option_ip_socket_address_free(udp_option_ip_socket_address_t *ptr); + +void udp_outgoing_datagram_free(udp_outgoing_datagram_t *ptr); + +extern void udp_udp_socket_drop_own(udp_own_udp_socket_t handle); + +extern udp_borrow_udp_socket_t udp_borrow_udp_socket(udp_own_udp_socket_t handle); + +extern void udp_incoming_datagram_stream_drop_own(udp_own_incoming_datagram_stream_t handle); + +extern udp_borrow_incoming_datagram_stream_t udp_borrow_incoming_datagram_stream(udp_own_incoming_datagram_stream_t handle); + +extern void udp_outgoing_datagram_stream_drop_own(udp_own_outgoing_datagram_stream_t handle); + +extern udp_borrow_outgoing_datagram_stream_t udp_borrow_outgoing_datagram_stream(udp_own_outgoing_datagram_stream_t handle); + +void udp_result_void_error_code_free(udp_result_void_error_code_t *ptr); + +void udp_result_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_error_code_free(udp_result_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_error_code_t *ptr); + +void udp_result_ip_socket_address_error_code_free(udp_result_ip_socket_address_error_code_t *ptr); + +void udp_result_u8_error_code_free(udp_result_u8_error_code_t *ptr); + +void udp_result_u64_error_code_free(udp_result_u64_error_code_t *ptr); + +void udp_list_incoming_datagram_free(udp_list_incoming_datagram_t *ptr); + +void udp_result_list_incoming_datagram_error_code_free(udp_result_list_incoming_datagram_error_code_t *ptr); + +void udp_list_outgoing_datagram_free(udp_list_outgoing_datagram_t *ptr); + +void udp_create_socket_result_own_udp_socket_error_code_free(udp_create_socket_result_own_udp_socket_error_code_t *ptr); + +void tcp_ip_socket_address_free(tcp_ip_socket_address_t *ptr); + +extern void tcp_tcp_socket_drop_own(tcp_own_tcp_socket_t handle); + +extern tcp_borrow_tcp_socket_t tcp_borrow_tcp_socket(tcp_own_tcp_socket_t handle); + +void tcp_result_void_error_code_free(tcp_result_void_error_code_t *ptr); + +void tcp_result_tuple2_own_input_stream_own_output_stream_error_code_free(tcp_result_tuple2_own_input_stream_own_output_stream_error_code_t *ptr); + +void tcp_result_tuple3_own_tcp_socket_own_input_stream_own_output_stream_error_code_free(tcp_result_tuple3_own_tcp_socket_own_input_stream_own_output_stream_error_code_t *ptr); + +void tcp_result_ip_socket_address_error_code_free(tcp_result_ip_socket_address_error_code_t *ptr); + +void tcp_result_bool_error_code_free(tcp_result_bool_error_code_t *ptr); + +void tcp_result_duration_error_code_free(tcp_result_duration_error_code_t *ptr); + +void tcp_result_u32_error_code_free(tcp_result_u32_error_code_t *ptr); + +void tcp_result_u8_error_code_free(tcp_result_u8_error_code_t *ptr); + +void tcp_result_u64_error_code_free(tcp_result_u64_error_code_t *ptr); + +void tcp_create_socket_result_own_tcp_socket_error_code_free(tcp_create_socket_result_own_tcp_socket_error_code_t *ptr); + +void ip_name_lookup_ip_address_free(ip_name_lookup_ip_address_t *ptr); + +extern void ip_name_lookup_resolve_address_stream_drop_own(ip_name_lookup_own_resolve_address_stream_t handle); + +extern ip_name_lookup_borrow_resolve_address_stream_t ip_name_lookup_borrow_resolve_address_stream(ip_name_lookup_own_resolve_address_stream_t handle); + +void ip_name_lookup_result_own_resolve_address_stream_error_code_free(ip_name_lookup_result_own_resolve_address_stream_error_code_t *ptr); + +void ip_name_lookup_option_ip_address_free(ip_name_lookup_option_ip_address_t *ptr); + +void ip_name_lookup_result_option_ip_address_error_code_free(ip_name_lookup_result_option_ip_address_error_code_t *ptr); + +// Sets the string `ret` to reference the input string `s` without copying it +void wasip2_string_set(wasip2_string_t *ret, const char*s); + +// Creates a copy of the input nul-terminated string `s` and +// stores it into the component model string `ret`. +void wasip2_string_dup(wasip2_string_t *ret, const char*s); + +// Deallocates the string pointed to by `ret`, deallocating +// the memory behind the string. +void wasip2_string_free(wasip2_string_t *ret); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h new file mode 100644 index 000000000..8618192ab --- /dev/null +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h @@ -0,0 +1,2031 @@ +// Generated by `wit-bindgen` 0.48.0. DO NOT EDIT! +#ifndef __BINDINGS_WASIP3_H +#define __BINDINGS_WASIP3_H +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +typedef struct wasip3_string_t { + uint8_t*ptr; + size_t len; +} wasip3_string_t; + +// Async Helper Functions + +typedef uint32_t wasip3_subtask_status_t; +typedef uint32_t wasip3_subtask_t; +#define WASIP3_SUBTASK_STATE(status) ((wasip3_subtask_state_t) ((status) & 0xf)) +#define WASIP3_SUBTASK_HANDLE(status) ((wasip3_subtask_t) ((status) >> 4)) + +typedef enum wasip3_subtask_state { + WASIP3_SUBTASK_STARTING, + WASIP3_SUBTASK_STARTED, + WASIP3_SUBTASK_RETURNED, + WASIP3_SUBTASK_STARTED_CANCELLED, + WASIP3_SUBTASK_RETURNED_CANCELLED, +} wasip3_subtask_state_t; + +wasip3_subtask_status_t wasip3_subtask_cancel(wasip3_subtask_t subtask); +void wasip3_subtask_drop(wasip3_subtask_t subtask); + +typedef uint32_t wasip3_callback_code_t; +#define WASIP3_CALLBACK_CODE_EXIT 0 +#define WASIP3_CALLBACK_CODE_YIELD 1 +#define WASIP3_CALLBACK_CODE_WAIT(set) (2 | (set << 4)) +#define WASIP3_CALLBACK_CODE_POLL(set) (3 | (set << 4)) + +typedef enum wasip3_event_code { + WASIP3_EVENT_NONE, + WASIP3_EVENT_SUBTASK, + WASIP3_EVENT_STREAM_READ, + WASIP3_EVENT_STREAM_WRITE, + WASIP3_EVENT_FUTURE_READ, + WASIP3_EVENT_FUTURE_WRITE, + WASIP3_EVENT_CANCEL, +} wasip3_event_code_t; + +typedef struct wasip3_event { + wasip3_event_code_t event; + uint32_t waitable; + uint32_t code; +} wasip3_event_t; + +typedef uint32_t wasip3_waitable_set_t; +wasip3_waitable_set_t wasip3_waitable_set_new(void); +void wasip3_waitable_join(uint32_t waitable, wasip3_waitable_set_t set); +void wasip3_waitable_set_drop(wasip3_waitable_set_t set); +void wasip3_waitable_set_wait(wasip3_waitable_set_t set, wasip3_event_t *event); +void wasip3_waitable_set_poll(wasip3_waitable_set_t set, wasip3_event_t *event); + +void wasip3_task_cancel(void); + +typedef uint32_t wasip3_waitable_status_t; +#define WASIP3_WAITABLE_STATE(status) ((wasip3_waitable_state_t) ((status) & 0xf)) +#define WASIP3_WAITABLE_COUNT(status) ((uint32_t) ((status) >> 4)) +#define WASIP3_WAITABLE_STATUS_BLOCKED ((wasip3_waitable_status_t) -1) + +typedef enum wasip3_waitable_state { + WASIP3_WAITABLE_COMPLETED, + WASIP3_WAITABLE_DROPPED, + WASIP3_WAITABLE_CANCELLED, +} wasip3_waitable_state_t; + +void wasip3_backpressure_set(bool enable); +void wasip3_backpressure_inc(void); +void wasip3_backpressure_dec(void); +void* wasip3_context_get(void); +void wasip3_context_set(void*); +void wasip3_yield(void); +uint32_t wasip3_yield_cancellable(void); + + + +typedef struct { + wasip3_string_t f0; + wasip3_string_t f1; +} wasip3_tuple2_string_string_t; + +typedef struct { + wasip3_tuple2_string_string_t *ptr; + size_t len; +} wasip3_list_tuple2_string_string_t; + +typedef struct { + wasip3_string_t *ptr; + size_t len; +} wasip3_list_string_t; + +typedef struct { + bool is_some; + wasip3_string_t val; +} wasip3_option_string_t; + +typedef struct { + bool is_err; +} exit_result_void_void_t; + +typedef uint8_t wasi_cli_types_error_code_t; + +// Input/output error +#define WASI_CLI_TYPES_ERROR_CODE_IO 0 +// Invalid or incomplete multibyte or wide character +#define WASI_CLI_TYPES_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE 1 +// Broken pipe +#define WASI_CLI_TYPES_ERROR_CODE_PIPE 2 + +typedef wasi_cli_types_error_code_t stdin_error_code_t; + +typedef uint32_t stdin_stream_u8_t; + +typedef struct { + bool is_err; + union { + stdin_error_code_t err; + } val; +} stdin_result_void_error_code_t; + +typedef uint32_t stdin_future_result_void_error_code_t; + +typedef struct { + stdin_stream_u8_t f0; + stdin_future_result_void_error_code_t f1; +} stdin_tuple2_stream_u8_future_result_void_error_code_t; + +typedef wasi_cli_types_error_code_t stdout_error_code_t; + +typedef struct { + bool is_err; + union { + stdout_error_code_t err; + } val; +} stdout_result_void_error_code_t; + +typedef wasi_cli_types_error_code_t stderr_error_code_t; + +typedef struct { + bool is_err; + union { + stderr_error_code_t err; + } val; +} stderr_result_void_error_code_t; + +typedef struct terminal_input_own_terminal_input_t { + int32_t __handle; +} terminal_input_own_terminal_input_t; + +typedef struct terminal_input_borrow_terminal_input_t { + int32_t __handle; +} terminal_input_borrow_terminal_input_t; + +typedef struct terminal_output_own_terminal_output_t { + int32_t __handle; +} terminal_output_own_terminal_output_t; + +typedef struct terminal_output_borrow_terminal_output_t { + int32_t __handle; +} terminal_output_borrow_terminal_output_t; + +typedef terminal_input_own_terminal_input_t terminal_stdin_own_terminal_input_t; + +typedef struct { + bool is_some; + terminal_stdin_own_terminal_input_t val; +} terminal_stdin_option_own_terminal_input_t; + +typedef terminal_output_own_terminal_output_t terminal_stdout_own_terminal_output_t; + +typedef struct { + bool is_some; + terminal_stdout_own_terminal_output_t val; +} terminal_stdout_option_own_terminal_output_t; + +typedef terminal_output_own_terminal_output_t terminal_stderr_own_terminal_output_t; + +typedef struct { + bool is_some; + terminal_stderr_own_terminal_output_t val; +} terminal_stderr_option_own_terminal_output_t; + +// A duration of time, in nanoseconds. +typedef uint64_t wasi_clocks_types_duration_t; + +typedef wasi_clocks_types_duration_t monotonic_clock_duration_t; + +// An instant in time, in nanoseconds. An instant is relative to an +// unspecified initial value, and can only be compared to instances from +// the same monotonic-clock. +typedef uint64_t monotonic_clock_instant_t; + +// A time and date in seconds plus nanoseconds. +typedef struct wall_clock_datetime_t { + uint64_t seconds; + uint32_t nanoseconds; +} wall_clock_datetime_t; + +typedef wall_clock_datetime_t filesystem_datetime_t; + +// File size or length of a region within a file. +typedef uint64_t filesystem_filesize_t; + +// The type of a filesystem object referenced by a descriptor. +// +// Note: This was called `filetype` in earlier versions of WASI. +typedef uint8_t filesystem_descriptor_type_t; + +// The type of the descriptor or file is unknown or is different from +// any of the other types specified. +#define FILESYSTEM_DESCRIPTOR_TYPE_UNKNOWN 0 +// The descriptor refers to a block device inode. +#define FILESYSTEM_DESCRIPTOR_TYPE_BLOCK_DEVICE 1 +// The descriptor refers to a character device inode. +#define FILESYSTEM_DESCRIPTOR_TYPE_CHARACTER_DEVICE 2 +// The descriptor refers to a directory inode. +#define FILESYSTEM_DESCRIPTOR_TYPE_DIRECTORY 3 +// The descriptor refers to a named pipe. +#define FILESYSTEM_DESCRIPTOR_TYPE_FIFO 4 +// The file refers to a symbolic link inode. +#define FILESYSTEM_DESCRIPTOR_TYPE_SYMBOLIC_LINK 5 +// The descriptor refers to a regular file inode. +#define FILESYSTEM_DESCRIPTOR_TYPE_REGULAR_FILE 6 +// The descriptor refers to a socket. +#define FILESYSTEM_DESCRIPTOR_TYPE_SOCKET 7 + +// Descriptor flags. +// +// Note: This was called `fdflags` in earlier versions of WASI. +typedef uint8_t filesystem_descriptor_flags_t; + +// Read mode: Data can be read. +#define FILESYSTEM_DESCRIPTOR_FLAGS_READ (1 << 0) +// Write mode: Data can be written to. +#define FILESYSTEM_DESCRIPTOR_FLAGS_WRITE (1 << 1) +// Request that writes be performed according to synchronized I/O file +// integrity completion. The data stored in the file and the file's +// metadata are synchronized. This is similar to `O_SYNC` in POSIX. +// +// The precise semantics of this operation have not yet been defined for +// WASI. At this time, it should be interpreted as a request, and not a +// requirement. +#define FILESYSTEM_DESCRIPTOR_FLAGS_FILE_INTEGRITY_SYNC (1 << 2) +// Request that writes be performed according to synchronized I/O data +// integrity completion. Only the data stored in the file is +// synchronized. This is similar to `O_DSYNC` in POSIX. +// +// The precise semantics of this operation have not yet been defined for +// WASI. At this time, it should be interpreted as a request, and not a +// requirement. +#define FILESYSTEM_DESCRIPTOR_FLAGS_DATA_INTEGRITY_SYNC (1 << 3) +// Requests that reads be performed at the same level of integrity +// requested for writes. This is similar to `O_RSYNC` in POSIX. +// +// The precise semantics of this operation have not yet been defined for +// WASI. At this time, it should be interpreted as a request, and not a +// requirement. +#define FILESYSTEM_DESCRIPTOR_FLAGS_REQUESTED_WRITE_SYNC (1 << 4) +// Mutating directories mode: Directory contents may be mutated. +// +// When this flag is unset on a descriptor, operations using the +// descriptor which would create, rename, delete, modify the data or +// metadata of filesystem objects, or obtain another handle which +// would permit any of those, shall fail with `error-code::read-only` if +// they would otherwise succeed. +// +// This may only be set on directories. +#define FILESYSTEM_DESCRIPTOR_FLAGS_MUTATE_DIRECTORY (1 << 5) + +// Flags determining the method of how paths are resolved. +typedef uint8_t filesystem_path_flags_t; + +// As long as the resolved path corresponds to a symbolic link, it is +// expanded. +#define FILESYSTEM_PATH_FLAGS_SYMLINK_FOLLOW (1 << 0) + +// Open flags used by `open-at`. +typedef uint8_t filesystem_open_flags_t; + +// Create file if it does not exist, similar to `O_CREAT` in POSIX. +#define FILESYSTEM_OPEN_FLAGS_CREATE (1 << 0) +// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. +#define FILESYSTEM_OPEN_FLAGS_DIRECTORY (1 << 1) +// Fail if file already exists, similar to `O_EXCL` in POSIX. +#define FILESYSTEM_OPEN_FLAGS_EXCLUSIVE (1 << 2) +// Truncate file to size 0, similar to `O_TRUNC` in POSIX. +#define FILESYSTEM_OPEN_FLAGS_TRUNCATE (1 << 3) + +// Number of hard links to an inode. +typedef uint64_t filesystem_link_count_t; + +typedef struct { + bool is_some; + filesystem_datetime_t val; +} filesystem_option_datetime_t; + +// File attributes. +// +// Note: This was called `filestat` in earlier versions of WASI. +typedef struct filesystem_descriptor_stat_t { + // File type. + filesystem_descriptor_type_t type; + // Number of hard links to the file. + filesystem_link_count_t link_count; + // For regular files, the file size in bytes. For symbolic links, the + // length in bytes of the pathname contained in the symbolic link. + filesystem_filesize_t size; + // Last data access timestamp. + // + // If the `option` is none, the platform doesn't maintain an access + // timestamp for this file. + filesystem_option_datetime_t data_access_timestamp; + // Last data modification timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // modification timestamp for this file. + filesystem_option_datetime_t data_modification_timestamp; + // Last file status-change timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // status-change timestamp for this file. + filesystem_option_datetime_t status_change_timestamp; +} filesystem_descriptor_stat_t; + +// When setting a timestamp, this gives the value to set it to. +typedef struct filesystem_new_timestamp_t { + uint8_t tag; + union { + filesystem_datetime_t timestamp; + } val; +} filesystem_new_timestamp_t; + +// Leave the timestamp set to its previous value. +#define FILESYSTEM_NEW_TIMESTAMP_NO_CHANGE 0 +// Set the timestamp to the current time of the system clock associated +// with the filesystem. +#define FILESYSTEM_NEW_TIMESTAMP_NOW 1 +// Set the timestamp to the given value. +#define FILESYSTEM_NEW_TIMESTAMP_TIMESTAMP 2 + +// A directory entry. +typedef struct filesystem_directory_entry_t { + // The type of the file referred to by this directory entry. + filesystem_descriptor_type_t type; + // The name of the object. + wasip3_string_t name; +} filesystem_directory_entry_t; + +// Error codes returned by functions, similar to `errno` in POSIX. +// Not all of these error codes are returned by the functions provided by this +// API; some are used in higher-level library layers, and others are provided +// merely for alignment with POSIX. +typedef uint8_t filesystem_error_code_t; + +// Permission denied, similar to `EACCES` in POSIX. +#define FILESYSTEM_ERROR_CODE_ACCESS 0 +// Connection already in progress, similar to `EALREADY` in POSIX. +#define FILESYSTEM_ERROR_CODE_ALREADY 1 +// Bad descriptor, similar to `EBADF` in POSIX. +#define FILESYSTEM_ERROR_CODE_BAD_DESCRIPTOR 2 +// Device or resource busy, similar to `EBUSY` in POSIX. +#define FILESYSTEM_ERROR_CODE_BUSY 3 +// Resource deadlock would occur, similar to `EDEADLK` in POSIX. +#define FILESYSTEM_ERROR_CODE_DEADLOCK 4 +// Storage quota exceeded, similar to `EDQUOT` in POSIX. +#define FILESYSTEM_ERROR_CODE_QUOTA 5 +// File exists, similar to `EEXIST` in POSIX. +#define FILESYSTEM_ERROR_CODE_EXIST 6 +// File too large, similar to `EFBIG` in POSIX. +#define FILESYSTEM_ERROR_CODE_FILE_TOO_LARGE 7 +// Illegal byte sequence, similar to `EILSEQ` in POSIX. +#define FILESYSTEM_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE 8 +// Operation in progress, similar to `EINPROGRESS` in POSIX. +#define FILESYSTEM_ERROR_CODE_IN_PROGRESS 9 +// Interrupted function, similar to `EINTR` in POSIX. +#define FILESYSTEM_ERROR_CODE_INTERRUPTED 10 +// Invalid argument, similar to `EINVAL` in POSIX. +#define FILESYSTEM_ERROR_CODE_INVALID 11 +// I/O error, similar to `EIO` in POSIX. +#define FILESYSTEM_ERROR_CODE_IO 12 +// Is a directory, similar to `EISDIR` in POSIX. +#define FILESYSTEM_ERROR_CODE_IS_DIRECTORY 13 +// Too many levels of symbolic links, similar to `ELOOP` in POSIX. +#define FILESYSTEM_ERROR_CODE_LOOP 14 +// Too many links, similar to `EMLINK` in POSIX. +#define FILESYSTEM_ERROR_CODE_TOO_MANY_LINKS 15 +// Message too large, similar to `EMSGSIZE` in POSIX. +#define FILESYSTEM_ERROR_CODE_MESSAGE_SIZE 16 +// Filename too long, similar to `ENAMETOOLONG` in POSIX. +#define FILESYSTEM_ERROR_CODE_NAME_TOO_LONG 17 +// No such device, similar to `ENODEV` in POSIX. +#define FILESYSTEM_ERROR_CODE_NO_DEVICE 18 +// No such file or directory, similar to `ENOENT` in POSIX. +#define FILESYSTEM_ERROR_CODE_NO_ENTRY 19 +// No locks available, similar to `ENOLCK` in POSIX. +#define FILESYSTEM_ERROR_CODE_NO_LOCK 20 +// Not enough space, similar to `ENOMEM` in POSIX. +#define FILESYSTEM_ERROR_CODE_INSUFFICIENT_MEMORY 21 +// No space left on device, similar to `ENOSPC` in POSIX. +#define FILESYSTEM_ERROR_CODE_INSUFFICIENT_SPACE 22 +// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. +#define FILESYSTEM_ERROR_CODE_NOT_DIRECTORY 23 +// Directory not empty, similar to `ENOTEMPTY` in POSIX. +#define FILESYSTEM_ERROR_CODE_NOT_EMPTY 24 +// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. +#define FILESYSTEM_ERROR_CODE_NOT_RECOVERABLE 25 +// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. +#define FILESYSTEM_ERROR_CODE_UNSUPPORTED 26 +// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. +#define FILESYSTEM_ERROR_CODE_NO_TTY 27 +// No such device or address, similar to `ENXIO` in POSIX. +#define FILESYSTEM_ERROR_CODE_NO_SUCH_DEVICE 28 +// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. +#define FILESYSTEM_ERROR_CODE_OVERFLOW 29 +// Operation not permitted, similar to `EPERM` in POSIX. +#define FILESYSTEM_ERROR_CODE_NOT_PERMITTED 30 +// Broken pipe, similar to `EPIPE` in POSIX. +#define FILESYSTEM_ERROR_CODE_PIPE 31 +// Read-only file system, similar to `EROFS` in POSIX. +#define FILESYSTEM_ERROR_CODE_READ_ONLY 32 +// Invalid seek, similar to `ESPIPE` in POSIX. +#define FILESYSTEM_ERROR_CODE_INVALID_SEEK 33 +// Text file busy, similar to `ETXTBSY` in POSIX. +#define FILESYSTEM_ERROR_CODE_TEXT_FILE_BUSY 34 +// Cross-device link, similar to `EXDEV` in POSIX. +#define FILESYSTEM_ERROR_CODE_CROSS_DEVICE 35 + +// File or memory access pattern advisory information. +typedef uint8_t filesystem_advice_t; + +// The application has no advice to give on its behavior with respect +// to the specified data. +#define FILESYSTEM_ADVICE_NORMAL 0 +// The application expects to access the specified data sequentially +// from lower offsets to higher offsets. +#define FILESYSTEM_ADVICE_SEQUENTIAL 1 +// The application expects to access the specified data in a random +// order. +#define FILESYSTEM_ADVICE_RANDOM 2 +// The application expects to access the specified data in the near +// future. +#define FILESYSTEM_ADVICE_WILL_NEED 3 +// The application expects that it will not access the specified data +// in the near future. +#define FILESYSTEM_ADVICE_DONT_NEED 4 +// The application expects to access the specified data once and then +// not reuse it thereafter. +#define FILESYSTEM_ADVICE_NO_REUSE 5 + +// A 128-bit hash value, split into parts because wasm doesn't have a +// 128-bit integer type. +typedef struct filesystem_metadata_hash_value_t { + // 64 bits of a 128-bit hash value. + uint64_t lower; + // Another 64 bits of a 128-bit hash value. + uint64_t upper; +} filesystem_metadata_hash_value_t; + +typedef struct filesystem_own_descriptor_t { + int32_t __handle; +} filesystem_own_descriptor_t; + +typedef struct filesystem_borrow_descriptor_t { + int32_t __handle; +} filesystem_borrow_descriptor_t; + +typedef uint32_t filesystem_stream_u8_t; + +typedef struct { + bool is_err; + union { + filesystem_error_code_t err; + } val; +} filesystem_result_void_error_code_t; + +typedef uint32_t filesystem_future_result_void_error_code_t; + +typedef struct { + filesystem_stream_u8_t f0; + filesystem_future_result_void_error_code_t f1; +} filesystem_tuple2_stream_u8_future_result_void_error_code_t; + +typedef struct { + bool is_err; + union { + filesystem_descriptor_flags_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_descriptor_flags_error_code_t; + +typedef struct { + bool is_err; + union { + filesystem_descriptor_type_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_descriptor_type_error_code_t; + +typedef uint32_t filesystem_stream_directory_entry_t; + +typedef struct { + filesystem_stream_directory_entry_t f0; + filesystem_future_result_void_error_code_t f1; +} filesystem_tuple2_stream_directory_entry_future_result_void_error_code_t; + +typedef struct { + bool is_err; + union { + filesystem_descriptor_stat_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_descriptor_stat_error_code_t; + +typedef struct { + bool is_err; + union { + filesystem_own_descriptor_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_own_descriptor_error_code_t; + +typedef struct { + bool is_err; + union { + wasip3_string_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_string_error_code_t; + +typedef struct { + bool is_err; + union { + filesystem_metadata_hash_value_t ok; + filesystem_error_code_t err; + } val; +} filesystem_result_metadata_hash_value_error_code_t; +typedef struct filesystem_method_descriptor_set_times_args { + filesystem_borrow_descriptor_t self; + filesystem_new_timestamp_t data_access_timestamp; + filesystem_new_timestamp_t data_modification_timestamp; +} filesystem_method_descriptor_set_times_args_t; +typedef struct filesystem_method_descriptor_set_times_at_args { + filesystem_borrow_descriptor_t self; + filesystem_path_flags_t path_flags; + wasip3_string_t path; + filesystem_new_timestamp_t data_access_timestamp; + filesystem_new_timestamp_t data_modification_timestamp; +} filesystem_method_descriptor_set_times_at_args_t; +typedef struct filesystem_method_descriptor_link_at_args { + filesystem_borrow_descriptor_t self; + filesystem_path_flags_t old_path_flags; + wasip3_string_t old_path; + filesystem_borrow_descriptor_t new_descriptor; + wasip3_string_t new_path; +} filesystem_method_descriptor_link_at_args_t; +typedef struct filesystem_method_descriptor_open_at_args { + filesystem_borrow_descriptor_t self; + filesystem_path_flags_t path_flags; + wasip3_string_t path; + filesystem_open_flags_t open_flags; + filesystem_descriptor_flags_t flags; +} filesystem_method_descriptor_open_at_args_t; +typedef struct filesystem_method_descriptor_rename_at_args { + filesystem_borrow_descriptor_t self; + wasip3_string_t old_path; + filesystem_borrow_descriptor_t new_descriptor; + wasip3_string_t new_path; +} filesystem_method_descriptor_rename_at_args_t; +typedef struct filesystem_method_descriptor_symlink_at_args { + filesystem_borrow_descriptor_t self; + wasip3_string_t old_path; + wasip3_string_t new_path; +} filesystem_method_descriptor_symlink_at_args_t; + +typedef filesystem_own_descriptor_t filesystem_preopens_own_descriptor_t; + +typedef struct { + filesystem_preopens_own_descriptor_t f0; + wasip3_string_t f1; +} filesystem_preopens_tuple2_own_descriptor_string_t; + +typedef struct { + filesystem_preopens_tuple2_own_descriptor_string_t *ptr; + size_t len; +} filesystem_preopens_list_tuple2_own_descriptor_string_t; + +typedef monotonic_clock_duration_t sockets_duration_t; + +// Error codes. +// +// In theory, every API can return any error code. +// In practice, API's typically only return the errors documented per API +// combined with a couple of errors that are always possible: +// - `unknown` +// - `access-denied` +// - `not-supported` +// - `out-of-memory` +// +// See each individual API for what the POSIX equivalents are. They sometimes differ per API. +typedef uint8_t sockets_error_code_t; + +// Unknown error +#define SOCKETS_ERROR_CODE_UNKNOWN 0 +// Access denied. +// +// POSIX equivalent: EACCES, EPERM +#define SOCKETS_ERROR_CODE_ACCESS_DENIED 1 +// The operation is not supported. +// +// POSIX equivalent: EOPNOTSUPP +#define SOCKETS_ERROR_CODE_NOT_SUPPORTED 2 +// One of the arguments is invalid. +// +// POSIX equivalent: EINVAL +#define SOCKETS_ERROR_CODE_INVALID_ARGUMENT 3 +// Not enough memory to complete the operation. +// +// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY +#define SOCKETS_ERROR_CODE_OUT_OF_MEMORY 4 +// The operation timed out before it could finish completely. +#define SOCKETS_ERROR_CODE_TIMEOUT 5 +// The operation is not valid in the socket's current state. +#define SOCKETS_ERROR_CODE_INVALID_STATE 6 +// A bind operation failed because the provided address is not an address that the `network` can bind to. +#define SOCKETS_ERROR_CODE_ADDRESS_NOT_BINDABLE 7 +// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. +#define SOCKETS_ERROR_CODE_ADDRESS_IN_USE 8 +// The remote address is not reachable +#define SOCKETS_ERROR_CODE_REMOTE_UNREACHABLE 9 +// The TCP connection was forcefully rejected +#define SOCKETS_ERROR_CODE_CONNECTION_REFUSED 10 +// The TCP connection was reset. +#define SOCKETS_ERROR_CODE_CONNECTION_RESET 11 +// A TCP connection was aborted. +#define SOCKETS_ERROR_CODE_CONNECTION_ABORTED 12 +// The size of a datagram sent to a UDP socket exceeded the maximum +// supported size. +#define SOCKETS_ERROR_CODE_DATAGRAM_TOO_LARGE 13 + +typedef uint8_t sockets_ip_address_family_t; + +// Similar to `AF_INET` in POSIX. +#define SOCKETS_IP_ADDRESS_FAMILY_IPV4 0 +// Similar to `AF_INET6` in POSIX. +#define SOCKETS_IP_ADDRESS_FAMILY_IPV6 1 + +typedef struct sockets_ipv4_address_t { + uint8_t f0; + uint8_t f1; + uint8_t f2; + uint8_t f3; +} sockets_ipv4_address_t; + +typedef struct sockets_ipv6_address_t { + uint16_t f0; + uint16_t f1; + uint16_t f2; + uint16_t f3; + uint16_t f4; + uint16_t f5; + uint16_t f6; + uint16_t f7; +} sockets_ipv6_address_t; + +typedef struct sockets_ip_address_t { + uint8_t tag; + union { + sockets_ipv4_address_t ipv4; + sockets_ipv6_address_t ipv6; + } val; +} sockets_ip_address_t; + +#define SOCKETS_IP_ADDRESS_IPV4 0 +#define SOCKETS_IP_ADDRESS_IPV6 1 + +typedef struct sockets_ipv4_socket_address_t { + // sin_port + uint16_t port; + // sin_addr + sockets_ipv4_address_t address; +} sockets_ipv4_socket_address_t; + +typedef struct sockets_ipv6_socket_address_t { + // sin6_port + uint16_t port; + // sin6_flowinfo + uint32_t flow_info; + // sin6_addr + sockets_ipv6_address_t address; + // sin6_scope_id + uint32_t scope_id; +} sockets_ipv6_socket_address_t; + +typedef struct sockets_ip_socket_address_t { + uint8_t tag; + union { + sockets_ipv4_socket_address_t ipv4; + sockets_ipv6_socket_address_t ipv6; + } val; +} sockets_ip_socket_address_t; + +#define SOCKETS_IP_SOCKET_ADDRESS_IPV4 0 +#define SOCKETS_IP_SOCKET_ADDRESS_IPV6 1 + +typedef struct sockets_own_tcp_socket_t { + int32_t __handle; +} sockets_own_tcp_socket_t; + +typedef struct sockets_borrow_tcp_socket_t { + int32_t __handle; +} sockets_borrow_tcp_socket_t; + +typedef struct sockets_own_udp_socket_t { + int32_t __handle; +} sockets_own_udp_socket_t; + +typedef struct sockets_borrow_udp_socket_t { + int32_t __handle; +} sockets_borrow_udp_socket_t; + +typedef struct { + bool is_err; + union { + sockets_own_tcp_socket_t ok; + sockets_error_code_t err; + } val; +} sockets_result_own_tcp_socket_error_code_t; + +typedef struct { + bool is_err; + union { + sockets_error_code_t err; + } val; +} sockets_result_void_error_code_t; + +typedef uint32_t sockets_stream_own_tcp_socket_t; + +typedef struct { + bool is_err; + union { + sockets_stream_own_tcp_socket_t ok; + sockets_error_code_t err; + } val; +} sockets_result_stream_own_tcp_socket_error_code_t; + +typedef uint32_t sockets_stream_u8_t; + +typedef uint32_t sockets_future_result_void_error_code_t; + +typedef struct { + sockets_stream_u8_t f0; + sockets_future_result_void_error_code_t f1; +} sockets_tuple2_stream_u8_future_result_void_error_code_t; + +typedef struct { + bool is_err; + union { + sockets_ip_socket_address_t ok; + sockets_error_code_t err; + } val; +} sockets_result_ip_socket_address_error_code_t; + +typedef struct { + bool is_err; + union { + bool ok; + sockets_error_code_t err; + } val; +} sockets_result_bool_error_code_t; + +typedef struct { + bool is_err; + union { + sockets_duration_t ok; + sockets_error_code_t err; + } val; +} sockets_result_duration_error_code_t; + +typedef struct { + bool is_err; + union { + uint32_t ok; + sockets_error_code_t err; + } val; +} sockets_result_u32_error_code_t; + +typedef struct { + bool is_err; + union { + uint8_t ok; + sockets_error_code_t err; + } val; +} sockets_result_u8_error_code_t; + +typedef struct { + bool is_err; + union { + uint64_t ok; + sockets_error_code_t err; + } val; +} sockets_result_u64_error_code_t; + +typedef struct { + bool is_err; + union { + sockets_own_udp_socket_t ok; + sockets_error_code_t err; + } val; +} sockets_result_own_udp_socket_error_code_t; + +typedef struct { + uint8_t *ptr; + size_t len; +} wasip3_list_u8_t; + +typedef struct { + bool is_some; + sockets_ip_socket_address_t val; +} sockets_option_ip_socket_address_t; + +typedef struct { + wasip3_list_u8_t f0; + sockets_ip_socket_address_t f1; +} sockets_tuple2_list_u8_ip_socket_address_t; + +typedef struct { + bool is_err; + union { + sockets_tuple2_list_u8_ip_socket_address_t ok; + sockets_error_code_t err; + } val; +} sockets_result_tuple2_list_u8_ip_socket_address_error_code_t; +typedef struct sockets_method_tcp_socket_connect_args { + sockets_borrow_tcp_socket_t self; + sockets_ip_socket_address_t remote_address; +} sockets_method_tcp_socket_connect_args_t; +typedef struct sockets_method_udp_socket_send_args { + sockets_borrow_udp_socket_t self; + wasip3_list_u8_t data; + sockets_option_ip_socket_address_t remote_address; +} sockets_method_udp_socket_send_args_t; + +typedef sockets_ip_address_t ip_name_lookup_ip_address_t; + +// Lookup error codes. +typedef uint8_t ip_name_lookup_error_code_t; + +// Unknown error +#define IP_NAME_LOOKUP_ERROR_CODE_UNKNOWN 0 +// Access denied. +// +// POSIX equivalent: EACCES, EPERM +#define IP_NAME_LOOKUP_ERROR_CODE_ACCESS_DENIED 1 +// `name` is a syntactically invalid domain name or IP address. +// +// POSIX equivalent: EINVAL +#define IP_NAME_LOOKUP_ERROR_CODE_INVALID_ARGUMENT 2 +// Name does not exist or has no suitable associated IP addresses. +// +// POSIX equivalent: EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY +#define IP_NAME_LOOKUP_ERROR_CODE_NAME_UNRESOLVABLE 3 +// A temporary failure in name resolution occurred. +// +// POSIX equivalent: EAI_AGAIN +#define IP_NAME_LOOKUP_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE 4 +// A permanent failure in name resolution occurred. +// +// POSIX equivalent: EAI_FAIL +#define IP_NAME_LOOKUP_ERROR_CODE_PERMANENT_RESOLVER_FAILURE 5 + +typedef struct { + ip_name_lookup_ip_address_t *ptr; + size_t len; +} ip_name_lookup_list_ip_address_t; + +typedef struct { + bool is_err; + union { + ip_name_lookup_list_ip_address_t ok; + ip_name_lookup_error_code_t err; + } val; +} ip_name_lookup_result_list_ip_address_error_code_t; + +typedef struct { + uint64_t f0; + uint64_t f1; +} wasip3_tuple2_u64_u64_t; + +// Imported Functions from `wasi:cli/environment@0.3.0-rc-2025-09-16` +// Get the POSIX-style environment variables. +// +// Each environment variable is provided as a pair of string variable names +// and string value. +// +// Morally, these are a value import, but until value imports are available +// in the component model, this import function should return the same +// values each time it is called. +extern void environment_get_environment(wasip3_list_tuple2_string_string_t *ret); +// Get the POSIX-style arguments to the program. +extern void environment_get_arguments(wasip3_list_string_t *ret); +// Return a path that programs should use as their initial current working +// directory, interpreting `.` as shorthand for this. +extern bool environment_get_initial_cwd(wasip3_string_t *ret); + +// Imported Functions from `wasi:cli/exit@0.3.0-rc-2025-09-16` +// Exit the current instance and any linked instances. +_Noreturn extern void exit_exit(exit_result_void_void_t *status); + +// Imported Functions from `wasi:cli/stdin@0.3.0-rc-2025-09-16` +// Return a stream for reading from stdin. +// +// This function returns a stream which provides data read from stdin, +// and a future to signal read results. +// +// If the stream's readable end is dropped the future will resolve to success. +// +// If the stream's writable end is dropped the future will either resolve to +// success if stdin was closed by the writer or to an error-code if reading +// failed for some other reason. +// +// Multiple streams may be active at the same time. The behavior of concurrent +// reads is implementation-specific. +extern void stdin_read_via_stream(stdin_tuple2_stream_u8_future_result_void_error_code_t *ret); + +// Imported Functions from `wasi:cli/stdout@0.3.0-rc-2025-09-16` +// Write the given stream to stdout. +// +// If the stream's writable end is dropped this function will either return +// success once the entire contents of the stream have been written or an +// error-code representing a failure. +// +// Otherwise if there is an error the readable end of the stream will be +// dropped and this function will return an error-code. +extern wasip3_subtask_status_t stdout_write_via_stream(stdin_stream_u8_t data, stdout_result_void_error_code_t *result); + +// Imported Functions from `wasi:cli/stderr@0.3.0-rc-2025-09-16` +// Write the given stream to stderr. +// +// If the stream's writable end is dropped this function will either return +// success once the entire contents of the stream have been written or an +// error-code representing a failure. +// +// Otherwise if there is an error the readable end of the stream will be +// dropped and this function will return an error-code. +extern wasip3_subtask_status_t stderr_write_via_stream(stdin_stream_u8_t data, stderr_result_void_error_code_t *result); + +// Imported Functions from `wasi:cli/terminal-stdin@0.3.0-rc-2025-09-16` +// If stdin is connected to a terminal, return a `terminal-input` handle +// allowing further interaction with it. +extern bool terminal_stdin_get_terminal_stdin(terminal_stdin_own_terminal_input_t *ret); + +// Imported Functions from `wasi:cli/terminal-stdout@0.3.0-rc-2025-09-16` +// If stdout is connected to a terminal, return a `terminal-output` handle +// allowing further interaction with it. +extern bool terminal_stdout_get_terminal_stdout(terminal_stdout_own_terminal_output_t *ret); + +// Imported Functions from `wasi:cli/terminal-stderr@0.3.0-rc-2025-09-16` +// If stderr is connected to a terminal, return a `terminal-output` handle +// allowing further interaction with it. +extern bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t *ret); + +// Imported Functions from `wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16` +// Read the current value of the clock. +// +// The clock is monotonic, therefore calling this function repeatedly will +// produce a sequence of non-decreasing values. +// +// For completeness, this function traps if it's not possible to represent +// the value of the clock in an `instant`. Consequently, implementations +// should ensure that the starting time is low enough to avoid the +// possibility of overflow in practice. +extern monotonic_clock_instant_t monotonic_clock_now(void); +// Query the resolution of the clock. Returns the duration of time +// corresponding to a clock tick. +extern monotonic_clock_duration_t monotonic_clock_get_resolution(void); +// Wait until the specified instant has occurred. +extern wasip3_subtask_status_t monotonic_clock_wait_until(monotonic_clock_instant_t when); +// Wait for the specified duration to elapse. +extern wasip3_subtask_status_t monotonic_clock_wait_for(monotonic_clock_duration_t how_long); + +// Imported Functions from `wasi:clocks/wall-clock@0.3.0-rc-2025-09-16` +// Read the current value of the clock. +// +// This clock is not monotonic, therefore calling this function repeatedly +// will not necessarily produce a sequence of non-decreasing values. +// +// The returned timestamps represent the number of seconds since +// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], +// also known as [Unix Time]. +// +// The nanoseconds field of the output is always less than 1000000000. +// +// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 +// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time +extern void wall_clock_now(wall_clock_datetime_t *ret); +// Query the resolution of the clock. +// +// The nanoseconds field of the output is always less than 1000000000. +extern void wall_clock_get_resolution(wall_clock_datetime_t *ret); + +// Imported Functions from `wasi:filesystem/types@0.3.0-rc-2025-09-16` +// Return a stream for reading from a file. +// +// Multiple read, write, and append streams may be active on the same open +// file and they do not interfere with each other. +// +// This function returns a `stream` which provides the data received from the +// file, and a `future` providing additional error information in case an +// error is encountered. +// +// If no error is encountered, `stream.read` on the `stream` will return +// `read-status::closed` with no `error-context` and the future resolves to +// the value `ok`. If an error is encountered, `stream.read` on the +// `stream` returns `read-status::closed` with an `error-context` and the future +// resolves to `err` with an `error-code`. +// +// Note: This is similar to `pread` in POSIX. +extern void filesystem_method_descriptor_read_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_tuple2_stream_u8_future_result_void_error_code_t *ret); +// Return a stream for writing to a file, if available. +// +// May fail with an error-code describing why the file cannot be written. +// +// It is valid to write past the end of a file; the file is extended to the +// extent of the write, with bytes between the previous end and the start of +// the write set to zero. +// +// This function returns once either full contents of the stream are +// written or an error is encountered. +// +// Note: This is similar to `pwrite` in POSIX. +extern wasip3_subtask_status_t filesystem_method_descriptor_write_via_stream(filesystem_borrow_descriptor_t self, filesystem_stream_u8_t data, filesystem_filesize_t offset, filesystem_result_void_error_code_t *result); +// Return a stream for appending to a file, if available. +// +// May fail with an error-code describing why the file cannot be appended. +// +// This function returns once either full contents of the stream are +// written or an error is encountered. +// +// Note: This is similar to `write` with `O_APPEND` in POSIX. +extern wasip3_subtask_status_t filesystem_method_descriptor_append_via_stream(filesystem_borrow_descriptor_t self, filesystem_stream_u8_t data, filesystem_result_void_error_code_t *result); +// Provide file advisory information on a descriptor. +// +// This is similar to `posix_fadvise` in POSIX. +extern wasip3_subtask_status_t filesystem_method_descriptor_advise(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_filesize_t length, filesystem_advice_t advice, filesystem_result_void_error_code_t *result); +// Synchronize the data of a file to disk. +// +// This function succeeds with no effect if the file descriptor is not +// opened for writing. +// +// Note: This is similar to `fdatasync` in POSIX. +extern wasip3_subtask_status_t filesystem_method_descriptor_sync_data(filesystem_borrow_descriptor_t self, filesystem_result_void_error_code_t *result); +// Get flags associated with a descriptor. +// +// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. +// +// Note: This returns the value that was the `fs_flags` value returned +// from `fdstat_get` in earlier versions of WASI. +extern wasip3_subtask_status_t filesystem_method_descriptor_get_flags(filesystem_borrow_descriptor_t self, filesystem_result_descriptor_flags_error_code_t *result); +// Get the dynamic type of a descriptor. +// +// Note: This returns the same value as the `type` field of the `fd-stat` +// returned by `stat`, `stat-at` and similar. +// +// Note: This returns similar flags to the `st_mode & S_IFMT` value provided +// by `fstat` in POSIX. +// +// Note: This returns the value that was the `fs_filetype` value returned +// from `fdstat_get` in earlier versions of WASI. +extern wasip3_subtask_status_t filesystem_method_descriptor_get_type(filesystem_borrow_descriptor_t self, filesystem_result_descriptor_type_error_code_t *result); +// Adjust the size of an open file. If this increases the file's size, the +// extra bytes are filled with zeros. +// +// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. +extern wasip3_subtask_status_t filesystem_method_descriptor_set_size(filesystem_borrow_descriptor_t self, filesystem_filesize_t size, filesystem_result_void_error_code_t *result); +// Adjust the timestamps of an open file or directory. +// +// Note: This is similar to `futimens` in POSIX. +// +// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. +extern wasip3_subtask_status_t filesystem_method_descriptor_set_times(filesystem_method_descriptor_set_times_args_t *args, filesystem_result_void_error_code_t *result); +// Read directory entries from a directory. +// +// On filesystems where directories contain entries referring to themselves +// and their parents, often named `.` and `..` respectively, these entries +// are omitted. +// +// This always returns a new stream which starts at the beginning of the +// directory. Multiple streams may be active on the same directory, and they +// do not interfere with each other. +// +// This function returns a future, which will resolve to an error code if +// reading full contents of the directory fails. +extern wasip3_subtask_status_t filesystem_method_descriptor_read_directory(filesystem_borrow_descriptor_t self, filesystem_tuple2_stream_directory_entry_future_result_void_error_code_t *result); +// Synchronize the data and metadata of a file to disk. +// +// This function succeeds with no effect if the file descriptor is not +// opened for writing. +// +// Note: This is similar to `fsync` in POSIX. +extern wasip3_subtask_status_t filesystem_method_descriptor_sync(filesystem_borrow_descriptor_t self, filesystem_result_void_error_code_t *result); +// Create a directory. +// +// Note: This is similar to `mkdirat` in POSIX. +extern wasip3_subtask_status_t filesystem_method_descriptor_create_directory_at(filesystem_borrow_descriptor_t self, wasip3_string_t path, filesystem_result_void_error_code_t *result); +// Return the attributes of an open file or directory. +// +// Note: This is similar to `fstat` in POSIX, except that it does not return +// device and inode information. For testing whether two descriptors refer to +// the same underlying filesystem object, use `is-same-object`. To obtain +// additional data that can be used do determine whether a file has been +// modified, use `metadata-hash`. +// +// Note: This was called `fd_filestat_get` in earlier versions of WASI. +extern wasip3_subtask_status_t filesystem_method_descriptor_stat(filesystem_borrow_descriptor_t self, filesystem_result_descriptor_stat_error_code_t *result); +// Return the attributes of a file or directory. +// +// Note: This is similar to `fstatat` in POSIX, except that it does not +// return device and inode information. See the `stat` description for a +// discussion of alternatives. +// +// Note: This was called `path_filestat_get` in earlier versions of WASI. +extern wasip3_subtask_status_t filesystem_method_descriptor_stat_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip3_string_t path, filesystem_result_descriptor_stat_error_code_t *result); +// Adjust the timestamps of a file or directory. +// +// Note: This is similar to `utimensat` in POSIX. +// +// Note: This was called `path_filestat_set_times` in earlier versions of +// WASI. +extern wasip3_subtask_status_t filesystem_method_descriptor_set_times_at(filesystem_method_descriptor_set_times_at_args_t *args, filesystem_result_void_error_code_t *result); +// Create a hard link. +// +// Fails with `error-code::no-entry` if the old path does not exist, +// with `error-code::exist` if the new path already exists, and +// `error-code::not-permitted` if the old path is not a file. +// +// Note: This is similar to `linkat` in POSIX. +extern wasip3_subtask_status_t filesystem_method_descriptor_link_at(filesystem_method_descriptor_link_at_args_t *args, filesystem_result_void_error_code_t *result); +// Open a file or directory. +// +// If `flags` contains `descriptor-flags::mutate-directory`, and the base +// descriptor doesn't have `descriptor-flags::mutate-directory` set, +// `open-at` fails with `error-code::read-only`. +// +// If `flags` contains `write` or `mutate-directory`, or `open-flags` +// contains `truncate` or `create`, and the base descriptor doesn't have +// `descriptor-flags::mutate-directory` set, `open-at` fails with +// `error-code::read-only`. +// +// Note: This is similar to `openat` in POSIX. +extern wasip3_subtask_status_t filesystem_method_descriptor_open_at(filesystem_method_descriptor_open_at_args_t *args, filesystem_result_own_descriptor_error_code_t *result); +// Read the contents of a symbolic link. +// +// If the contents contain an absolute or rooted path in the underlying +// filesystem, this function fails with `error-code::not-permitted`. +// +// Note: This is similar to `readlinkat` in POSIX. +extern wasip3_subtask_status_t filesystem_method_descriptor_readlink_at(filesystem_borrow_descriptor_t self, wasip3_string_t path, filesystem_result_string_error_code_t *result); +// Remove a directory. +// +// Return `error-code::not-empty` if the directory is not empty. +// +// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. +extern wasip3_subtask_status_t filesystem_method_descriptor_remove_directory_at(filesystem_borrow_descriptor_t self, wasip3_string_t path, filesystem_result_void_error_code_t *result); +// Rename a filesystem object. +// +// Note: This is similar to `renameat` in POSIX. +extern wasip3_subtask_status_t filesystem_method_descriptor_rename_at(filesystem_method_descriptor_rename_at_args_t *args, filesystem_result_void_error_code_t *result); +// Create a symbolic link (also known as a "symlink"). +// +// If `old-path` starts with `/`, the function fails with +// `error-code::not-permitted`. +// +// Note: This is similar to `symlinkat` in POSIX. +extern wasip3_subtask_status_t filesystem_method_descriptor_symlink_at(filesystem_method_descriptor_symlink_at_args_t *args, filesystem_result_void_error_code_t *result); +// Unlink a filesystem object that is not a directory. +// +// Return `error-code::is-directory` if the path refers to a directory. +// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. +extern wasip3_subtask_status_t filesystem_method_descriptor_unlink_file_at(filesystem_borrow_descriptor_t self, wasip3_string_t path, filesystem_result_void_error_code_t *result); +// Test whether two descriptors refer to the same filesystem object. +// +// In POSIX, this corresponds to testing whether the two descriptors have the +// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. +// wasi-filesystem does not expose device and inode numbers, so this function +// may be used instead. +extern wasip3_subtask_status_t filesystem_method_descriptor_is_same_object(filesystem_borrow_descriptor_t self, filesystem_borrow_descriptor_t other, bool *result); +// Return a hash of the metadata associated with a filesystem object referred +// to by a descriptor. +// +// This returns a hash of the last-modification timestamp and file size, and +// may also include the inode number, device number, birth timestamp, and +// other metadata fields that may change when the file is modified or +// replaced. It may also include a secret value chosen by the +// implementation and not otherwise exposed. +// +// Implementations are encouraged to provide the following properties: +// +// - If the file is not modified or replaced, the computed hash value should +// usually not change. +// - If the object is modified or replaced, the computed hash value should +// usually change. +// - The inputs to the hash should not be easily computable from the +// computed hash. +// +// However, none of these is required. +extern wasip3_subtask_status_t filesystem_method_descriptor_metadata_hash(filesystem_borrow_descriptor_t self, filesystem_result_metadata_hash_value_error_code_t *result); +// Return a hash of the metadata associated with a filesystem object referred +// to by a directory descriptor and a relative path. +// +// This performs the same hash computation as `metadata-hash`. +extern wasip3_subtask_status_t filesystem_method_descriptor_metadata_hash_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip3_string_t path, filesystem_result_metadata_hash_value_error_code_t *result); + +// Imported Functions from `wasi:filesystem/preopens@0.3.0-rc-2025-09-16` +// Return the set of preopened directories, and their paths. +extern void filesystem_preopens_get_directories(filesystem_preopens_list_tuple2_own_descriptor_string_t *ret); + +// Imported Functions from `wasi:sockets/types@0.3.0-rc-2025-09-16` +// Create a new TCP socket. +// +// Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. +// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. +// +// Unlike POSIX, WASI sockets have no notion of a socket-level +// `O_NONBLOCK` flag. Instead they fully rely on the Component Model's +// async support. +// +// # References +// - +// - +// - +// - +extern bool sockets_static_tcp_socket_create(sockets_ip_address_family_t address_family, sockets_own_tcp_socket_t *ret, sockets_error_code_t *err); +// Bind the socket to the provided IP address and port. +// +// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which +// network interface(s) to bind to. +// If the TCP/UDP port is zero, the socket will be bound to a random free port. +// +// Bind can be attempted multiple times on the same socket, even with +// different arguments on each iteration. But never concurrently and +// only as long as the previous bind failed. Once a bind succeeds, the +// binding can't be changed anymore. +// +// # Typical errors +// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) +// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) +// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL) +// - `invalid-state`: The socket is already bound. (EINVAL) +// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) +// - `address-in-use`: Address is already in use. (EADDRINUSE) +// - `address-not-bindable`: `local-address` is not an address that can be bound to. (EADDRNOTAVAIL) +// +// # Implementors note +// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT +// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR +// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior +// and SO_REUSEADDR performs something different entirely. +// +// # References +// - +// - +// - +// - +extern bool sockets_method_tcp_socket_bind(sockets_borrow_tcp_socket_t self, sockets_ip_socket_address_t *local_address, sockets_error_code_t *err); +// Connect to a remote endpoint. +// +// On success, the socket is transitioned into the `connected` state and this function returns a connection resource. +// +// After a failed connection attempt, the socket will be in the `closed` +// state and the only valid action left is to `drop` the socket. A single +// socket can not be used to connect more than once. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) +// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) +// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows) +// - `invalid-state`: The socket is already in the `connecting` state. (EALREADY) +// - `invalid-state`: The socket is already in the `connected` state. (EISCONN) +// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows) +// - `timeout`: Connection timed out. (ETIMEDOUT) +// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) +// - `connection-reset`: The connection was reset. (ECONNRESET) +// - `connection-aborted`: The connection was aborted. (ECONNABORTED) +// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) +// +// # References +// - +// - +// - +// - +extern wasip3_subtask_status_t sockets_method_tcp_socket_connect(sockets_method_tcp_socket_connect_args_t *args, sockets_result_void_error_code_t *result); +// Start listening and return a stream of new inbound connections. +// +// Transitions the socket into the `listening` state. This can be called +// at most once per socket. +// +// If the socket is not already explicitly bound, this function will +// implicitly bind the socket to a random free port. +// +// Normally, the returned sockets are bound, in the `connected` state +// and immediately ready for I/O. Though, depending on exact timing and +// circumstances, a newly accepted connection may already be `closed` +// by the time the server attempts to perform its first I/O on it. This +// is true regardless of whether the WASI implementation uses +// "synthesized" sockets or not (see Implementors Notes below). +// +// The following properties are inherited from the listener socket: +// - `address-family` +// - `keep-alive-enabled` +// - `keep-alive-idle-time` +// - `keep-alive-interval` +// - `keep-alive-count` +// - `hop-limit` +// - `receive-buffer-size` +// - `send-buffer-size` +// +// # Typical errors +// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD) +// - `invalid-state`: The socket is already in the `listening` state. +// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE) +// +// # Implementors note +// This method returns a single perpetual stream that should only close +// on fatal errors (if any). Yet, the POSIX' `accept` function may also +// return transient errors (e.g. ECONNABORTED). The exact details differ +// per operation system. For example, the Linux manual mentions: +// +// > Linux accept() passes already-pending network errors on the new +// > socket as an error code from accept(). This behavior differs from +// > other BSD socket implementations. For reliable operation the +// > application should detect the network errors defined for the +// > protocol after accept() and treat them like EAGAIN by retrying. +// > In the case of TCP/IP, these are ENETDOWN, EPROTO, ENOPROTOOPT, +// > EHOSTDOWN, ENONET, EHOSTUNREACH, EOPNOTSUPP, and ENETUNREACH. +// Source: https://man7.org/linux/man-pages/man2/accept.2.html +// +// WASI implementations have two options to handle this: +// - Optionally log it and then skip over non-fatal errors returned by +// `accept`. Guest code never gets to see these failures. Or: +// - Synthesize a `tcp-socket` resource that exposes the error when +// attempting to send or receive on it. Guest code then sees these +// failures as regular I/O errors. +// +// In either case, the stream returned by this `listen` method remains +// operational. +// +// # References +// - +// - +// - +// - +// - +// - +// - +// - +extern bool sockets_method_tcp_socket_listen(sockets_borrow_tcp_socket_t self, sockets_stream_own_tcp_socket_t *ret, sockets_error_code_t *err); +// Transmit data to peer. +// +// The caller should close the stream when it has no more data to send +// to the peer. Under normal circumstances this will cause a FIN packet +// to be sent out. Closing the stream is equivalent to calling +// `shutdown(SHUT_WR)` in POSIX. +// +// This function may be called at most once and returns once the full +// contents of the stream are transmitted or an error is encountered. +// +// # Typical errors +// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) +// - `connection-reset`: The connection was reset. (ECONNRESET) +// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// +// # References +// - +// - +// - +// - +extern wasip3_subtask_status_t sockets_method_tcp_socket_send(sockets_borrow_tcp_socket_t self, sockets_stream_u8_t data, sockets_result_void_error_code_t *result); +// Read data from peer. +// +// This function returns a `stream` which provides the data received from the +// socket, and a `future` providing additional error information in case the +// socket is closed abnormally. +// +// If the socket is closed normally, `stream.read` on the `stream` will return +// `read-status::closed` with no `error-context` and the future resolves to +// the value `ok`. If the socket is closed abnormally, `stream.read` on the +// `stream` returns `read-status::closed` with an `error-context` and the future +// resolves to `err` with an `error-code`. +// +// `receive` is meant to be called only once per socket. If it is called more +// than once, the subsequent calls return a new `stream` that fails as if it +// were closed abnormally. +// +// If the caller is not expecting to receive any data from the peer, +// they may drop the stream. Any data still in the receive queue +// will be discarded. This is equivalent to calling `shutdown(SHUT_RD)` +// in POSIX. +// +// # Typical errors +// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) +// - `connection-reset`: The connection was reset. (ECONNRESET) +// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// +// # References +// - +// - +// - +// - +extern void sockets_method_tcp_socket_receive(sockets_borrow_tcp_socket_t self, sockets_tuple2_stream_u8_future_result_void_error_code_t *ret); +// Get the bound local address. +// +// POSIX mentions: +// > If the socket has not been bound to a local name, the value +// > stored in the object pointed to by `address` is unspecified. +// +// WASI is stricter and requires `get-local-address` to return `invalid-state` when the socket hasn't been bound yet. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. +// +// # References +// - +// - +// - +// - +extern bool sockets_method_tcp_socket_get_local_address(sockets_borrow_tcp_socket_t self, sockets_ip_socket_address_t *ret, sockets_error_code_t *err); +// Get the remote address. +// +// # Typical errors +// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) +// +// # References +// - +// - +// - +// - +extern bool sockets_method_tcp_socket_get_remote_address(sockets_borrow_tcp_socket_t self, sockets_ip_socket_address_t *ret, sockets_error_code_t *err); +// Whether the socket is in the `listening` state. +// +// Equivalent to the SO_ACCEPTCONN socket option. +extern bool sockets_method_tcp_socket_get_is_listening(sockets_borrow_tcp_socket_t self); +// Whether this is a IPv4 or IPv6 socket. +// +// This is the value passed to the constructor. +// +// Equivalent to the SO_DOMAIN socket option. +extern sockets_ip_address_family_t sockets_method_tcp_socket_get_address_family(sockets_borrow_tcp_socket_t self); +// Hints the desired listen queue size. Implementations are free to ignore this. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// +// # Typical errors +// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. +// - `invalid-argument`: (set) The provided value was 0. +// - `invalid-state`: (set) The socket is in the `connecting` or `connected` state. +extern bool sockets_method_tcp_socket_set_listen_backlog_size(sockets_borrow_tcp_socket_t self, uint64_t value, sockets_error_code_t *err); +// Enables or disables keepalive. +// +// The keepalive behavior can be adjusted using: +// - `keep-alive-idle-time` +// - `keep-alive-interval` +// - `keep-alive-count` +// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. +// +// Equivalent to the SO_KEEPALIVE socket option. +extern bool sockets_method_tcp_socket_get_keep_alive_enabled(sockets_borrow_tcp_socket_t self, bool *ret, sockets_error_code_t *err); +extern bool sockets_method_tcp_socket_set_keep_alive_enabled(sockets_borrow_tcp_socket_t self, bool value, sockets_error_code_t *err); +// Amount of time the connection has to be idle before TCP starts sending keepalive packets. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +extern bool sockets_method_tcp_socket_get_keep_alive_idle_time(sockets_borrow_tcp_socket_t self, sockets_duration_t *ret, sockets_error_code_t *err); +extern bool sockets_method_tcp_socket_set_keep_alive_idle_time(sockets_borrow_tcp_socket_t self, sockets_duration_t value, sockets_error_code_t *err); +// The time between keepalive packets. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the TCP_KEEPINTVL socket option. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +extern bool sockets_method_tcp_socket_get_keep_alive_interval(sockets_borrow_tcp_socket_t self, sockets_duration_t *ret, sockets_error_code_t *err); +extern bool sockets_method_tcp_socket_set_keep_alive_interval(sockets_borrow_tcp_socket_t self, sockets_duration_t value, sockets_error_code_t *err); +// The maximum amount of keepalive packets TCP should send before aborting the connection. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the TCP_KEEPCNT socket option. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +extern bool sockets_method_tcp_socket_get_keep_alive_count(sockets_borrow_tcp_socket_t self, uint32_t *ret, sockets_error_code_t *err); +extern bool sockets_method_tcp_socket_set_keep_alive_count(sockets_borrow_tcp_socket_t self, uint32_t value, sockets_error_code_t *err); +// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// +// # Typical errors +// - `invalid-argument`: (set) The TTL value must be 1 or higher. +extern bool sockets_method_tcp_socket_get_hop_limit(sockets_borrow_tcp_socket_t self, uint8_t *ret, sockets_error_code_t *err); +extern bool sockets_method_tcp_socket_set_hop_limit(sockets_borrow_tcp_socket_t self, uint8_t value, sockets_error_code_t *err); +// The kernel buffer space reserved for sends/receives on this socket. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +extern bool sockets_method_tcp_socket_get_receive_buffer_size(sockets_borrow_tcp_socket_t self, uint64_t *ret, sockets_error_code_t *err); +extern bool sockets_method_tcp_socket_set_receive_buffer_size(sockets_borrow_tcp_socket_t self, uint64_t value, sockets_error_code_t *err); +extern bool sockets_method_tcp_socket_get_send_buffer_size(sockets_borrow_tcp_socket_t self, uint64_t *ret, sockets_error_code_t *err); +extern bool sockets_method_tcp_socket_set_send_buffer_size(sockets_borrow_tcp_socket_t self, uint64_t value, sockets_error_code_t *err); +// Create a new UDP socket. +// +// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX. +// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. +// +// Unlike POSIX, WASI sockets have no notion of a socket-level +// `O_NONBLOCK` flag. Instead they fully rely on the Component Model's +// async support. +// +// # References: +// - +// - +// - +// - +extern bool sockets_static_udp_socket_create(sockets_ip_address_family_t address_family, sockets_own_udp_socket_t *ret, sockets_error_code_t *err); +// Bind the socket to the provided IP address and port. +// +// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which +// network interface(s) to bind to. +// If the port is zero, the socket will be bound to a random free port. +// +// # Typical errors +// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) +// - `invalid-state`: The socket is already bound. (EINVAL) +// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) +// - `address-in-use`: Address is already in use. (EADDRINUSE) +// - `address-not-bindable`: `local-address` is not an address that can be bound to. (EADDRNOTAVAIL) +// +// # References +// - +// - +// - +// - +extern bool sockets_method_udp_socket_bind(sockets_borrow_udp_socket_t self, sockets_ip_socket_address_t *local_address, sockets_error_code_t *err); +// Associate this socket with a specific peer address. +// +// On success, the `remote-address` of the socket is updated. +// The `local-address` may be updated as well, based on the best network +// path to `remote-address`. If the socket was not already explicitly +// bound, this function will implicitly bind the socket to a random +// free port. +// +// When a UDP socket is "connected", the `send` and `receive` methods +// are limited to communicating with that peer only: +// - `send` can only be used to send to this destination. +// - `receive` will only return datagrams sent from the provided `remote-address`. +// +// The name "connect" was kept to align with the existing POSIX +// terminology. Other than that, this function only changes the local +// socket configuration and does not generate any network traffic. +// The peer is not aware of this "connection". +// +// This method may be called multiple times on the same socket to change +// its association, but only the most recent one will be effective. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) +// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) +// +// # Implementors note +// If the socket is already connected, some platforms (e.g. Linux) +// require a disconnect before connecting to a different peer address. +// +// # References +// - +// - +// - +// - +extern bool sockets_method_udp_socket_connect(sockets_borrow_udp_socket_t self, sockets_ip_socket_address_t *remote_address, sockets_error_code_t *err); +// Dissociate this socket from its peer address. +// +// After calling this method, `send` & `receive` are free to communicate +// with any address again. +// +// The POSIX equivalent of this is calling `connect` with an `AF_UNSPEC` address. +// +// # Typical errors +// - `invalid-state`: The socket is not connected. +// +// # References +// - +// - +// - +// - +extern bool sockets_method_udp_socket_disconnect(sockets_borrow_udp_socket_t self, sockets_error_code_t *err); +// Send a message on the socket to a particular peer. +// +// If the socket is connected, the peer address may be left empty. In +// that case this is equivalent to `send` in POSIX. Otherwise it is +// equivalent to `sendto`. +// +// Additionally, if the socket is connected, a `remote-address` argument +// _may_ be provided but then it must be identical to the address +// passed to `connect`. +// +// Implementations may trap if the `data` length exceeds 64 KiB. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `connect`. (EISCONN) +// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ) +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) +// +// # References +// - +// - +// - +// - +// - +// - +// - +// - +extern wasip3_subtask_status_t sockets_method_udp_socket_send(sockets_method_udp_socket_send_args_t *args, sockets_result_void_error_code_t *result); +// Receive a message on the socket. +// +// On success, the return value contains a tuple of the received data +// and the address of the sender. Theoretical maximum length of the +// data is 64 KiB. Though in practice, it will typically be less than +// 1500 bytes. +// +// If the socket is connected, the sender address is guaranteed to +// match the remote address passed to `connect`. +// +// # Typical errors +// - `invalid-state`: The socket has not been bound yet. +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// +// # References +// - +// - +// - +// - +// - +// - +// - +extern wasip3_subtask_status_t sockets_method_udp_socket_receive(sockets_borrow_udp_socket_t self, sockets_result_tuple2_list_u8_ip_socket_address_error_code_t *result); +// Get the current bound address. +// +// POSIX mentions: +// > If the socket has not been bound to a local name, the value +// > stored in the object pointed to by `address` is unspecified. +// +// WASI is stricter and requires `get-local-address` to return `invalid-state` when the socket hasn't been bound yet. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. +// +// # References +// - +// - +// - +// - +extern bool sockets_method_udp_socket_get_local_address(sockets_borrow_udp_socket_t self, sockets_ip_socket_address_t *ret, sockets_error_code_t *err); +// Get the address the socket is currently "connected" to. +// +// # Typical errors +// - `invalid-state`: The socket is not "connected" to a specific remote address. (ENOTCONN) +// +// # References +// - +// - +// - +// - +extern bool sockets_method_udp_socket_get_remote_address(sockets_borrow_udp_socket_t self, sockets_ip_socket_address_t *ret, sockets_error_code_t *err); +// Whether this is a IPv4 or IPv6 socket. +// +// This is the value passed to the constructor. +// +// Equivalent to the SO_DOMAIN socket option. +extern sockets_ip_address_family_t sockets_method_udp_socket_get_address_family(sockets_borrow_udp_socket_t self); +// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// +// # Typical errors +// - `invalid-argument`: (set) The TTL value must be 1 or higher. +extern bool sockets_method_udp_socket_get_unicast_hop_limit(sockets_borrow_udp_socket_t self, uint8_t *ret, sockets_error_code_t *err); +extern bool sockets_method_udp_socket_set_unicast_hop_limit(sockets_borrow_udp_socket_t self, uint8_t value, sockets_error_code_t *err); +// The kernel buffer space reserved for sends/receives on this socket. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. +extern bool sockets_method_udp_socket_get_receive_buffer_size(sockets_borrow_udp_socket_t self, uint64_t *ret, sockets_error_code_t *err); +extern bool sockets_method_udp_socket_set_receive_buffer_size(sockets_borrow_udp_socket_t self, uint64_t value, sockets_error_code_t *err); +extern bool sockets_method_udp_socket_get_send_buffer_size(sockets_borrow_udp_socket_t self, uint64_t *ret, sockets_error_code_t *err); +extern bool sockets_method_udp_socket_set_send_buffer_size(sockets_borrow_udp_socket_t self, uint64_t value, sockets_error_code_t *err); + +// Imported Functions from `wasi:sockets/ip-name-lookup@0.3.0-rc-2025-09-16` +// Resolve an internet host name to a list of IP addresses. +// +// Unicode domain names are automatically converted to ASCII using IDNA encoding. +// If the input is an IP address string, the address is parsed and returned +// as-is without making any external requests. +// +// See the wasi-socket proposal README.md for a comparison with getaddrinfo. +// +// The results are returned in connection order preference. +// +// This function never succeeds with 0 results. It either fails or succeeds +// with at least one address. Additionally, this function never returns +// IPv4-mapped IPv6 addresses. +// +// The returned future will resolve to an error code in case of failure. +// It will resolve to success once the returned stream is exhausted. +// +// # References: +// - +// - +// - +// - +extern wasip3_subtask_status_t ip_name_lookup_resolve_addresses(wasip3_string_t name, ip_name_lookup_result_list_ip_address_error_code_t *result); + +// Imported Functions from `wasi:random/random@0.3.0-rc-2025-09-16` +// Return `len` cryptographically-secure random or pseudo-random bytes. +// +// This function must produce data at least as cryptographically secure and +// fast as an adequately seeded cryptographically-secure pseudo-random +// number generator (CSPRNG). It must not block, from the perspective of +// the calling program, under any circumstances, including on the first +// request and on requests for numbers of bytes. The returned data must +// always be unpredictable. +// +// This function must always return fresh data. Deterministic environments +// must omit this function, rather than implementing it with deterministic +// data. +extern void random_get_random_bytes(uint64_t len, wasip3_list_u8_t *ret); +// Return a cryptographically-secure random or pseudo-random `u64` value. +// +// This function returns the same type of data as `get-random-bytes`, +// represented as a `u64`. +extern uint64_t random_get_random_u64(void); + +// Imported Functions from `wasi:random/insecure@0.3.0-rc-2025-09-16` +// Return `len` insecure pseudo-random bytes. +// +// This function is not cryptographically secure. Do not use it for +// anything related to security. +// +// There are no requirements on the values of the returned bytes, however +// implementations are encouraged to return evenly distributed values with +// a long period. +extern void random_insecure_get_insecure_random_bytes(uint64_t len, wasip3_list_u8_t *ret); +// Return an insecure pseudo-random `u64` value. +// +// This function returns the same type of pseudo-random data as +// `get-insecure-random-bytes`, represented as a `u64`. +extern uint64_t random_insecure_get_insecure_random_u64(void); + +// Imported Functions from `wasi:random/insecure-seed@0.3.0-rc-2025-09-16` +// Return a 128-bit value that may contain a pseudo-random value. +// +// The returned value is not required to be computed from a CSPRNG, and may +// even be entirely deterministic. Host implementations are encouraged to +// provide pseudo-random values to any program exposed to +// attacker-controlled content, to enable DoS protection built into many +// languages' hash-map implementations. +// +// This function is intended to only be called once, by a source language +// to initialize Denial Of Service (DoS) protection in its hash-map +// implementation. +// +// # Expected future evolution +// +// This will likely be changed to a value import, to prevent it from being +// called multiple times and potentially used for purposes other than DoS +// protection. +extern void random_insecure_seed_get_insecure_seed(wasip3_tuple2_u64_u64_t *ret); + +// Helper Functions + +void wasip3_tuple2_string_string_free(wasip3_tuple2_string_string_t *ptr); + +void wasip3_list_tuple2_string_string_free(wasip3_list_tuple2_string_string_t *ptr); + +void wasip3_list_string_free(wasip3_list_string_t *ptr); + +void wasip3_option_string_free(wasip3_option_string_t *ptr); + +void exit_result_void_void_free(exit_result_void_void_t *ptr); + +void stdin_result_void_error_code_free(stdin_result_void_error_code_t *ptr); + +typedef uint32_t stdin_stream_u8_writer_t; + +stdin_stream_u8_t stdin_stream_u8_new(stdin_stream_u8_writer_t *writer); +wasip3_waitable_status_t stdin_stream_u8_read(stdin_stream_u8_t reader, uint8_t *buf, size_t amt); +wasip3_waitable_status_t stdin_stream_u8_write(stdin_stream_u8_writer_t writer, const uint8_t *buf, size_t amt); +wasip3_waitable_status_t stdin_stream_u8_cancel_read(stdin_stream_u8_t reader); +wasip3_waitable_status_t stdin_stream_u8_cancel_write(stdin_stream_u8_writer_t writer); +void stdin_stream_u8_drop_readable(stdin_stream_u8_t reader); +void stdin_stream_u8_drop_writable(stdin_stream_u8_writer_t writer); + + +typedef uint32_t stdin_future_result_void_error_code_writer_t; + +stdin_future_result_void_error_code_t stdin_future_result_void_error_code_new(stdin_future_result_void_error_code_writer_t *writer); +wasip3_waitable_status_t stdin_future_result_void_error_code_read(stdin_future_result_void_error_code_t reader, stdin_result_void_error_code_t *buf); +wasip3_waitable_status_t stdin_future_result_void_error_code_write(stdin_future_result_void_error_code_writer_t writer, const stdin_result_void_error_code_t *buf); +wasip3_waitable_status_t stdin_future_result_void_error_code_cancel_read(stdin_future_result_void_error_code_t reader); +wasip3_waitable_status_t stdin_future_result_void_error_code_cancel_write(stdin_future_result_void_error_code_writer_t writer); +void stdin_future_result_void_error_code_drop_readable(stdin_future_result_void_error_code_t reader); +void stdin_future_result_void_error_code_drop_writable(stdin_future_result_void_error_code_writer_t writer); + + +void stdout_result_void_error_code_free(stdout_result_void_error_code_t *ptr); + +void stderr_result_void_error_code_free(stderr_result_void_error_code_t *ptr); + +extern void terminal_input_terminal_input_drop_own(terminal_input_own_terminal_input_t handle); + +extern terminal_input_borrow_terminal_input_t terminal_input_borrow_terminal_input(terminal_input_own_terminal_input_t handle); + +extern void terminal_output_terminal_output_drop_own(terminal_output_own_terminal_output_t handle); + +extern terminal_output_borrow_terminal_output_t terminal_output_borrow_terminal_output(terminal_output_own_terminal_output_t handle); + +void terminal_stdin_option_own_terminal_input_free(terminal_stdin_option_own_terminal_input_t *ptr); + +void terminal_stdout_option_own_terminal_output_free(terminal_stdout_option_own_terminal_output_t *ptr); + +void terminal_stderr_option_own_terminal_output_free(terminal_stderr_option_own_terminal_output_t *ptr); + +void filesystem_option_datetime_free(filesystem_option_datetime_t *ptr); + +void filesystem_descriptor_stat_free(filesystem_descriptor_stat_t *ptr); + +void filesystem_new_timestamp_free(filesystem_new_timestamp_t *ptr); + +void filesystem_directory_entry_free(filesystem_directory_entry_t *ptr); + +extern void filesystem_descriptor_drop_own(filesystem_own_descriptor_t handle); + +extern filesystem_borrow_descriptor_t filesystem_borrow_descriptor(filesystem_own_descriptor_t handle); + +void filesystem_result_void_error_code_free(filesystem_result_void_error_code_t *ptr); + +void filesystem_result_descriptor_flags_error_code_free(filesystem_result_descriptor_flags_error_code_t *ptr); + +void filesystem_result_descriptor_type_error_code_free(filesystem_result_descriptor_type_error_code_t *ptr); + +void filesystem_result_descriptor_stat_error_code_free(filesystem_result_descriptor_stat_error_code_t *ptr); + +void filesystem_result_own_descriptor_error_code_free(filesystem_result_own_descriptor_error_code_t *ptr); + +void filesystem_result_string_error_code_free(filesystem_result_string_error_code_t *ptr); + +void filesystem_result_metadata_hash_value_error_code_free(filesystem_result_metadata_hash_value_error_code_t *ptr); + +typedef uint32_t filesystem_stream_u8_writer_t; + +filesystem_stream_u8_t filesystem_stream_u8_new(filesystem_stream_u8_writer_t *writer); +wasip3_waitable_status_t filesystem_stream_u8_read(filesystem_stream_u8_t reader, uint8_t *buf, size_t amt); +wasip3_waitable_status_t filesystem_stream_u8_write(filesystem_stream_u8_writer_t writer, const uint8_t *buf, size_t amt); +wasip3_waitable_status_t filesystem_stream_u8_cancel_read(filesystem_stream_u8_t reader); +wasip3_waitable_status_t filesystem_stream_u8_cancel_write(filesystem_stream_u8_writer_t writer); +void filesystem_stream_u8_drop_readable(filesystem_stream_u8_t reader); +void filesystem_stream_u8_drop_writable(filesystem_stream_u8_writer_t writer); + + +typedef uint32_t filesystem_future_result_void_error_code_writer_t; + +filesystem_future_result_void_error_code_t filesystem_future_result_void_error_code_new(filesystem_future_result_void_error_code_writer_t *writer); +wasip3_waitable_status_t filesystem_future_result_void_error_code_read(filesystem_future_result_void_error_code_t reader, filesystem_result_void_error_code_t *buf); +wasip3_waitable_status_t filesystem_future_result_void_error_code_write(filesystem_future_result_void_error_code_writer_t writer, const filesystem_result_void_error_code_t *buf); +wasip3_waitable_status_t filesystem_future_result_void_error_code_cancel_read(filesystem_future_result_void_error_code_t reader); +wasip3_waitable_status_t filesystem_future_result_void_error_code_cancel_write(filesystem_future_result_void_error_code_writer_t writer); +void filesystem_future_result_void_error_code_drop_readable(filesystem_future_result_void_error_code_t reader); +void filesystem_future_result_void_error_code_drop_writable(filesystem_future_result_void_error_code_writer_t writer); + + +typedef uint32_t filesystem_stream_directory_entry_writer_t; + +filesystem_stream_directory_entry_t filesystem_stream_directory_entry_new(filesystem_stream_directory_entry_writer_t *writer); +wasip3_waitable_status_t filesystem_stream_directory_entry_read(filesystem_stream_directory_entry_t reader, filesystem_directory_entry_t *buf, size_t amt); +wasip3_waitable_status_t filesystem_stream_directory_entry_write(filesystem_stream_directory_entry_writer_t writer, const filesystem_directory_entry_t *buf, size_t amt); +wasip3_waitable_status_t filesystem_stream_directory_entry_cancel_read(filesystem_stream_directory_entry_t reader); +wasip3_waitable_status_t filesystem_stream_directory_entry_cancel_write(filesystem_stream_directory_entry_writer_t writer); +void filesystem_stream_directory_entry_drop_readable(filesystem_stream_directory_entry_t reader); +void filesystem_stream_directory_entry_drop_writable(filesystem_stream_directory_entry_writer_t writer); + + +void filesystem_preopens_tuple2_own_descriptor_string_free(filesystem_preopens_tuple2_own_descriptor_string_t *ptr); + +void filesystem_preopens_list_tuple2_own_descriptor_string_free(filesystem_preopens_list_tuple2_own_descriptor_string_t *ptr); + +void sockets_ip_address_free(sockets_ip_address_t *ptr); + +void sockets_ip_socket_address_free(sockets_ip_socket_address_t *ptr); + +extern void sockets_tcp_socket_drop_own(sockets_own_tcp_socket_t handle); + +extern sockets_borrow_tcp_socket_t sockets_borrow_tcp_socket(sockets_own_tcp_socket_t handle); + +extern void sockets_udp_socket_drop_own(sockets_own_udp_socket_t handle); + +extern sockets_borrow_udp_socket_t sockets_borrow_udp_socket(sockets_own_udp_socket_t handle); + +void sockets_result_own_tcp_socket_error_code_free(sockets_result_own_tcp_socket_error_code_t *ptr); + +void sockets_result_void_error_code_free(sockets_result_void_error_code_t *ptr); + +void sockets_result_stream_own_tcp_socket_error_code_free(sockets_result_stream_own_tcp_socket_error_code_t *ptr); + +void sockets_result_ip_socket_address_error_code_free(sockets_result_ip_socket_address_error_code_t *ptr); + +void sockets_result_bool_error_code_free(sockets_result_bool_error_code_t *ptr); + +void sockets_result_duration_error_code_free(sockets_result_duration_error_code_t *ptr); + +void sockets_result_u32_error_code_free(sockets_result_u32_error_code_t *ptr); + +void sockets_result_u8_error_code_free(sockets_result_u8_error_code_t *ptr); + +void sockets_result_u64_error_code_free(sockets_result_u64_error_code_t *ptr); + +void sockets_result_own_udp_socket_error_code_free(sockets_result_own_udp_socket_error_code_t *ptr); + +void wasip3_list_u8_free(wasip3_list_u8_t *ptr); + +void sockets_option_ip_socket_address_free(sockets_option_ip_socket_address_t *ptr); + +void sockets_tuple2_list_u8_ip_socket_address_free(sockets_tuple2_list_u8_ip_socket_address_t *ptr); + +void sockets_result_tuple2_list_u8_ip_socket_address_error_code_free(sockets_result_tuple2_list_u8_ip_socket_address_error_code_t *ptr); + +typedef uint32_t sockets_stream_own_tcp_socket_writer_t; + +sockets_stream_own_tcp_socket_t sockets_stream_own_tcp_socket_new(sockets_stream_own_tcp_socket_writer_t *writer); +wasip3_waitable_status_t sockets_stream_own_tcp_socket_read(sockets_stream_own_tcp_socket_t reader, sockets_own_tcp_socket_t *buf, size_t amt); +wasip3_waitable_status_t sockets_stream_own_tcp_socket_write(sockets_stream_own_tcp_socket_writer_t writer, const sockets_own_tcp_socket_t *buf, size_t amt); +wasip3_waitable_status_t sockets_stream_own_tcp_socket_cancel_read(sockets_stream_own_tcp_socket_t reader); +wasip3_waitable_status_t sockets_stream_own_tcp_socket_cancel_write(sockets_stream_own_tcp_socket_writer_t writer); +void sockets_stream_own_tcp_socket_drop_readable(sockets_stream_own_tcp_socket_t reader); +void sockets_stream_own_tcp_socket_drop_writable(sockets_stream_own_tcp_socket_writer_t writer); + + +typedef uint32_t sockets_stream_u8_writer_t; + +sockets_stream_u8_t sockets_stream_u8_new(sockets_stream_u8_writer_t *writer); +wasip3_waitable_status_t sockets_stream_u8_read(sockets_stream_u8_t reader, uint8_t *buf, size_t amt); +wasip3_waitable_status_t sockets_stream_u8_write(sockets_stream_u8_writer_t writer, const uint8_t *buf, size_t amt); +wasip3_waitable_status_t sockets_stream_u8_cancel_read(sockets_stream_u8_t reader); +wasip3_waitable_status_t sockets_stream_u8_cancel_write(sockets_stream_u8_writer_t writer); +void sockets_stream_u8_drop_readable(sockets_stream_u8_t reader); +void sockets_stream_u8_drop_writable(sockets_stream_u8_writer_t writer); + + +typedef uint32_t sockets_future_result_void_error_code_writer_t; + +sockets_future_result_void_error_code_t sockets_future_result_void_error_code_new(sockets_future_result_void_error_code_writer_t *writer); +wasip3_waitable_status_t sockets_future_result_void_error_code_read(sockets_future_result_void_error_code_t reader, sockets_result_void_error_code_t *buf); +wasip3_waitable_status_t sockets_future_result_void_error_code_write(sockets_future_result_void_error_code_writer_t writer, const sockets_result_void_error_code_t *buf); +wasip3_waitable_status_t sockets_future_result_void_error_code_cancel_read(sockets_future_result_void_error_code_t reader); +wasip3_waitable_status_t sockets_future_result_void_error_code_cancel_write(sockets_future_result_void_error_code_writer_t writer); +void sockets_future_result_void_error_code_drop_readable(sockets_future_result_void_error_code_t reader); +void sockets_future_result_void_error_code_drop_writable(sockets_future_result_void_error_code_writer_t writer); + + +void ip_name_lookup_ip_address_free(ip_name_lookup_ip_address_t *ptr); + +void ip_name_lookup_list_ip_address_free(ip_name_lookup_list_ip_address_t *ptr); + +void ip_name_lookup_result_list_ip_address_error_code_free(ip_name_lookup_result_list_ip_address_error_code_t *ptr); + +// Sets the string `ret` to reference the input string `s` without copying it +void wasip3_string_set(wasip3_string_t *ret, const char*s); + +// Creates a copy of the input nul-terminated string `s` and +// stores it into the component model string `ret`. +void wasip3_string_dup(wasip3_string_t *ret, const char*s); + +// Deallocates the string pointed to by `ret`, deallocating +// the memory behind the string. +void wasip3_string_free(wasip3_string_t *ret); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/libc-bottom-half/headers/public/wasi/api.h b/libc-bottom-half/headers/public/wasi/api.h index b44ea34e4..24ccddbb5 100644 --- a/libc-bottom-half/headers/public/wasi/api.h +++ b/libc-bottom-half/headers/public/wasi/api.h @@ -25,6 +25,8 @@ #include #elif defined(__wasip2__) #include +#elif defined(__wasip3__) +#include #else #error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/headers/public/wasi/wasip2.h b/libc-bottom-half/headers/public/wasi/wasip2.h index 54ffac264..9c544cce6 100644 --- a/libc-bottom-half/headers/public/wasi/wasip2.h +++ b/libc-bottom-half/headers/public/wasi/wasip2.h @@ -1,2457 +1,10 @@ -// Generated by `wit-bindgen` 0.48.0. DO NOT EDIT! -#ifndef __BINDINGS_WASIP2_H -#define __BINDINGS_WASIP2_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -typedef struct wasip2_string_t { - uint8_t*ptr; - size_t len; -} wasip2_string_t; - -typedef struct { - wasip2_string_t f0; - wasip2_string_t f1; -} wasip2_tuple2_string_string_t; - -typedef struct { - wasip2_tuple2_string_string_t *ptr; - size_t len; -} wasip2_list_tuple2_string_string_t; - -typedef struct { - wasip2_string_t *ptr; - size_t len; -} wasip2_list_string_t; - -typedef struct { - bool is_some; - wasip2_string_t val; -} wasip2_option_string_t; - -typedef struct { - bool is_err; -} exit_result_void_void_t; - -typedef struct io_error_own_error_t { - int32_t __handle; -} io_error_own_error_t; - -typedef struct io_error_borrow_error_t { - int32_t __handle; -} io_error_borrow_error_t; - -typedef struct poll_own_pollable_t { - int32_t __handle; -} poll_own_pollable_t; - -typedef struct poll_borrow_pollable_t { - int32_t __handle; -} poll_borrow_pollable_t; - -typedef struct { - poll_borrow_pollable_t *ptr; - size_t len; -} poll_list_borrow_pollable_t; - -typedef struct { - uint32_t *ptr; - size_t len; -} wasip2_list_u32_t; - -typedef io_error_own_error_t streams_own_error_t; - -// An error for input-stream and output-stream operations. -typedef struct streams_stream_error_t { - uint8_t tag; - union { - streams_own_error_t last_operation_failed; - } val; -} streams_stream_error_t; - -// The last operation (a write or flush) failed before completion. -// -// More information is available in the `error` payload. -#define STREAMS_STREAM_ERROR_LAST_OPERATION_FAILED 0 -// The stream is closed: no more input will be accepted by the -// stream. A closed output-stream will return this error on all -// future operations. -#define STREAMS_STREAM_ERROR_CLOSED 1 - -typedef struct streams_own_input_stream_t { - int32_t __handle; -} streams_own_input_stream_t; - -typedef struct streams_borrow_input_stream_t { - int32_t __handle; -} streams_borrow_input_stream_t; - -typedef struct streams_own_output_stream_t { - int32_t __handle; -} streams_own_output_stream_t; - -typedef struct streams_borrow_output_stream_t { - int32_t __handle; -} streams_borrow_output_stream_t; - -typedef struct { - uint8_t *ptr; - size_t len; -} wasip2_list_u8_t; - -typedef struct { - bool is_err; - union { - wasip2_list_u8_t ok; - streams_stream_error_t err; - } val; -} streams_result_list_u8_stream_error_t; - -typedef struct { - bool is_err; - union { - uint64_t ok; - streams_stream_error_t err; - } val; -} streams_result_u64_stream_error_t; - -typedef poll_own_pollable_t streams_own_pollable_t; - -typedef struct { - bool is_err; - union { - streams_stream_error_t err; - } val; -} streams_result_void_stream_error_t; - -typedef streams_own_input_stream_t stdin_own_input_stream_t; - -typedef streams_own_output_stream_t stdout_own_output_stream_t; - -typedef streams_own_output_stream_t stderr_own_output_stream_t; - -typedef struct terminal_input_own_terminal_input_t { - int32_t __handle; -} terminal_input_own_terminal_input_t; - -typedef struct terminal_input_borrow_terminal_input_t { - int32_t __handle; -} terminal_input_borrow_terminal_input_t; - -typedef struct terminal_output_own_terminal_output_t { - int32_t __handle; -} terminal_output_own_terminal_output_t; - -typedef struct terminal_output_borrow_terminal_output_t { - int32_t __handle; -} terminal_output_borrow_terminal_output_t; - -typedef terminal_input_own_terminal_input_t terminal_stdin_own_terminal_input_t; - -typedef struct { - bool is_some; - terminal_stdin_own_terminal_input_t val; -} terminal_stdin_option_own_terminal_input_t; - -typedef terminal_output_own_terminal_output_t terminal_stdout_own_terminal_output_t; - -typedef struct { - bool is_some; - terminal_stdout_own_terminal_output_t val; -} terminal_stdout_option_own_terminal_output_t; - -typedef terminal_output_own_terminal_output_t terminal_stderr_own_terminal_output_t; - -typedef struct { - bool is_some; - terminal_stderr_own_terminal_output_t val; -} terminal_stderr_option_own_terminal_output_t; - -// An instant in time, in nanoseconds. An instant is relative to an -// unspecified initial value, and can only be compared to instances from -// the same monotonic-clock. -typedef uint64_t monotonic_clock_instant_t; - -// A duration of time, in nanoseconds. -typedef uint64_t monotonic_clock_duration_t; - -typedef poll_own_pollable_t monotonic_clock_own_pollable_t; - -// A time and date in seconds plus nanoseconds. -typedef struct wall_clock_datetime_t { - uint64_t seconds; - uint32_t nanoseconds; -} wall_clock_datetime_t; - -typedef wall_clock_datetime_t filesystem_datetime_t; - -// File size or length of a region within a file. -typedef uint64_t filesystem_filesize_t; - -// The type of a filesystem object referenced by a descriptor. -// -// Note: This was called `filetype` in earlier versions of WASI. -typedef uint8_t filesystem_descriptor_type_t; - -// The type of the descriptor or file is unknown or is different from -// any of the other types specified. -#define FILESYSTEM_DESCRIPTOR_TYPE_UNKNOWN 0 -// The descriptor refers to a block device inode. -#define FILESYSTEM_DESCRIPTOR_TYPE_BLOCK_DEVICE 1 -// The descriptor refers to a character device inode. -#define FILESYSTEM_DESCRIPTOR_TYPE_CHARACTER_DEVICE 2 -// The descriptor refers to a directory inode. -#define FILESYSTEM_DESCRIPTOR_TYPE_DIRECTORY 3 -// The descriptor refers to a named pipe. -#define FILESYSTEM_DESCRIPTOR_TYPE_FIFO 4 -// The file refers to a symbolic link inode. -#define FILESYSTEM_DESCRIPTOR_TYPE_SYMBOLIC_LINK 5 -// The descriptor refers to a regular file inode. -#define FILESYSTEM_DESCRIPTOR_TYPE_REGULAR_FILE 6 -// The descriptor refers to a socket. -#define FILESYSTEM_DESCRIPTOR_TYPE_SOCKET 7 - -// Descriptor flags. -// -// Note: This was called `fdflags` in earlier versions of WASI. -typedef uint8_t filesystem_descriptor_flags_t; - -// Read mode: Data can be read. -#define FILESYSTEM_DESCRIPTOR_FLAGS_READ (1 << 0) -// Write mode: Data can be written to. -#define FILESYSTEM_DESCRIPTOR_FLAGS_WRITE (1 << 1) -// Request that writes be performed according to synchronized I/O file -// integrity completion. The data stored in the file and the file's -// metadata are synchronized. This is similar to `O_SYNC` in POSIX. -// -// The precise semantics of this operation have not yet been defined for -// WASI. At this time, it should be interpreted as a request, and not a -// requirement. -#define FILESYSTEM_DESCRIPTOR_FLAGS_FILE_INTEGRITY_SYNC (1 << 2) -// Request that writes be performed according to synchronized I/O data -// integrity completion. Only the data stored in the file is -// synchronized. This is similar to `O_DSYNC` in POSIX. -// -// The precise semantics of this operation have not yet been defined for -// WASI. At this time, it should be interpreted as a request, and not a -// requirement. -#define FILESYSTEM_DESCRIPTOR_FLAGS_DATA_INTEGRITY_SYNC (1 << 3) -// Requests that reads be performed at the same level of integrety -// requested for writes. This is similar to `O_RSYNC` in POSIX. -// -// The precise semantics of this operation have not yet been defined for -// WASI. At this time, it should be interpreted as a request, and not a -// requirement. -#define FILESYSTEM_DESCRIPTOR_FLAGS_REQUESTED_WRITE_SYNC (1 << 4) -// Mutating directories mode: Directory contents may be mutated. -// -// When this flag is unset on a descriptor, operations using the -// descriptor which would create, rename, delete, modify the data or -// metadata of filesystem objects, or obtain another handle which -// would permit any of those, shall fail with `error-code::read-only` if -// they would otherwise succeed. -// -// This may only be set on directories. -#define FILESYSTEM_DESCRIPTOR_FLAGS_MUTATE_DIRECTORY (1 << 5) - -// Flags determining the method of how paths are resolved. -typedef uint8_t filesystem_path_flags_t; - -// As long as the resolved path corresponds to a symbolic link, it is -// expanded. -#define FILESYSTEM_PATH_FLAGS_SYMLINK_FOLLOW (1 << 0) - -// Open flags used by `open-at`. -typedef uint8_t filesystem_open_flags_t; - -// Create file if it does not exist, similar to `O_CREAT` in POSIX. -#define FILESYSTEM_OPEN_FLAGS_CREATE (1 << 0) -// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. -#define FILESYSTEM_OPEN_FLAGS_DIRECTORY (1 << 1) -// Fail if file already exists, similar to `O_EXCL` in POSIX. -#define FILESYSTEM_OPEN_FLAGS_EXCLUSIVE (1 << 2) -// Truncate file to size 0, similar to `O_TRUNC` in POSIX. -#define FILESYSTEM_OPEN_FLAGS_TRUNCATE (1 << 3) - -// Number of hard links to an inode. -typedef uint64_t filesystem_link_count_t; - -typedef struct { - bool is_some; - filesystem_datetime_t val; -} filesystem_option_datetime_t; - -// File attributes. -// -// Note: This was called `filestat` in earlier versions of WASI. -typedef struct filesystem_descriptor_stat_t { - // File type. - filesystem_descriptor_type_t type; - // Number of hard links to the file. - filesystem_link_count_t link_count; - // For regular files, the file size in bytes. For symbolic links, the - // length in bytes of the pathname contained in the symbolic link. - filesystem_filesize_t size; - // Last data access timestamp. - // - // If the `option` is none, the platform doesn't maintain an access - // timestamp for this file. - filesystem_option_datetime_t data_access_timestamp; - // Last data modification timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // modification timestamp for this file. - filesystem_option_datetime_t data_modification_timestamp; - // Last file status-change timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // status-change timestamp for this file. - filesystem_option_datetime_t status_change_timestamp; -} filesystem_descriptor_stat_t; - -// When setting a timestamp, this gives the value to set it to. -typedef struct filesystem_new_timestamp_t { - uint8_t tag; - union { - filesystem_datetime_t timestamp; - } val; -} filesystem_new_timestamp_t; - -// Leave the timestamp set to its previous value. -#define FILESYSTEM_NEW_TIMESTAMP_NO_CHANGE 0 -// Set the timestamp to the current time of the system clock associated -// with the filesystem. -#define FILESYSTEM_NEW_TIMESTAMP_NOW 1 -// Set the timestamp to the given value. -#define FILESYSTEM_NEW_TIMESTAMP_TIMESTAMP 2 - -// A directory entry. -typedef struct filesystem_directory_entry_t { - // The type of the file referred to by this directory entry. - filesystem_descriptor_type_t type; - // The name of the object. - wasip2_string_t name; -} filesystem_directory_entry_t; - -// Error codes returned by functions, similar to `errno` in POSIX. -// Not all of these error codes are returned by the functions provided by this -// API; some are used in higher-level library layers, and others are provided -// merely for alignment with POSIX. -typedef uint8_t filesystem_error_code_t; - -// Permission denied, similar to `EACCES` in POSIX. -#define FILESYSTEM_ERROR_CODE_ACCESS 0 -// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. -#define FILESYSTEM_ERROR_CODE_WOULD_BLOCK 1 -// Connection already in progress, similar to `EALREADY` in POSIX. -#define FILESYSTEM_ERROR_CODE_ALREADY 2 -// Bad descriptor, similar to `EBADF` in POSIX. -#define FILESYSTEM_ERROR_CODE_BAD_DESCRIPTOR 3 -// Device or resource busy, similar to `EBUSY` in POSIX. -#define FILESYSTEM_ERROR_CODE_BUSY 4 -// Resource deadlock would occur, similar to `EDEADLK` in POSIX. -#define FILESYSTEM_ERROR_CODE_DEADLOCK 5 -// Storage quota exceeded, similar to `EDQUOT` in POSIX. -#define FILESYSTEM_ERROR_CODE_QUOTA 6 -// File exists, similar to `EEXIST` in POSIX. -#define FILESYSTEM_ERROR_CODE_EXIST 7 -// File too large, similar to `EFBIG` in POSIX. -#define FILESYSTEM_ERROR_CODE_FILE_TOO_LARGE 8 -// Illegal byte sequence, similar to `EILSEQ` in POSIX. -#define FILESYSTEM_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE 9 -// Operation in progress, similar to `EINPROGRESS` in POSIX. -#define FILESYSTEM_ERROR_CODE_IN_PROGRESS 10 -// Interrupted function, similar to `EINTR` in POSIX. -#define FILESYSTEM_ERROR_CODE_INTERRUPTED 11 -// Invalid argument, similar to `EINVAL` in POSIX. -#define FILESYSTEM_ERROR_CODE_INVALID 12 -// I/O error, similar to `EIO` in POSIX. -#define FILESYSTEM_ERROR_CODE_IO 13 -// Is a directory, similar to `EISDIR` in POSIX. -#define FILESYSTEM_ERROR_CODE_IS_DIRECTORY 14 -// Too many levels of symbolic links, similar to `ELOOP` in POSIX. -#define FILESYSTEM_ERROR_CODE_LOOP 15 -// Too many links, similar to `EMLINK` in POSIX. -#define FILESYSTEM_ERROR_CODE_TOO_MANY_LINKS 16 -// Message too large, similar to `EMSGSIZE` in POSIX. -#define FILESYSTEM_ERROR_CODE_MESSAGE_SIZE 17 -// Filename too long, similar to `ENAMETOOLONG` in POSIX. -#define FILESYSTEM_ERROR_CODE_NAME_TOO_LONG 18 -// No such device, similar to `ENODEV` in POSIX. -#define FILESYSTEM_ERROR_CODE_NO_DEVICE 19 -// No such file or directory, similar to `ENOENT` in POSIX. -#define FILESYSTEM_ERROR_CODE_NO_ENTRY 20 -// No locks available, similar to `ENOLCK` in POSIX. -#define FILESYSTEM_ERROR_CODE_NO_LOCK 21 -// Not enough space, similar to `ENOMEM` in POSIX. -#define FILESYSTEM_ERROR_CODE_INSUFFICIENT_MEMORY 22 -// No space left on device, similar to `ENOSPC` in POSIX. -#define FILESYSTEM_ERROR_CODE_INSUFFICIENT_SPACE 23 -// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. -#define FILESYSTEM_ERROR_CODE_NOT_DIRECTORY 24 -// Directory not empty, similar to `ENOTEMPTY` in POSIX. -#define FILESYSTEM_ERROR_CODE_NOT_EMPTY 25 -// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. -#define FILESYSTEM_ERROR_CODE_NOT_RECOVERABLE 26 -// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. -#define FILESYSTEM_ERROR_CODE_UNSUPPORTED 27 -// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. -#define FILESYSTEM_ERROR_CODE_NO_TTY 28 -// No such device or address, similar to `ENXIO` in POSIX. -#define FILESYSTEM_ERROR_CODE_NO_SUCH_DEVICE 29 -// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. -#define FILESYSTEM_ERROR_CODE_OVERFLOW 30 -// Operation not permitted, similar to `EPERM` in POSIX. -#define FILESYSTEM_ERROR_CODE_NOT_PERMITTED 31 -// Broken pipe, similar to `EPIPE` in POSIX. -#define FILESYSTEM_ERROR_CODE_PIPE 32 -// Read-only file system, similar to `EROFS` in POSIX. -#define FILESYSTEM_ERROR_CODE_READ_ONLY 33 -// Invalid seek, similar to `ESPIPE` in POSIX. -#define FILESYSTEM_ERROR_CODE_INVALID_SEEK 34 -// Text file busy, similar to `ETXTBSY` in POSIX. -#define FILESYSTEM_ERROR_CODE_TEXT_FILE_BUSY 35 -// Cross-device link, similar to `EXDEV` in POSIX. -#define FILESYSTEM_ERROR_CODE_CROSS_DEVICE 36 - -// File or memory access pattern advisory information. -typedef uint8_t filesystem_advice_t; - -// The application has no advice to give on its behavior with respect -// to the specified data. -#define FILESYSTEM_ADVICE_NORMAL 0 -// The application expects to access the specified data sequentially -// from lower offsets to higher offsets. -#define FILESYSTEM_ADVICE_SEQUENTIAL 1 -// The application expects to access the specified data in a random -// order. -#define FILESYSTEM_ADVICE_RANDOM 2 -// The application expects to access the specified data in the near -// future. -#define FILESYSTEM_ADVICE_WILL_NEED 3 -// The application expects that it will not access the specified data -// in the near future. -#define FILESYSTEM_ADVICE_DONT_NEED 4 -// The application expects to access the specified data once and then -// not reuse it thereafter. -#define FILESYSTEM_ADVICE_NO_REUSE 5 - -// A 128-bit hash value, split into parts because wasm doesn't have a -// 128-bit integer type. -typedef struct filesystem_metadata_hash_value_t { - // 64 bits of a 128-bit hash value. - uint64_t lower; - // Another 64 bits of a 128-bit hash value. - uint64_t upper; -} filesystem_metadata_hash_value_t; - -typedef struct filesystem_own_descriptor_t { - int32_t __handle; -} filesystem_own_descriptor_t; - -typedef struct filesystem_borrow_descriptor_t { - int32_t __handle; -} filesystem_borrow_descriptor_t; - -typedef struct filesystem_own_directory_entry_stream_t { - int32_t __handle; -} filesystem_own_directory_entry_stream_t; - -typedef struct filesystem_borrow_directory_entry_stream_t { - int32_t __handle; -} filesystem_borrow_directory_entry_stream_t; - -typedef streams_own_input_stream_t filesystem_own_input_stream_t; - -typedef struct { - bool is_err; - union { - filesystem_own_input_stream_t ok; - filesystem_error_code_t err; - } val; -} filesystem_result_own_input_stream_error_code_t; - -typedef streams_own_output_stream_t filesystem_own_output_stream_t; - -typedef struct { - bool is_err; - union { - filesystem_own_output_stream_t ok; - filesystem_error_code_t err; - } val; -} filesystem_result_own_output_stream_error_code_t; - -typedef struct { - bool is_err; - union { - filesystem_error_code_t err; - } val; -} filesystem_result_void_error_code_t; - -typedef struct { - bool is_err; - union { - filesystem_descriptor_flags_t ok; - filesystem_error_code_t err; - } val; -} filesystem_result_descriptor_flags_error_code_t; - -typedef struct { - bool is_err; - union { - filesystem_descriptor_type_t ok; - filesystem_error_code_t err; - } val; -} filesystem_result_descriptor_type_error_code_t; - -typedef struct { - wasip2_list_u8_t f0; - bool f1; -} wasip2_tuple2_list_u8_bool_t; - -typedef struct { - bool is_err; - union { - wasip2_tuple2_list_u8_bool_t ok; - filesystem_error_code_t err; - } val; -} filesystem_result_tuple2_list_u8_bool_error_code_t; - -typedef struct { - bool is_err; - union { - filesystem_filesize_t ok; - filesystem_error_code_t err; - } val; -} filesystem_result_filesize_error_code_t; - -typedef struct { - bool is_err; - union { - filesystem_own_directory_entry_stream_t ok; - filesystem_error_code_t err; - } val; -} filesystem_result_own_directory_entry_stream_error_code_t; - -typedef struct { - bool is_err; - union { - filesystem_descriptor_stat_t ok; - filesystem_error_code_t err; - } val; -} filesystem_result_descriptor_stat_error_code_t; - -typedef struct { - bool is_err; - union { - filesystem_own_descriptor_t ok; - filesystem_error_code_t err; - } val; -} filesystem_result_own_descriptor_error_code_t; - -typedef struct { - bool is_err; - union { - wasip2_string_t ok; - filesystem_error_code_t err; - } val; -} filesystem_result_string_error_code_t; - -typedef struct { - bool is_err; - union { - filesystem_metadata_hash_value_t ok; - filesystem_error_code_t err; - } val; -} filesystem_result_metadata_hash_value_error_code_t; - -typedef struct { - bool is_some; - filesystem_directory_entry_t val; -} filesystem_option_directory_entry_t; - -typedef struct { - bool is_err; - union { - filesystem_option_directory_entry_t ok; - filesystem_error_code_t err; - } val; -} filesystem_result_option_directory_entry_error_code_t; - -typedef io_error_borrow_error_t filesystem_borrow_error_t; - -typedef struct { - bool is_some; - filesystem_error_code_t val; -} filesystem_option_error_code_t; - -typedef filesystem_own_descriptor_t filesystem_preopens_own_descriptor_t; - -typedef struct { - filesystem_preopens_own_descriptor_t f0; - wasip2_string_t f1; -} filesystem_preopens_tuple2_own_descriptor_string_t; - -typedef struct { - filesystem_preopens_tuple2_own_descriptor_string_t *ptr; - size_t len; -} filesystem_preopens_list_tuple2_own_descriptor_string_t; - -typedef struct network_own_network_t { - int32_t __handle; -} network_own_network_t; - -typedef struct network_borrow_network_t { - int32_t __handle; -} network_borrow_network_t; - -// Error codes. -// -// In theory, every API can return any error code. -// In practice, API's typically only return the errors documented per API -// combined with a couple of errors that are always possible: -// - `unknown` -// - `access-denied` -// - `not-supported` -// - `out-of-memory` -// - `concurrency-conflict` -// -// See each individual API for what the POSIX equivalents are. They sometimes differ per API. -typedef uint8_t network_error_code_t; - -// Unknown error -#define NETWORK_ERROR_CODE_UNKNOWN 0 -// Access denied. -// -// POSIX equivalent: EACCES, EPERM -#define NETWORK_ERROR_CODE_ACCESS_DENIED 1 -// The operation is not supported. -// -// POSIX equivalent: EOPNOTSUPP -#define NETWORK_ERROR_CODE_NOT_SUPPORTED 2 -// One of the arguments is invalid. -// -// POSIX equivalent: EINVAL -#define NETWORK_ERROR_CODE_INVALID_ARGUMENT 3 -// Not enough memory to complete the operation. -// -// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY -#define NETWORK_ERROR_CODE_OUT_OF_MEMORY 4 -// The operation timed out before it could finish completely. -#define NETWORK_ERROR_CODE_TIMEOUT 5 -// This operation is incompatible with another asynchronous operation that is already in progress. -// -// POSIX equivalent: EALREADY -#define NETWORK_ERROR_CODE_CONCURRENCY_CONFLICT 6 -// Trying to finish an asynchronous operation that: -// - has not been started yet, or: -// - was already finished by a previous `finish-*` call. -// -// Note: this is scheduled to be removed when `future`s are natively supported. -#define NETWORK_ERROR_CODE_NOT_IN_PROGRESS 7 -// The operation has been aborted because it could not be completed immediately. -// -// Note: this is scheduled to be removed when `future`s are natively supported. -#define NETWORK_ERROR_CODE_WOULD_BLOCK 8 -// The operation is not valid in the socket's current state. -#define NETWORK_ERROR_CODE_INVALID_STATE 9 -// A new socket resource could not be created because of a system limit. -#define NETWORK_ERROR_CODE_NEW_SOCKET_LIMIT 10 -// A bind operation failed because the provided address is not an address that the `network` can bind to. -#define NETWORK_ERROR_CODE_ADDRESS_NOT_BINDABLE 11 -// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. -#define NETWORK_ERROR_CODE_ADDRESS_IN_USE 12 -// The remote address is not reachable -#define NETWORK_ERROR_CODE_REMOTE_UNREACHABLE 13 -// The TCP connection was forcefully rejected -#define NETWORK_ERROR_CODE_CONNECTION_REFUSED 14 -// The TCP connection was reset. -#define NETWORK_ERROR_CODE_CONNECTION_RESET 15 -// A TCP connection was aborted. -#define NETWORK_ERROR_CODE_CONNECTION_ABORTED 16 -// The size of a datagram sent to a UDP socket exceeded the maximum -// supported size. -#define NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE 17 -// Name does not exist or has no suitable associated IP addresses. -#define NETWORK_ERROR_CODE_NAME_UNRESOLVABLE 18 -// A temporary failure in name resolution occurred. -#define NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE 19 -// A permanent failure in name resolution occurred. -#define NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE 20 - -typedef uint8_t network_ip_address_family_t; - -// Similar to `AF_INET` in POSIX. -#define NETWORK_IP_ADDRESS_FAMILY_IPV4 0 -// Similar to `AF_INET6` in POSIX. -#define NETWORK_IP_ADDRESS_FAMILY_IPV6 1 - -typedef struct network_ipv4_address_t { - uint8_t f0; - uint8_t f1; - uint8_t f2; - uint8_t f3; -} network_ipv4_address_t; - -typedef struct network_ipv6_address_t { - uint16_t f0; - uint16_t f1; - uint16_t f2; - uint16_t f3; - uint16_t f4; - uint16_t f5; - uint16_t f6; - uint16_t f7; -} network_ipv6_address_t; - -typedef struct network_ip_address_t { - uint8_t tag; - union { - network_ipv4_address_t ipv4; - network_ipv6_address_t ipv6; - } val; -} network_ip_address_t; - -#define NETWORK_IP_ADDRESS_IPV4 0 -#define NETWORK_IP_ADDRESS_IPV6 1 - -typedef struct network_ipv4_socket_address_t { - // sin_port - uint16_t port; - // sin_addr - network_ipv4_address_t address; -} network_ipv4_socket_address_t; - -typedef struct network_ipv6_socket_address_t { - // sin6_port - uint16_t port; - // sin6_flowinfo - uint32_t flow_info; - // sin6_addr - network_ipv6_address_t address; - // sin6_scope_id - uint32_t scope_id; -} network_ipv6_socket_address_t; - -typedef struct network_ip_socket_address_t { - uint8_t tag; - union { - network_ipv4_socket_address_t ipv4; - network_ipv6_socket_address_t ipv6; - } val; -} network_ip_socket_address_t; - -#define NETWORK_IP_SOCKET_ADDRESS_IPV4 0 -#define NETWORK_IP_SOCKET_ADDRESS_IPV6 1 - -typedef network_own_network_t instance_network_own_network_t; - -typedef network_error_code_t udp_error_code_t; - -typedef network_ip_socket_address_t udp_ip_socket_address_t; - -typedef network_ip_address_family_t udp_ip_address_family_t; - -// A received datagram. -typedef struct udp_incoming_datagram_t { - // The payload. - // - // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. - wasip2_list_u8_t data; - // The source address. - // - // This field is guaranteed to match the remote address the stream was initialized with, if any. - // - // Equivalent to the `src_addr` out parameter of `recvfrom`. - udp_ip_socket_address_t remote_address; -} udp_incoming_datagram_t; - -typedef struct { - bool is_some; - udp_ip_socket_address_t val; -} udp_option_ip_socket_address_t; - -// A datagram to be sent out. -typedef struct udp_outgoing_datagram_t { - // The payload. - wasip2_list_u8_t data; - // The destination address. - // - // The requirements on this field depend on how the stream was initialized: - // - with a remote address: this field must be None or match the stream's remote address exactly. - // - without a remote address: this field is required. - // - // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`. - udp_option_ip_socket_address_t remote_address; -} udp_outgoing_datagram_t; - -typedef struct udp_own_udp_socket_t { - int32_t __handle; -} udp_own_udp_socket_t; - -typedef struct udp_borrow_udp_socket_t { - int32_t __handle; -} udp_borrow_udp_socket_t; - -typedef struct udp_own_incoming_datagram_stream_t { - int32_t __handle; -} udp_own_incoming_datagram_stream_t; - -typedef struct udp_borrow_incoming_datagram_stream_t { - int32_t __handle; -} udp_borrow_incoming_datagram_stream_t; - -typedef struct udp_own_outgoing_datagram_stream_t { - int32_t __handle; -} udp_own_outgoing_datagram_stream_t; - -typedef struct udp_borrow_outgoing_datagram_stream_t { - int32_t __handle; -} udp_borrow_outgoing_datagram_stream_t; - -typedef network_borrow_network_t udp_borrow_network_t; - -typedef struct { - bool is_err; - union { - udp_error_code_t err; - } val; -} udp_result_void_error_code_t; - -typedef struct { - udp_own_incoming_datagram_stream_t f0; - udp_own_outgoing_datagram_stream_t f1; -} udp_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_t; - -typedef struct { - bool is_err; - union { - udp_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_t ok; - udp_error_code_t err; - } val; -} udp_result_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_error_code_t; - -typedef struct { - bool is_err; - union { - udp_ip_socket_address_t ok; - udp_error_code_t err; - } val; -} udp_result_ip_socket_address_error_code_t; - -typedef struct { - bool is_err; - union { - uint8_t ok; - udp_error_code_t err; - } val; -} udp_result_u8_error_code_t; - -typedef struct { - bool is_err; - union { - uint64_t ok; - udp_error_code_t err; - } val; -} udp_result_u64_error_code_t; - -typedef poll_own_pollable_t udp_own_pollable_t; - -typedef struct { - udp_incoming_datagram_t *ptr; - size_t len; -} udp_list_incoming_datagram_t; - -typedef struct { - bool is_err; - union { - udp_list_incoming_datagram_t ok; - udp_error_code_t err; - } val; -} udp_result_list_incoming_datagram_error_code_t; - -typedef struct { - udp_outgoing_datagram_t *ptr; - size_t len; -} udp_list_outgoing_datagram_t; - -typedef network_error_code_t udp_create_socket_error_code_t; - -typedef network_ip_address_family_t udp_create_socket_ip_address_family_t; - -typedef udp_own_udp_socket_t udp_create_socket_own_udp_socket_t; - -typedef struct { - bool is_err; - union { - udp_create_socket_own_udp_socket_t ok; - udp_create_socket_error_code_t err; - } val; -} udp_create_socket_result_own_udp_socket_error_code_t; - -typedef monotonic_clock_duration_t tcp_duration_t; - -typedef network_error_code_t tcp_error_code_t; - -typedef network_ip_socket_address_t tcp_ip_socket_address_t; - -typedef network_ip_address_family_t tcp_ip_address_family_t; - -typedef uint8_t tcp_shutdown_type_t; - -// Similar to `SHUT_RD` in POSIX. -#define TCP_SHUTDOWN_TYPE_RECEIVE 0 -// Similar to `SHUT_WR` in POSIX. -#define TCP_SHUTDOWN_TYPE_SEND 1 -// Similar to `SHUT_RDWR` in POSIX. -#define TCP_SHUTDOWN_TYPE_BOTH 2 - -typedef struct tcp_own_tcp_socket_t { - int32_t __handle; -} tcp_own_tcp_socket_t; - -typedef struct tcp_borrow_tcp_socket_t { - int32_t __handle; -} tcp_borrow_tcp_socket_t; - -typedef network_borrow_network_t tcp_borrow_network_t; - -typedef struct { - bool is_err; - union { - tcp_error_code_t err; - } val; -} tcp_result_void_error_code_t; - -typedef streams_own_input_stream_t tcp_own_input_stream_t; - -typedef streams_own_output_stream_t tcp_own_output_stream_t; - -typedef struct { - tcp_own_input_stream_t f0; - tcp_own_output_stream_t f1; -} tcp_tuple2_own_input_stream_own_output_stream_t; - -typedef struct { - bool is_err; - union { - tcp_tuple2_own_input_stream_own_output_stream_t ok; - tcp_error_code_t err; - } val; -} tcp_result_tuple2_own_input_stream_own_output_stream_error_code_t; +#ifndef __WASI_WASIP2_H +#define __WASI_WASIP2_H -typedef struct { - tcp_own_tcp_socket_t f0; - tcp_own_input_stream_t f1; - tcp_own_output_stream_t f2; -} tcp_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t; +#include -typedef struct { - bool is_err; - union { - tcp_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t ok; - tcp_error_code_t err; - } val; -} tcp_result_tuple3_own_tcp_socket_own_input_stream_own_output_stream_error_code_t; - -typedef struct { - bool is_err; - union { - tcp_ip_socket_address_t ok; - tcp_error_code_t err; - } val; -} tcp_result_ip_socket_address_error_code_t; - -typedef struct { - bool is_err; - union { - bool ok; - tcp_error_code_t err; - } val; -} tcp_result_bool_error_code_t; - -typedef struct { - bool is_err; - union { - tcp_duration_t ok; - tcp_error_code_t err; - } val; -} tcp_result_duration_error_code_t; - -typedef struct { - bool is_err; - union { - uint32_t ok; - tcp_error_code_t err; - } val; -} tcp_result_u32_error_code_t; - -typedef struct { - bool is_err; - union { - uint8_t ok; - tcp_error_code_t err; - } val; -} tcp_result_u8_error_code_t; - -typedef struct { - bool is_err; - union { - uint64_t ok; - tcp_error_code_t err; - } val; -} tcp_result_u64_error_code_t; - -typedef poll_own_pollable_t tcp_own_pollable_t; - -typedef network_error_code_t tcp_create_socket_error_code_t; - -typedef network_ip_address_family_t tcp_create_socket_ip_address_family_t; - -typedef tcp_own_tcp_socket_t tcp_create_socket_own_tcp_socket_t; - -typedef struct { - bool is_err; - union { - tcp_create_socket_own_tcp_socket_t ok; - tcp_create_socket_error_code_t err; - } val; -} tcp_create_socket_result_own_tcp_socket_error_code_t; - -typedef network_error_code_t ip_name_lookup_error_code_t; - -typedef network_ip_address_t ip_name_lookup_ip_address_t; - -typedef struct ip_name_lookup_own_resolve_address_stream_t { - int32_t __handle; -} ip_name_lookup_own_resolve_address_stream_t; - -typedef struct ip_name_lookup_borrow_resolve_address_stream_t { - int32_t __handle; -} ip_name_lookup_borrow_resolve_address_stream_t; - -typedef network_borrow_network_t ip_name_lookup_borrow_network_t; - -typedef struct { - bool is_err; - union { - ip_name_lookup_own_resolve_address_stream_t ok; - ip_name_lookup_error_code_t err; - } val; -} ip_name_lookup_result_own_resolve_address_stream_error_code_t; - -typedef struct { - bool is_some; - ip_name_lookup_ip_address_t val; -} ip_name_lookup_option_ip_address_t; - -typedef struct { - bool is_err; - union { - ip_name_lookup_option_ip_address_t ok; - ip_name_lookup_error_code_t err; - } val; -} ip_name_lookup_result_option_ip_address_error_code_t; - -typedef poll_own_pollable_t ip_name_lookup_own_pollable_t; - -typedef struct { - uint64_t f0; - uint64_t f1; -} wasip2_tuple2_u64_u64_t; - -// Imported Functions from `wasi:cli/environment@0.2.0` -// Get the POSIX-style environment variables. -// -// Each environment variable is provided as a pair of string variable names -// and string value. -// -// Morally, these are a value import, but until value imports are available -// in the component model, this import function should return the same -// values each time it is called. -extern void environment_get_environment(wasip2_list_tuple2_string_string_t *ret); -// Get the POSIX-style arguments to the program. -extern void environment_get_arguments(wasip2_list_string_t *ret); -// Return a path that programs should use as their initial current working -// directory, interpreting `.` as shorthand for this. -extern bool environment_initial_cwd(wasip2_string_t *ret); - -// Imported Functions from `wasi:cli/exit@0.2.0` -// Exit the current instance and any linked instances. -_Noreturn extern void exit_exit(exit_result_void_void_t *status); - -// Imported Functions from `wasi:io/error@0.2.0` -// Returns a string that is suitable to assist humans in debugging -// this error. -// -// WARNING: The returned string should not be consumed mechanically! -// It may change across platforms, hosts, or other implementation -// details. Parsing this string is a major platform-compatibility -// hazard. -extern void io_error_method_error_to_debug_string(io_error_borrow_error_t self, wasip2_string_t *ret); - -// Imported Functions from `wasi:io/poll@0.2.0` -// Return the readiness of a pollable. This function never blocks. -// -// Returns `true` when the pollable is ready, and `false` otherwise. -extern bool poll_method_pollable_ready(poll_borrow_pollable_t self); -// `block` returns immediately if the pollable is ready, and otherwise -// blocks until ready. -// -// This function is equivalent to calling `poll.poll` on a list -// containing only this pollable. -extern void poll_method_pollable_block(poll_borrow_pollable_t self); -// Poll for completion on a set of pollables. -// -// This function takes a list of pollables, which identify I/O sources of -// interest, and waits until one or more of the events is ready for I/O. -// -// The result `list` contains one or more indices of handles in the -// argument list that is ready for I/O. -// -// If the list contains more elements than can be indexed with a `u32` -// value, this function traps. -// -// A timeout can be implemented by adding a pollable from the -// wasi-clocks API to the list. -// -// This function does not return a `result`; polling in itself does not -// do any I/O so it doesn't fail. If any of the I/O sources identified by -// the pollables has an error, it is indicated by marking the source as -// being reaedy for I/O. -extern void poll_poll(poll_list_borrow_pollable_t *in, wasip2_list_u32_t *ret); - -// Imported Functions from `wasi:io/streams@0.2.0` -// Perform a non-blocking read from the stream. -// -// When the source of a `read` is binary data, the bytes from the source -// are returned verbatim. When the source of a `read` is known to the -// implementation to be text, bytes containing the UTF-8 encoding of the -// text are returned. -// -// This function returns a list of bytes containing the read data, -// when successful. The returned list will contain up to `len` bytes; -// it may return fewer than requested, but not more. The list is -// empty when no bytes are available for reading at this time. The -// pollable given by `subscribe` will be ready when more bytes are -// available. -// -// This function fails with a `stream-error` when the operation -// encounters an error, giving `last-operation-failed`, or when the -// stream is closed, giving `closed`. -// -// When the caller gives a `len` of 0, it represents a request to -// read 0 bytes. If the stream is still open, this call should -// succeed and return an empty list, or otherwise fail with `closed`. -// -// The `len` parameter is a `u64`, which could represent a list of u8 which -// is not possible to allocate in wasm32, or not desirable to allocate as -// as a return value by the callee. The callee may return a list of bytes -// less than `len` in size while more bytes are available for reading. -extern bool streams_method_input_stream_read(streams_borrow_input_stream_t self, uint64_t len, wasip2_list_u8_t *ret, streams_stream_error_t *err); -// Read bytes from a stream, after blocking until at least one byte can -// be read. Except for blocking, behavior is identical to `read`. -extern bool streams_method_input_stream_blocking_read(streams_borrow_input_stream_t self, uint64_t len, wasip2_list_u8_t *ret, streams_stream_error_t *err); -// Skip bytes from a stream. Returns number of bytes skipped. -// -// Behaves identical to `read`, except instead of returning a list -// of bytes, returns the number of bytes consumed from the stream. -extern bool streams_method_input_stream_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err); -// Skip bytes from a stream, after blocking until at least one byte -// can be skipped. Except for blocking behavior, identical to `skip`. -extern bool streams_method_input_stream_blocking_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err); -// Create a `pollable` which will resolve once either the specified stream -// has bytes available to read or the other end of the stream has been -// closed. -// The created `pollable` is a child resource of the `input-stream`. -// Implementations may trap if the `input-stream` is dropped before -// all derived `pollable`s created with this function are dropped. -extern streams_own_pollable_t streams_method_input_stream_subscribe(streams_borrow_input_stream_t self); -// Check readiness for writing. This function never blocks. -// -// Returns the number of bytes permitted for the next call to `write`, -// or an error. Calling `write` with more bytes than this function has -// permitted will trap. -// -// When this function returns 0 bytes, the `subscribe` pollable will -// become ready when this function will report at least 1 byte, or an -// error. -extern bool streams_method_output_stream_check_write(streams_borrow_output_stream_t self, uint64_t *ret, streams_stream_error_t *err); -// Perform a write. This function never blocks. -// -// When the destination of a `write` is binary data, the bytes from -// `contents` are written verbatim. When the destination of a `write` is -// known to the implementation to be text, the bytes of `contents` are -// transcoded from UTF-8 into the encoding of the destination and then -// written. -// -// Precondition: check-write gave permit of Ok(n) and contents has a -// length of less than or equal to n. Otherwise, this function will trap. -// -// returns Err(closed) without writing if the stream has closed since -// the last call to check-write provided a permit. -extern bool streams_method_output_stream_write(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err); -// Perform a write of up to 4096 bytes, and then flush the stream. Block -// until all of these operations are complete, or an error occurs. -// -// This is a convenience wrapper around the use of `check-write`, -// `subscribe`, `write`, and `flush`, and is implemented with the -// following pseudo-code: -// -// ```text -// let pollable = this.subscribe(); -// while !contents.is_empty() { -// // Wait for the stream to become writable -// pollable.block(); -// let Ok(n) = this.check-write(); // eliding error handling -// let len = min(n, contents.len()); -// let (chunk, rest) = contents.split_at(len); -// this.write(chunk ); // eliding error handling -// contents = rest; -// } -// this.flush(); -// // Wait for completion of `flush` -// pollable.block(); -// // Check for any errors that arose during `flush` -// let _ = this.check-write(); // eliding error handling -// ``` -extern bool streams_method_output_stream_blocking_write_and_flush(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err); -// Request to flush buffered output. This function never blocks. -// -// This tells the output-stream that the caller intends any buffered -// output to be flushed. the output which is expected to be flushed -// is all that has been passed to `write` prior to this call. -// -// Upon calling this function, the `output-stream` will not accept any -// writes (`check-write` will return `ok(0)`) until the flush has -// completed. The `subscribe` pollable will become ready when the -// flush has completed and the stream can accept more writes. -extern bool streams_method_output_stream_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err); -// Request to flush buffered output, and block until flush completes -// and stream is ready for writing again. -extern bool streams_method_output_stream_blocking_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err); -// Create a `pollable` which will resolve once the output-stream -// is ready for more writing, or an error has occured. When this -// pollable is ready, `check-write` will return `ok(n)` with n>0, or an -// error. -// -// If the stream is closed, this pollable is always ready immediately. -// -// The created `pollable` is a child resource of the `output-stream`. -// Implementations may trap if the `output-stream` is dropped before -// all derived `pollable`s created with this function are dropped. -extern streams_own_pollable_t streams_method_output_stream_subscribe(streams_borrow_output_stream_t self); -// Write zeroes to a stream. -// -// This should be used precisely like `write` with the exact same -// preconditions (must use check-write first), but instead of -// passing a list of bytes, you simply pass the number of zero-bytes -// that should be written. -extern bool streams_method_output_stream_write_zeroes(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err); -// Perform a write of up to 4096 zeroes, and then flush the stream. -// Block until all of these operations are complete, or an error -// occurs. -// -// This is a convenience wrapper around the use of `check-write`, -// `subscribe`, `write-zeroes`, and `flush`, and is implemented with -// the following pseudo-code: -// -// ```text -// let pollable = this.subscribe(); -// while num_zeroes != 0 { -// // Wait for the stream to become writable -// pollable.block(); -// let Ok(n) = this.check-write(); // eliding error handling -// let len = min(n, num_zeroes); -// this.write-zeroes(len); // eliding error handling -// num_zeroes -= len; -// } -// this.flush(); -// // Wait for completion of `flush` -// pollable.block(); -// // Check for any errors that arose during `flush` -// let _ = this.check-write(); // eliding error handling -// ``` -extern bool streams_method_output_stream_blocking_write_zeroes_and_flush(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err); -// Read from one stream and write to another. -// -// The behavior of splice is equivelant to: -// 1. calling `check-write` on the `output-stream` -// 2. calling `read` on the `input-stream` with the smaller of the -// `check-write` permitted length and the `len` provided to `splice` -// 3. calling `write` on the `output-stream` with that read data. -// -// Any error reported by the call to `check-write`, `read`, or -// `write` ends the splice and reports that error. -// -// This function returns the number of bytes transferred; it may be less -// than `len`. -extern bool streams_method_output_stream_splice(streams_borrow_output_stream_t self, streams_borrow_input_stream_t src, uint64_t len, uint64_t *ret, streams_stream_error_t *err); -// Read from one stream and write to another, with blocking. -// -// This is similar to `splice`, except that it blocks until the -// `output-stream` is ready for writing, and the `input-stream` -// is ready for reading, before performing the `splice`. -extern bool streams_method_output_stream_blocking_splice(streams_borrow_output_stream_t self, streams_borrow_input_stream_t src, uint64_t len, uint64_t *ret, streams_stream_error_t *err); - -// Imported Functions from `wasi:cli/stdin@0.2.0` -extern stdin_own_input_stream_t stdin_get_stdin(void); - -// Imported Functions from `wasi:cli/stdout@0.2.0` -extern stdout_own_output_stream_t stdout_get_stdout(void); - -// Imported Functions from `wasi:cli/stderr@0.2.0` -extern stderr_own_output_stream_t stderr_get_stderr(void); - -// Imported Functions from `wasi:cli/terminal-stdin@0.2.0` -// If stdin is connected to a terminal, return a `terminal-input` handle -// allowing further interaction with it. -extern bool terminal_stdin_get_terminal_stdin(terminal_stdin_own_terminal_input_t *ret); - -// Imported Functions from `wasi:cli/terminal-stdout@0.2.0` -// If stdout is connected to a terminal, return a `terminal-output` handle -// allowing further interaction with it. -extern bool terminal_stdout_get_terminal_stdout(terminal_stdout_own_terminal_output_t *ret); - -// Imported Functions from `wasi:cli/terminal-stderr@0.2.0` -// If stderr is connected to a terminal, return a `terminal-output` handle -// allowing further interaction with it. -extern bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t *ret); - -// Imported Functions from `wasi:clocks/monotonic-clock@0.2.0` -// Read the current value of the clock. -// -// The clock is monotonic, therefore calling this function repeatedly will -// produce a sequence of non-decreasing values. -extern monotonic_clock_instant_t monotonic_clock_now(void); -// Query the resolution of the clock. Returns the duration of time -// corresponding to a clock tick. -extern monotonic_clock_duration_t monotonic_clock_resolution(void); -// Create a `pollable` which will resolve once the specified instant -// occured. -extern monotonic_clock_own_pollable_t monotonic_clock_subscribe_instant(monotonic_clock_instant_t when); -// Create a `pollable` which will resolve once the given duration has -// elapsed, starting at the time at which this function was called. -// occured. -extern monotonic_clock_own_pollable_t monotonic_clock_subscribe_duration(monotonic_clock_duration_t when); - -// Imported Functions from `wasi:clocks/wall-clock@0.2.0` -// Read the current value of the clock. -// -// This clock is not monotonic, therefore calling this function repeatedly -// will not necessarily produce a sequence of non-decreasing values. -// -// The returned timestamps represent the number of seconds since -// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], -// also known as [Unix Time]. -// -// The nanoseconds field of the output is always less than 1000000000. -// -// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 -// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time -extern void wall_clock_now(wall_clock_datetime_t *ret); -// Query the resolution of the clock. -// -// The nanoseconds field of the output is always less than 1000000000. -extern void wall_clock_resolution(wall_clock_datetime_t *ret); - -// Imported Functions from `wasi:filesystem/types@0.2.0` -// Return a stream for reading from a file, if available. -// -// May fail with an error-code describing why the file cannot be read. -// -// Multiple read, write, and append streams may be active on the same open -// file and they do not interfere with each other. -// -// Note: This allows using `read-stream`, which is similar to `read` in POSIX. -extern bool filesystem_method_descriptor_read_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_own_input_stream_t *ret, filesystem_error_code_t *err); -// Return a stream for writing to a file, if available. -// -// May fail with an error-code describing why the file cannot be written. -// -// Note: This allows using `write-stream`, which is similar to `write` in -// POSIX. -extern bool filesystem_method_descriptor_write_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_own_output_stream_t *ret, filesystem_error_code_t *err); -// Return a stream for appending to a file, if available. -// -// May fail with an error-code describing why the file cannot be appended. -// -// Note: This allows using `write-stream`, which is similar to `write` with -// `O_APPEND` in in POSIX. -extern bool filesystem_method_descriptor_append_via_stream(filesystem_borrow_descriptor_t self, filesystem_own_output_stream_t *ret, filesystem_error_code_t *err); -// Provide file advisory information on a descriptor. -// -// This is similar to `posix_fadvise` in POSIX. -extern bool filesystem_method_descriptor_advise(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_filesize_t length, filesystem_advice_t advice, filesystem_error_code_t *err); -// Synchronize the data of a file to disk. -// -// This function succeeds with no effect if the file descriptor is not -// opened for writing. -// -// Note: This is similar to `fdatasync` in POSIX. -extern bool filesystem_method_descriptor_sync_data(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err); -// Get flags associated with a descriptor. -// -// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. -// -// Note: This returns the value that was the `fs_flags` value returned -// from `fdstat_get` in earlier versions of WASI. -extern bool filesystem_method_descriptor_get_flags(filesystem_borrow_descriptor_t self, filesystem_descriptor_flags_t *ret, filesystem_error_code_t *err); -// Get the dynamic type of a descriptor. -// -// Note: This returns the same value as the `type` field of the `fd-stat` -// returned by `stat`, `stat-at` and similar. -// -// Note: This returns similar flags to the `st_mode & S_IFMT` value provided -// by `fstat` in POSIX. -// -// Note: This returns the value that was the `fs_filetype` value returned -// from `fdstat_get` in earlier versions of WASI. -extern bool filesystem_method_descriptor_get_type(filesystem_borrow_descriptor_t self, filesystem_descriptor_type_t *ret, filesystem_error_code_t *err); -// Adjust the size of an open file. If this increases the file's size, the -// extra bytes are filled with zeros. -// -// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. -extern bool filesystem_method_descriptor_set_size(filesystem_borrow_descriptor_t self, filesystem_filesize_t size, filesystem_error_code_t *err); -// Adjust the timestamps of an open file or directory. -// -// Note: This is similar to `futimens` in POSIX. -// -// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. -extern bool filesystem_method_descriptor_set_times(filesystem_borrow_descriptor_t self, filesystem_new_timestamp_t *data_access_timestamp, filesystem_new_timestamp_t *data_modification_timestamp, filesystem_error_code_t *err); -// Read from a descriptor, without using and updating the descriptor's offset. -// -// This function returns a list of bytes containing the data that was -// read, along with a bool which, when true, indicates that the end of the -// file was reached. The returned list will contain up to `length` bytes; it -// may return fewer than requested, if the end of the file is reached or -// if the I/O operation is interrupted. -// -// In the future, this may change to return a `stream`. -// -// Note: This is similar to `pread` in POSIX. -extern bool filesystem_method_descriptor_read(filesystem_borrow_descriptor_t self, filesystem_filesize_t length, filesystem_filesize_t offset, wasip2_tuple2_list_u8_bool_t *ret, filesystem_error_code_t *err); -// Write to a descriptor, without using and updating the descriptor's offset. -// -// It is valid to write past the end of a file; the file is extended to the -// extent of the write, with bytes between the previous end and the start of -// the write set to zero. -// -// In the future, this may change to take a `stream`. -// -// Note: This is similar to `pwrite` in POSIX. -extern bool filesystem_method_descriptor_write(filesystem_borrow_descriptor_t self, wasip2_list_u8_t *buffer, filesystem_filesize_t offset, filesystem_filesize_t *ret, filesystem_error_code_t *err); -// Read directory entries from a directory. -// -// On filesystems where directories contain entries referring to themselves -// and their parents, often named `.` and `..` respectively, these entries -// are omitted. -// -// This always returns a new stream which starts at the beginning of the -// directory. Multiple streams may be active on the same directory, and they -// do not interfere with each other. -extern bool filesystem_method_descriptor_read_directory(filesystem_borrow_descriptor_t self, filesystem_own_directory_entry_stream_t *ret, filesystem_error_code_t *err); -// Synchronize the data and metadata of a file to disk. -// -// This function succeeds with no effect if the file descriptor is not -// opened for writing. -// -// Note: This is similar to `fsync` in POSIX. -extern bool filesystem_method_descriptor_sync(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err); -// Create a directory. -// -// Note: This is similar to `mkdirat` in POSIX. -extern bool filesystem_method_descriptor_create_directory_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); -// Return the attributes of an open file or directory. -// -// Note: This is similar to `fstat` in POSIX, except that it does not return -// device and inode information. For testing whether two descriptors refer to -// the same underlying filesystem object, use `is-same-object`. To obtain -// additional data that can be used do determine whether a file has been -// modified, use `metadata-hash`. -// -// Note: This was called `fd_filestat_get` in earlier versions of WASI. -extern bool filesystem_method_descriptor_stat(filesystem_borrow_descriptor_t self, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err); -// Return the attributes of a file or directory. -// -// Note: This is similar to `fstatat` in POSIX, except that it does not -// return device and inode information. See the `stat` description for a -// discussion of alternatives. -// -// Note: This was called `path_filestat_get` in earlier versions of WASI. -extern bool filesystem_method_descriptor_stat_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err); -// Adjust the timestamps of a file or directory. -// -// Note: This is similar to `utimensat` in POSIX. -// -// Note: This was called `path_filestat_set_times` in earlier versions of -// WASI. -extern bool filesystem_method_descriptor_set_times_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_new_timestamp_t *data_access_timestamp, filesystem_new_timestamp_t *data_modification_timestamp, filesystem_error_code_t *err); -// Create a hard link. -// -// Note: This is similar to `linkat` in POSIX. -extern bool filesystem_method_descriptor_link_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t old_path_flags, wasip2_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, wasip2_string_t *new_path, filesystem_error_code_t *err); -// Open a file or directory. -// -// The returned descriptor is not guaranteed to be the lowest-numbered -// 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 descriptor is -// guaranteed to be less than 2**31. -// -// If `flags` contains `descriptor-flags::mutate-directory`, and the base -// descriptor doesn't have `descriptor-flags::mutate-directory` set, -// `open-at` fails with `error-code::read-only`. -// -// If `flags` contains `write` or `mutate-directory`, or `open-flags` -// contains `truncate` or `create`, and the base descriptor doesn't have -// `descriptor-flags::mutate-directory` set, `open-at` fails with -// `error-code::read-only`. -// -// Note: This is similar to `openat` in POSIX. -extern bool filesystem_method_descriptor_open_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_open_flags_t open_flags, filesystem_descriptor_flags_t flags, filesystem_own_descriptor_t *ret, filesystem_error_code_t *err); -// Read the contents of a symbolic link. -// -// If the contents contain an absolute or rooted path in the underlying -// filesystem, this function fails with `error-code::not-permitted`. -// -// Note: This is similar to `readlinkat` in POSIX. -extern bool filesystem_method_descriptor_readlink_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, wasip2_string_t *ret, filesystem_error_code_t *err); -// Remove a directory. -// -// Return `error-code::not-empty` if the directory is not empty. -// -// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. -extern bool filesystem_method_descriptor_remove_directory_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); -// Rename a filesystem object. -// -// Note: This is similar to `renameat` in POSIX. -extern bool filesystem_method_descriptor_rename_at(filesystem_borrow_descriptor_t self, wasip2_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, wasip2_string_t *new_path, filesystem_error_code_t *err); -// Create a symbolic link (also known as a "symlink"). -// -// If `old-path` starts with `/`, the function fails with -// `error-code::not-permitted`. -// -// Note: This is similar to `symlinkat` in POSIX. -extern bool filesystem_method_descriptor_symlink_at(filesystem_borrow_descriptor_t self, wasip2_string_t *old_path, wasip2_string_t *new_path, filesystem_error_code_t *err); -// Unlink a filesystem object that is not a directory. -// -// Return `error-code::is-directory` if the path refers to a directory. -// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. -extern bool filesystem_method_descriptor_unlink_file_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); -// Test whether two descriptors refer to the same filesystem object. -// -// In POSIX, this corresponds to testing whether the two descriptors have the -// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. -// wasi-filesystem does not expose device and inode numbers, so this function -// may be used instead. -extern bool filesystem_method_descriptor_is_same_object(filesystem_borrow_descriptor_t self, filesystem_borrow_descriptor_t other); -// Return a hash of the metadata associated with a filesystem object referred -// to by a descriptor. -// -// This returns a hash of the last-modification timestamp and file size, and -// may also include the inode number, device number, birth timestamp, and -// other metadata fields that may change when the file is modified or -// replaced. It may also include a secret value chosen by the -// implementation and not otherwise exposed. -// -// Implementations are encourated to provide the following properties: -// -// - If the file is not modified or replaced, the computed hash value should -// usually not change. -// - If the object is modified or replaced, the computed hash value should -// usually change. -// - The inputs to the hash should not be easily computable from the -// computed hash. -// -// However, none of these is required. -extern bool filesystem_method_descriptor_metadata_hash(filesystem_borrow_descriptor_t self, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err); -// Return a hash of the metadata associated with a filesystem object referred -// to by a directory descriptor and a relative path. -// -// This performs the same hash computation as `metadata-hash`. -extern bool filesystem_method_descriptor_metadata_hash_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err); -// Read a single directory entry from a `directory-entry-stream`. -extern bool filesystem_method_directory_entry_stream_read_directory_entry(filesystem_borrow_directory_entry_stream_t self, filesystem_option_directory_entry_t *ret, filesystem_error_code_t *err); -// Attempts to extract a filesystem-related `error-code` from the stream -// `error` provided. -// -// Stream operations which return `stream-error::last-operation-failed` -// have a payload with more information about the operation that failed. -// This payload can be passed through to this function to see if there's -// filesystem-related information about the error to return. -// -// Note that this function is fallible because not all stream-related -// errors are filesystem-related errors. -extern bool filesystem_filesystem_error_code(filesystem_borrow_error_t err_, filesystem_error_code_t *ret); - -// Imported Functions from `wasi:filesystem/preopens@0.2.0` -// Return the set of preopened directories, and their path. -extern void filesystem_preopens_get_directories(filesystem_preopens_list_tuple2_own_descriptor_string_t *ret); - -// Imported Functions from `wasi:sockets/instance-network@0.2.0` -// Get a handle to the default network. -extern instance_network_own_network_t instance_network_instance_network(void); - -// Imported Functions from `wasi:sockets/udp@0.2.0` -// Bind the socket to a specific network on the provided IP address and port. -// -// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which -// network interface(s) to bind to. -// If the port is zero, the socket will be bound to a random free port. -// -// # Typical errors -// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) -// - `invalid-state`: The socket is already bound. (EINVAL) -// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) -// - `address-in-use`: Address is already in use. (EADDRINUSE) -// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) -// - `not-in-progress`: A `bind` operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// Unlike in POSIX, in WASI the bind operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `bind` as part of either `start-bind` or `finish-bind`. -// -// # References -// - -// - -// - -// - -extern bool udp_method_udp_socket_start_bind(udp_borrow_udp_socket_t self, udp_borrow_network_t network, udp_ip_socket_address_t *local_address, udp_error_code_t *err); -extern bool udp_method_udp_socket_finish_bind(udp_borrow_udp_socket_t self, udp_error_code_t *err); -// Set up inbound & outbound communication channels, optionally to a specific peer. -// -// This function only changes the local socket configuration and does not generate any network traffic. -// On success, the `remote-address` of the socket is updated. The `local-address` may be updated as well, -// based on the best network path to `remote-address`. -// -// When a `remote-address` is provided, the returned streams are limited to communicating with that specific peer: -// - `send` can only be used to send to this destination. -// - `receive` will only return datagrams sent from the provided `remote-address`. -// -// This method may be called multiple times on the same socket to change its association, but -// only the most recently returned pair of streams will be operational. Implementations may trap if -// the streams returned by a previous invocation haven't been dropped yet before calling `stream` again. -// -// The POSIX equivalent in pseudo-code is: -// ```text -// if (was previously connected) { -// connect(s, AF_UNSPEC) -// } -// if (remote_address is Some) { -// connect(s, remote_address) -// } -// ``` -// -// Unlike in POSIX, the socket must already be explicitly bound. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-state`: The socket is not bound. -// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// -// # References -// - -// - -// - -// - -extern bool udp_method_udp_socket_stream(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *maybe_remote_address, udp_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_t *ret, udp_error_code_t *err); -// Get the current bound address. -// -// POSIX mentions: -// > If the socket has not been bound to a local name, the value -// > stored in the object pointed to by `address` is unspecified. -// -// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. -// -// # References -// - -// - -// - -// - -extern bool udp_method_udp_socket_local_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err); -// Get the address the socket is currently streaming to. -// -// # Typical errors -// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) -// -// # References -// - -// - -// - -// - -extern bool udp_method_udp_socket_remote_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err); -// Whether this is a IPv4 or IPv6 socket. -// -// Equivalent to the SO_DOMAIN socket option. -extern udp_ip_address_family_t udp_method_udp_socket_address_family(udp_borrow_udp_socket_t self); -// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// -// # Typical errors -// - `invalid-argument`: (set) The TTL value must be 1 or higher. -extern bool udp_method_udp_socket_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t *ret, udp_error_code_t *err); -extern bool udp_method_udp_socket_set_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t value, udp_error_code_t *err); -// The kernel buffer space reserved for sends/receives on this socket. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -extern bool udp_method_udp_socket_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err); -extern bool udp_method_udp_socket_set_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err); -extern bool udp_method_udp_socket_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err); -extern bool udp_method_udp_socket_set_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err); -// Create a `pollable` which will resolve once the socket is ready for I/O. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -extern udp_own_pollable_t udp_method_udp_socket_subscribe(udp_borrow_udp_socket_t self); -// Receive messages on the socket. -// -// This function attempts to receive up to `max-results` datagrams on the socket without blocking. -// The returned list may contain fewer elements than requested, but never more. -// -// This function returns successfully with an empty list when either: -// - `max-results` is 0, or: -// - `max-results` is greater than 0, but no results are immediately available. -// This function never returns `error(would-block)`. -// -// # Typical errors -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - -extern bool udp_method_incoming_datagram_stream_receive(udp_borrow_incoming_datagram_stream_t self, uint64_t max_results, udp_list_incoming_datagram_t *ret, udp_error_code_t *err); -// Create a `pollable` which will resolve once the stream is ready to receive again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -extern udp_own_pollable_t udp_method_incoming_datagram_stream_subscribe(udp_borrow_incoming_datagram_stream_t self); -// Check readiness for sending. This function never blocks. -// -// Returns the number of datagrams permitted for the next call to `send`, -// or an error. Calling `send` with more datagrams than this function has -// permitted will trap. -// -// When this function returns ok(0), the `subscribe` pollable will -// become ready when this function will report at least ok(1), or an -// error. -// -// Never returns `would-block`. -extern bool udp_method_outgoing_datagram_stream_check_send(udp_borrow_outgoing_datagram_stream_t self, uint64_t *ret, udp_error_code_t *err); -// Send messages on the socket. -// -// This function attempts to send all provided `datagrams` on the socket without blocking and -// returns how many messages were actually sent (or queued for sending). This function never -// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned. -// -// This function semantically behaves the same as iterating the `datagrams` list and sequentially -// sending each individual datagram until either the end of the list has been reached or the first error occurred. -// If at least one datagram has been sent successfully, this function never returns an error. -// -// If the input list is empty, the function returns `ok(0)`. -// -// Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if -// either `check-send` was not called or `datagrams` contains more items than `check-send` permitted. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN) -// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ) -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - -extern bool udp_method_outgoing_datagram_stream_send(udp_borrow_outgoing_datagram_stream_t self, udp_list_outgoing_datagram_t *datagrams, uint64_t *ret, udp_error_code_t *err); -// Create a `pollable` which will resolve once the stream is ready to send again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -extern udp_own_pollable_t udp_method_outgoing_datagram_stream_subscribe(udp_borrow_outgoing_datagram_stream_t self); - -// Imported Functions from `wasi:sockets/udp-create-socket@0.2.0` -// Create a new UDP socket. -// -// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX. -// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. -// -// This function does not require a network capability handle. This is considered to be safe because -// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind` is called, -// the socket is effectively an in-memory configuration object, unable to communicate with the outside world. -// -// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. -// -// # Typical errors -// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) -// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) -// -// # References: -// - -// - -// - -// - -extern bool udp_create_socket_create_udp_socket(udp_create_socket_ip_address_family_t address_family, udp_create_socket_own_udp_socket_t *ret, udp_create_socket_error_code_t *err); - -// Imported Functions from `wasi:sockets/tcp@0.2.0` -// Bind the socket to a specific network on the provided IP address and port. -// -// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which -// network interface(s) to bind to. -// If the TCP/UDP port is zero, the socket will be bound to a random free port. -// -// Bind can be attempted multiple times on the same socket, even with -// different arguments on each iteration. But never concurrently and -// only as long as the previous bind failed. Once a bind succeeds, the -// binding can't be changed anymore. -// -// # Typical errors -// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) -// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) -// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL) -// - `invalid-state`: The socket is already bound. (EINVAL) -// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) -// - `address-in-use`: Address is already in use. (EADDRINUSE) -// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) -// - `not-in-progress`: A `bind` operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT -// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR -// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior -// and SO_REUSEADDR performs something different entirely. -// -// Unlike in POSIX, in WASI the bind operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `bind` as part of either `start-bind` or `finish-bind`. -// -// # References -// - -// - -// - -// - -extern bool tcp_method_tcp_socket_start_bind(tcp_borrow_tcp_socket_t self, tcp_borrow_network_t network, tcp_ip_socket_address_t *local_address, tcp_error_code_t *err); -extern bool tcp_method_tcp_socket_finish_bind(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); -// Connect to a remote endpoint. -// -// On success: -// - the socket is transitioned into the `connection` state. -// - a pair of streams is returned that can be used to read & write to the connection -// -// After a failed connection attempt, the socket will be in the `closed` -// state and the only valid action left is to `drop` the socket. A single -// socket can not be used to connect more than once. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) -// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) -// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows) -// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. -// - `invalid-state`: The socket is already in the `connected` state. (EISCONN) -// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows) -// - `timeout`: Connection timed out. (ETIMEDOUT) -// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) -// - `connection-reset`: The connection was reset. (ECONNRESET) -// - `connection-aborted`: The connection was aborted. (ECONNABORTED) -// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) -// - `not-in-progress`: A connect operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// The POSIX equivalent of `start-connect` is the regular `connect` syscall. -// Because all WASI sockets are non-blocking this is expected to return -// EINPROGRESS, which should be translated to `ok()` in WASI. -// -// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` -// with a timeout of 0 on the socket descriptor. Followed by a check for -// the `SO_ERROR` socket option, in case the poll signaled readiness. -// -// # References -// - -// - -// - -// - -extern bool tcp_method_tcp_socket_start_connect(tcp_borrow_tcp_socket_t self, tcp_borrow_network_t network, tcp_ip_socket_address_t *remote_address, tcp_error_code_t *err); -extern bool tcp_method_tcp_socket_finish_connect(tcp_borrow_tcp_socket_t self, tcp_tuple2_own_input_stream_own_output_stream_t *ret, tcp_error_code_t *err); -// Start listening for new connections. -// -// Transitions the socket into the `listening` state. -// -// Unlike POSIX, the socket must already be explicitly bound. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) -// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD) -// - `invalid-state`: The socket is already in the `listening` state. -// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE) -// - `not-in-progress`: A listen operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// Unlike in POSIX, in WASI the listen operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `listen` as part of either `start-listen` or `finish-listen`. -// -// # References -// - -// - -// - -// - -extern bool tcp_method_tcp_socket_start_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); -extern bool tcp_method_tcp_socket_finish_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); -// Accept a new client socket. -// -// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket: -// - `address-family` -// - `keep-alive-enabled` -// - `keep-alive-idle-time` -// - `keep-alive-interval` -// - `keep-alive-count` -// - `hop-limit` -// - `receive-buffer-size` -// - `send-buffer-size` -// -// On success, this function returns the newly accepted client socket along with -// a pair of streams that can be used to read & write to the connection. -// -// # Typical errors -// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) -// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) -// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED) -// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) -// -// # References -// - -// - -// - -// - -extern bool tcp_method_tcp_socket_accept(tcp_borrow_tcp_socket_t self, tcp_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ret, tcp_error_code_t *err); -// Get the bound local address. -// -// POSIX mentions: -// > If the socket has not been bound to a local name, the value -// > stored in the object pointed to by `address` is unspecified. -// -// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. -// -// # References -// - -// - -// - -// - -extern bool tcp_method_tcp_socket_local_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err); -// Get the remote address. -// -// # Typical errors -// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) -// -// # References -// - -// - -// - -// - -extern bool tcp_method_tcp_socket_remote_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err); -// Whether the socket is in the `listening` state. -// -// Equivalent to the SO_ACCEPTCONN socket option. -extern bool tcp_method_tcp_socket_is_listening(tcp_borrow_tcp_socket_t self); -// Whether this is a IPv4 or IPv6 socket. -// -// Equivalent to the SO_DOMAIN socket option. -extern tcp_ip_address_family_t tcp_method_tcp_socket_address_family(tcp_borrow_tcp_socket_t self); -// Hints the desired listen queue size. Implementations are free to ignore this. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// -// # Typical errors -// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. -// - `invalid-argument`: (set) The provided value was 0. -// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state. -extern bool tcp_method_tcp_socket_set_listen_backlog_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); -// Enables or disables keepalive. -// -// The keepalive behavior can be adjusted using: -// - `keep-alive-idle-time` -// - `keep-alive-interval` -// - `keep-alive-count` -// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. -// -// Equivalent to the SO_KEEPALIVE socket option. -extern bool tcp_method_tcp_socket_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool *ret, tcp_error_code_t *err); -extern bool tcp_method_tcp_socket_set_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool value, tcp_error_code_t *err); -// Amount of time the connection has to be idle before TCP starts sending keepalive packets. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -extern bool tcp_method_tcp_socket_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err); -extern bool tcp_method_tcp_socket_set_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err); -// The time between keepalive packets. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the TCP_KEEPINTVL socket option. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -extern bool tcp_method_tcp_socket_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err); -extern bool tcp_method_tcp_socket_set_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err); -// The maximum amount of keepalive packets TCP should send before aborting the connection. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the TCP_KEEPCNT socket option. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -extern bool tcp_method_tcp_socket_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t *ret, tcp_error_code_t *err); -extern bool tcp_method_tcp_socket_set_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t value, tcp_error_code_t *err); -// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// -// # Typical errors -// - `invalid-argument`: (set) The TTL value must be 1 or higher. -extern bool tcp_method_tcp_socket_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t *ret, tcp_error_code_t *err); -extern bool tcp_method_tcp_socket_set_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t value, tcp_error_code_t *err); -// The kernel buffer space reserved for sends/receives on this socket. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. -extern bool tcp_method_tcp_socket_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err); -extern bool tcp_method_tcp_socket_set_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); -extern bool tcp_method_tcp_socket_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err); -extern bool tcp_method_tcp_socket_set_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); -// Create a `pollable` which can be used to poll for, or block on, -// completion of any of the asynchronous operations of this socket. -// -// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` -// return `error(would-block)`, this pollable can be used to wait for -// their success or failure, after which the method can be retried. -// -// The pollable is not limited to the async operation that happens to be -// in progress at the time of calling `subscribe` (if any). Theoretically, -// `subscribe` only has to be called once per socket and can then be -// (re)used for the remainder of the socket's lifetime. -// -// See -// for a more information. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -extern tcp_own_pollable_t tcp_method_tcp_socket_subscribe(tcp_borrow_tcp_socket_t self); -// Initiate a graceful shutdown. -// -// - `receive`: The socket is not expecting to receive any data from -// the peer. The `input-stream` associated with this socket will be -// closed. Any data still in the receive queue at time of calling -// this method will be discarded. -// - `send`: The socket has no more data to send to the peer. The `output-stream` -// associated with this socket will be closed and a FIN packet will be sent. -// - `both`: Same effect as `receive` & `send` combined. -// -// This function is idempotent. Shutting a down a direction more than once -// has no effect and returns `ok`. -// -// The shutdown function does not close (drop) the socket. -// -// # Typical errors -// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) -// -// # References -// - -// - -// - -// - -extern bool tcp_method_tcp_socket_shutdown(tcp_borrow_tcp_socket_t self, tcp_shutdown_type_t shutdown_type, tcp_error_code_t *err); - -// Imported Functions from `wasi:sockets/tcp-create-socket@0.2.0` -// Create a new TCP socket. -// -// Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. -// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. -// -// This function does not require a network capability handle. This is considered to be safe because -// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`connect` -// is called, the socket is effectively an in-memory configuration object, unable to communicate with the outside world. -// -// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. -// -// # Typical errors -// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) -// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) -// -// # References -// - -// - -// - -// - -extern bool tcp_create_socket_create_tcp_socket(tcp_create_socket_ip_address_family_t address_family, tcp_create_socket_own_tcp_socket_t *ret, tcp_create_socket_error_code_t *err); - -// Imported Functions from `wasi:sockets/ip-name-lookup@0.2.0` -// Resolve an internet host name to a list of IP addresses. -// -// Unicode domain names are automatically converted to ASCII using IDNA encoding. -// If the input is an IP address string, the address is parsed and returned -// as-is without making any external requests. -// -// See the wasi-socket proposal README.md for a comparison with getaddrinfo. -// -// This function never blocks. It either immediately fails or immediately -// returns successfully with a `resolve-address-stream` that can be used -// to (asynchronously) fetch the results. -// -// # Typical errors -// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. -// -// # References: -// - -// - -// - -// - -extern bool ip_name_lookup_resolve_addresses(ip_name_lookup_borrow_network_t network, wasip2_string_t *name, ip_name_lookup_own_resolve_address_stream_t *ret, ip_name_lookup_error_code_t *err); -// Returns the next address from the resolver. -// -// This function should be called multiple times. On each call, it will -// return the next address in connection order preference. If all -// addresses have been exhausted, this function returns `none`. -// -// This function never returns IPv4-mapped IPv6 addresses. -// -// # Typical errors -// - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) -// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN) -// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL) -// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) -extern bool ip_name_lookup_method_resolve_address_stream_resolve_next_address(ip_name_lookup_borrow_resolve_address_stream_t self, ip_name_lookup_option_ip_address_t *ret, ip_name_lookup_error_code_t *err); -// Create a `pollable` which will resolve once the stream is ready for I/O. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. -extern ip_name_lookup_own_pollable_t ip_name_lookup_method_resolve_address_stream_subscribe(ip_name_lookup_borrow_resolve_address_stream_t self); - -// Imported Functions from `wasi:random/random@0.2.0` -// Return `len` cryptographically-secure random or pseudo-random bytes. -// -// This function must produce data at least as cryptographically secure and -// fast as an adequately seeded cryptographically-secure pseudo-random -// number generator (CSPRNG). It must not block, from the perspective of -// the calling program, under any circumstances, including on the first -// request and on requests for numbers of bytes. The returned data must -// always be unpredictable. -// -// This function must always return fresh data. Deterministic environments -// must omit this function, rather than implementing it with deterministic -// data. -extern void random_get_random_bytes(uint64_t len, wasip2_list_u8_t *ret); -// Return a cryptographically-secure random or pseudo-random `u64` value. -// -// This function returns the same type of data as `get-random-bytes`, -// represented as a `u64`. -extern uint64_t random_get_random_u64(void); - -// Imported Functions from `wasi:random/insecure@0.2.0` -// Return `len` insecure pseudo-random bytes. -// -// This function is not cryptographically secure. Do not use it for -// anything related to security. -// -// There are no requirements on the values of the returned bytes, however -// implementations are encouraged to return evenly distributed values with -// a long period. -extern void random_insecure_get_insecure_random_bytes(uint64_t len, wasip2_list_u8_t *ret); -// Return an insecure pseudo-random `u64` value. -// -// This function returns the same type of pseudo-random data as -// `get-insecure-random-bytes`, represented as a `u64`. -extern uint64_t random_insecure_get_insecure_random_u64(void); - -// Imported Functions from `wasi:random/insecure-seed@0.2.0` -// Return a 128-bit value that may contain a pseudo-random value. -// -// The returned value is not required to be computed from a CSPRNG, and may -// even be entirely deterministic. Host implementations are encouraged to -// provide pseudo-random values to any program exposed to -// attacker-controlled content, to enable DoS protection built into many -// languages' hash-map implementations. -// -// This function is intended to only be called once, by a source language -// to initialize Denial Of Service (DoS) protection in its hash-map -// implementation. -// -// # Expected future evolution -// -// This will likely be changed to a value import, to prevent it from being -// called multiple times and potentially used for purposes other than DoS -// protection. -extern void random_insecure_seed_insecure_seed(wasip2_tuple2_u64_u64_t *ret); - -// Helper Functions - -void wasip2_tuple2_string_string_free(wasip2_tuple2_string_string_t *ptr); - -void wasip2_list_tuple2_string_string_free(wasip2_list_tuple2_string_string_t *ptr); - -void wasip2_list_string_free(wasip2_list_string_t *ptr); - -void wasip2_option_string_free(wasip2_option_string_t *ptr); - -void exit_result_void_void_free(exit_result_void_void_t *ptr); - -extern void io_error_error_drop_own(io_error_own_error_t handle); - -extern io_error_borrow_error_t io_error_borrow_error(io_error_own_error_t handle); - -extern void poll_pollable_drop_own(poll_own_pollable_t handle); - -extern poll_borrow_pollable_t poll_borrow_pollable(poll_own_pollable_t handle); - -void poll_list_borrow_pollable_free(poll_list_borrow_pollable_t *ptr); - -void wasip2_list_u32_free(wasip2_list_u32_t *ptr); - -void streams_stream_error_free(streams_stream_error_t *ptr); - -extern void streams_input_stream_drop_own(streams_own_input_stream_t handle); - -extern streams_borrow_input_stream_t streams_borrow_input_stream(streams_own_input_stream_t handle); - -extern void streams_output_stream_drop_own(streams_own_output_stream_t handle); - -extern streams_borrow_output_stream_t streams_borrow_output_stream(streams_own_output_stream_t handle); - -void wasip2_list_u8_free(wasip2_list_u8_t *ptr); - -void streams_result_list_u8_stream_error_free(streams_result_list_u8_stream_error_t *ptr); - -void streams_result_u64_stream_error_free(streams_result_u64_stream_error_t *ptr); - -void streams_result_void_stream_error_free(streams_result_void_stream_error_t *ptr); - -extern void terminal_input_terminal_input_drop_own(terminal_input_own_terminal_input_t handle); - -extern terminal_input_borrow_terminal_input_t terminal_input_borrow_terminal_input(terminal_input_own_terminal_input_t handle); - -extern void terminal_output_terminal_output_drop_own(terminal_output_own_terminal_output_t handle); - -extern terminal_output_borrow_terminal_output_t terminal_output_borrow_terminal_output(terminal_output_own_terminal_output_t handle); - -void terminal_stdin_option_own_terminal_input_free(terminal_stdin_option_own_terminal_input_t *ptr); - -void terminal_stdout_option_own_terminal_output_free(terminal_stdout_option_own_terminal_output_t *ptr); - -void terminal_stderr_option_own_terminal_output_free(terminal_stderr_option_own_terminal_output_t *ptr); - -void filesystem_option_datetime_free(filesystem_option_datetime_t *ptr); - -void filesystem_descriptor_stat_free(filesystem_descriptor_stat_t *ptr); - -void filesystem_new_timestamp_free(filesystem_new_timestamp_t *ptr); - -void filesystem_directory_entry_free(filesystem_directory_entry_t *ptr); - -extern void filesystem_descriptor_drop_own(filesystem_own_descriptor_t handle); - -extern filesystem_borrow_descriptor_t filesystem_borrow_descriptor(filesystem_own_descriptor_t handle); - -extern void filesystem_directory_entry_stream_drop_own(filesystem_own_directory_entry_stream_t handle); - -extern filesystem_borrow_directory_entry_stream_t filesystem_borrow_directory_entry_stream(filesystem_own_directory_entry_stream_t handle); - -void filesystem_result_own_input_stream_error_code_free(filesystem_result_own_input_stream_error_code_t *ptr); - -void filesystem_result_own_output_stream_error_code_free(filesystem_result_own_output_stream_error_code_t *ptr); - -void filesystem_result_void_error_code_free(filesystem_result_void_error_code_t *ptr); - -void filesystem_result_descriptor_flags_error_code_free(filesystem_result_descriptor_flags_error_code_t *ptr); - -void filesystem_result_descriptor_type_error_code_free(filesystem_result_descriptor_type_error_code_t *ptr); - -void filesystem_result_tuple2_list_u8_bool_error_code_free(filesystem_result_tuple2_list_u8_bool_error_code_t *ptr); - -void filesystem_result_filesize_error_code_free(filesystem_result_filesize_error_code_t *ptr); - -void filesystem_result_own_directory_entry_stream_error_code_free(filesystem_result_own_directory_entry_stream_error_code_t *ptr); - -void filesystem_result_descriptor_stat_error_code_free(filesystem_result_descriptor_stat_error_code_t *ptr); - -void filesystem_result_own_descriptor_error_code_free(filesystem_result_own_descriptor_error_code_t *ptr); - -void filesystem_result_string_error_code_free(filesystem_result_string_error_code_t *ptr); - -void filesystem_result_metadata_hash_value_error_code_free(filesystem_result_metadata_hash_value_error_code_t *ptr); - -void filesystem_option_directory_entry_free(filesystem_option_directory_entry_t *ptr); - -void filesystem_result_option_directory_entry_error_code_free(filesystem_result_option_directory_entry_error_code_t *ptr); - -void filesystem_option_error_code_free(filesystem_option_error_code_t *ptr); - -void filesystem_preopens_tuple2_own_descriptor_string_free(filesystem_preopens_tuple2_own_descriptor_string_t *ptr); - -void filesystem_preopens_list_tuple2_own_descriptor_string_free(filesystem_preopens_list_tuple2_own_descriptor_string_t *ptr); - -extern void network_network_drop_own(network_own_network_t handle); - -extern network_borrow_network_t network_borrow_network(network_own_network_t handle); - -void network_ip_address_free(network_ip_address_t *ptr); - -void network_ip_socket_address_free(network_ip_socket_address_t *ptr); - -void udp_ip_socket_address_free(udp_ip_socket_address_t *ptr); - -void udp_incoming_datagram_free(udp_incoming_datagram_t *ptr); - -void udp_option_ip_socket_address_free(udp_option_ip_socket_address_t *ptr); - -void udp_outgoing_datagram_free(udp_outgoing_datagram_t *ptr); - -extern void udp_udp_socket_drop_own(udp_own_udp_socket_t handle); - -extern udp_borrow_udp_socket_t udp_borrow_udp_socket(udp_own_udp_socket_t handle); - -extern void udp_incoming_datagram_stream_drop_own(udp_own_incoming_datagram_stream_t handle); - -extern udp_borrow_incoming_datagram_stream_t udp_borrow_incoming_datagram_stream(udp_own_incoming_datagram_stream_t handle); - -extern void udp_outgoing_datagram_stream_drop_own(udp_own_outgoing_datagram_stream_t handle); - -extern udp_borrow_outgoing_datagram_stream_t udp_borrow_outgoing_datagram_stream(udp_own_outgoing_datagram_stream_t handle); - -void udp_result_void_error_code_free(udp_result_void_error_code_t *ptr); - -void udp_result_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_error_code_free(udp_result_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_error_code_t *ptr); - -void udp_result_ip_socket_address_error_code_free(udp_result_ip_socket_address_error_code_t *ptr); - -void udp_result_u8_error_code_free(udp_result_u8_error_code_t *ptr); - -void udp_result_u64_error_code_free(udp_result_u64_error_code_t *ptr); - -void udp_list_incoming_datagram_free(udp_list_incoming_datagram_t *ptr); - -void udp_result_list_incoming_datagram_error_code_free(udp_result_list_incoming_datagram_error_code_t *ptr); - -void udp_list_outgoing_datagram_free(udp_list_outgoing_datagram_t *ptr); - -void udp_create_socket_result_own_udp_socket_error_code_free(udp_create_socket_result_own_udp_socket_error_code_t *ptr); - -void tcp_ip_socket_address_free(tcp_ip_socket_address_t *ptr); - -extern void tcp_tcp_socket_drop_own(tcp_own_tcp_socket_t handle); - -extern tcp_borrow_tcp_socket_t tcp_borrow_tcp_socket(tcp_own_tcp_socket_t handle); - -void tcp_result_void_error_code_free(tcp_result_void_error_code_t *ptr); - -void tcp_result_tuple2_own_input_stream_own_output_stream_error_code_free(tcp_result_tuple2_own_input_stream_own_output_stream_error_code_t *ptr); - -void tcp_result_tuple3_own_tcp_socket_own_input_stream_own_output_stream_error_code_free(tcp_result_tuple3_own_tcp_socket_own_input_stream_own_output_stream_error_code_t *ptr); - -void tcp_result_ip_socket_address_error_code_free(tcp_result_ip_socket_address_error_code_t *ptr); - -void tcp_result_bool_error_code_free(tcp_result_bool_error_code_t *ptr); - -void tcp_result_duration_error_code_free(tcp_result_duration_error_code_t *ptr); - -void tcp_result_u32_error_code_free(tcp_result_u32_error_code_t *ptr); - -void tcp_result_u8_error_code_free(tcp_result_u8_error_code_t *ptr); - -void tcp_result_u64_error_code_free(tcp_result_u64_error_code_t *ptr); - -void tcp_create_socket_result_own_tcp_socket_error_code_free(tcp_create_socket_result_own_tcp_socket_error_code_t *ptr); - -void ip_name_lookup_ip_address_free(ip_name_lookup_ip_address_t *ptr); - -extern void ip_name_lookup_resolve_address_stream_drop_own(ip_name_lookup_own_resolve_address_stream_t handle); - -extern ip_name_lookup_borrow_resolve_address_stream_t ip_name_lookup_borrow_resolve_address_stream(ip_name_lookup_own_resolve_address_stream_t handle); - -void ip_name_lookup_result_own_resolve_address_stream_error_code_free(ip_name_lookup_result_own_resolve_address_stream_error_code_t *ptr); - -void ip_name_lookup_option_ip_address_free(ip_name_lookup_option_ip_address_t *ptr); - -void ip_name_lookup_result_option_ip_address_error_code_free(ip_name_lookup_result_option_ip_address_error_code_t *ptr); - -// Sets the string `ret` to reference the input string `s` without copying it -void wasip2_string_set(wasip2_string_t *ret, const char*s); - -// Creates a copy of the input nul-terminated string `s` and -// stores it into the component model string `ret`. -void wasip2_string_dup(wasip2_string_t *ret, const char*s); - -// Deallocates the string pointed to by `ret`, deallocating -// the memory behind the string. -void wasip2_string_free(wasip2_string_t *ret); - -#ifdef __cplusplus -} +#ifdef __wasip2__ +#include #endif + #endif diff --git a/libc-bottom-half/headers/public/wasi/wasip3.h b/libc-bottom-half/headers/public/wasi/wasip3.h new file mode 100644 index 000000000..70d03d2b0 --- /dev/null +++ b/libc-bottom-half/headers/public/wasi/wasip3.h @@ -0,0 +1,10 @@ +#ifndef __WASI_WASIP3_H +#define __WASI_WASIP3_H + +#include + +#ifdef __wasip3__ +#include +#endif + +#endif diff --git a/libc-bottom-half/sources/__main_void.c b/libc-bottom-half/sources/__main_void.c index 6e311114f..880d06233 100644 --- a/libc-bottom-half/sources/__main_void.c +++ b/libc-bottom-half/sources/__main_void.c @@ -67,8 +67,18 @@ __attribute__((__weak__, nodebug)) int __main_void(void) { // Call `__main_argc_argv` with the arguments! return __main_argc_argv(argc, argv); -#elif defined(__wasip2__) - wasip2_list_string_t argument_list; +#elif defined(__wasip2__) || defined(__wasip3__) +#ifdef __wasip2__ + typedef wasip2_list_string_t list_string_t; + typedef wasip2_string_t string_t; +#define list_string_free wasip2_list_string_free +#else + typedef wasip3_list_string_t list_string_t; + typedef wasip3_string_t string_t; +#define list_string_free wasip3_list_string_free +#endif + + list_string_t argument_list; environment_get_arguments(&argument_list); @@ -76,7 +86,7 @@ __attribute__((__weak__, nodebug)) int __main_void(void) { size_t argc = argument_list.len; size_t num_ptrs = argc + 1; if (num_ptrs == 0) { - wasip2_list_string_free(&argument_list); + list_string_free(&argument_list); _Exit(EX_SOFTWARE); } @@ -84,17 +94,17 @@ __attribute__((__weak__, nodebug)) int __main_void(void) { // handle overflow and to initialize the NULL pointer at the end. char **argv = calloc(num_ptrs, sizeof(char *)); if (argv == NULL) { - wasip2_list_string_free(&argument_list); + list_string_free(&argument_list); _Exit(EX_SOFTWARE); } // Copy the arguments for (size_t i = 0; i < argc; i++) { - wasip2_string_t wasi_string = argument_list.ptr[i]; + string_t wasi_string = argument_list.ptr[i]; size_t len = wasi_string.len; argv[i] = malloc(len + 1); if (!argv[i]) { - wasip2_list_string_free(&argument_list); + list_string_free(&argument_list); _Exit(EX_SOFTWARE); } memcpy(argv[i], wasi_string.ptr, len); @@ -102,7 +112,7 @@ __attribute__((__weak__, nodebug)) int __main_void(void) { } // Free the WASI argument list - wasip2_list_string_free(&argument_list); + list_string_free(&argument_list); // Call `__main_argc_argv` with the arguments! return __main_argc_argv(argc, argv); diff --git a/libc-bottom-half/sources/__wasilibc_fd_renumber.c b/libc-bottom-half/sources/__wasilibc_fd_renumber.c index 9d431132d..a21bac63f 100644 --- a/libc-bottom-half/sources/__wasilibc_fd_renumber.c +++ b/libc-bottom-half/sources/__wasilibc_fd_renumber.c @@ -18,7 +18,7 @@ int __wasilibc_fd_renumber(int fd, int newfd) { errno = error; return -1; } -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) if (descriptor_table_renumber(fd, newfd) < 0) return -1; #else @@ -37,7 +37,7 @@ int close(int fd) { errno = error; return -1; } -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) if (descriptor_table_remove(fd) < 0) return -1; #else diff --git a/libc-bottom-half/sources/__wasilibc_initialize_environ.c b/libc-bottom-half/sources/__wasilibc_initialize_environ.c index 08e662e3f..d638965cd 100644 --- a/libc-bottom-half/sources/__wasilibc_initialize_environ.c +++ b/libc-bottom-half/sources/__wasilibc_initialize_environ.c @@ -79,9 +79,18 @@ void __wasilibc_initialize_environ(void) { _Exit(EX_OSERR); software: _Exit(EX_SOFTWARE); -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) +#ifdef __wasip2__ + typedef wasip2_list_tuple2_string_string_t list_tuple2_string_string_t; + typedef wasip2_tuple2_string_string_t tuple2_string_string_t; +#define list_tuple2_string_string_free wasip2_list_tuple2_string_string_free +#else + typedef wasip3_list_tuple2_string_string_t list_tuple2_string_string_t; + typedef wasip3_tuple2_string_string_t tuple2_string_string_t; +#define list_tuple2_string_string_free wasip3_list_tuple2_string_string_free +#endif // Get the environment - wasip2_list_tuple2_string_string_t wasi_environment; + list_tuple2_string_string_t wasi_environment; environment_get_environment(&wasi_environment); size_t environ_count = wasi_environment.len; @@ -102,7 +111,7 @@ void __wasilibc_initialize_environ(void) { // Copy the environment variables for (size_t i = 0; i < environ_count; i++) { - wasip2_tuple2_string_string_t pair = wasi_environment.ptr[i]; + tuple2_string_string_t pair = wasi_environment.ptr[i]; // 1 extra character for the null terminator, 1 for the '=' character environ_ptrs[i] = malloc(pair.f0.len + pair.f1.len + 2); if (!environ_ptrs[i]) { @@ -118,13 +127,13 @@ void __wasilibc_initialize_environ(void) { } // Free the WASI environment list - wasip2_list_tuple2_string_string_free(&wasi_environment); + list_tuple2_string_string_free(&wasi_environment); // Initialize the environment from the created array __wasilibc_environ = environ_ptrs; return; software: - wasip2_list_tuple2_string_string_free(&wasi_environment); + list_tuple2_string_string_free(&wasi_environment); _Exit(EX_SOFTWARE); #else #error "Unsupported WASI version" diff --git a/libc-bottom-half/sources/__wasilibc_random.c b/libc-bottom-half/sources/__wasilibc_random.c index 258465086..054f7c08d 100644 --- a/libc-bottom-half/sources/__wasilibc_random.c +++ b/libc-bottom-half/sources/__wasilibc_random.c @@ -2,16 +2,26 @@ #include #include -#ifdef __wasip2__ +#ifndef __wasip1__ #include #include #include -#include +#include + +#if defined(__wasip2__) +typedef wasip2_list_u8_t list_u8_t; +#define list_u8_free wasip2_list_u8_free +#elif defined(__wasip3__) +typedef wasip3_list_u8_t list_u8_t; +#define list_u8_free wasip3_list_u8_free +#else +#error "Unknown WASI version" +#endif int __wasilibc_random(void *buffer, size_t len) { // Set up a WASI byte list to receive the results - wasip2_list_u8_t wasi_list; + list_u8_t wasi_list; // Get random bytes random_get_random_bytes(len, &wasi_list); @@ -26,7 +36,7 @@ int __wasilibc_random(void *buffer, size_t len) { } // Free the WASI byte list - wasip2_list_u8_free(&wasi_list); + list_u8_free(&wasi_list); return 0; } diff --git a/libc-bottom-half/sources/__wasilibc_real.c b/libc-bottom-half/sources/__wasilibc_real.c index 1c0f71316..7d2f2c06c 100644 --- a/libc-bottom-half/sources/__wasilibc_real.c +++ b/libc-bottom-half/sources/__wasilibc_real.c @@ -12,7 +12,7 @@ #include -#ifndef __wasip2__ +#ifdef __wasip1__ #include #include diff --git a/libc-bottom-half/sources/__wasilibc_rmdirat.c b/libc-bottom-half/sources/__wasilibc_rmdirat.c index 89111a7bf..0c0521828 100644 --- a/libc-bottom-half/sources/__wasilibc_rmdirat.c +++ b/libc-bottom-half/sources/__wasilibc_rmdirat.c @@ -34,6 +34,10 @@ int __wasilibc_nocwd___wasilibc_rmdirat(int fd, const char *path) { translate_error(error_code); return -1; } +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else #error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/sources/__wasilibc_tell.c b/libc-bottom-half/sources/__wasilibc_tell.c index 82c18554c..c8ce2b40a 100644 --- a/libc-bottom-half/sources/__wasilibc_tell.c +++ b/libc-bottom-half/sources/__wasilibc_tell.c @@ -29,6 +29,10 @@ off_t __wasilibc_tell(int fildes) { return -1; } return entry->vtable->seek(entry->data, 0, SEEK_CUR); +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else #error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/sources/__wasilibc_unlinkat.c b/libc-bottom-half/sources/__wasilibc_unlinkat.c index ab73e4e94..415483df6 100644 --- a/libc-bottom-half/sources/__wasilibc_unlinkat.c +++ b/libc-bottom-half/sources/__wasilibc_unlinkat.c @@ -47,6 +47,10 @@ int __wasilibc_nocwd___wasilibc_unlinkat(int fd, const char *path) { } return 0; +#elif defined(__wasip3__) + // TODO(wasip3) + errno = ENOTSUP; + return -1; #else #error "Unknown WASI version" #endif diff --git a/libc-bottom-half/sources/accept-wasip2.c b/libc-bottom-half/sources/accept-wasip2.c deleted file mode 100644 index ed2413b64..000000000 --- a/libc-bottom-half/sources/accept-wasip2.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include - -int accept(int socket, struct sockaddr *restrict addr, - socklen_t *restrict addrlen) -{ - return accept4(socket, addr, addrlen, 0); -} - -int accept4(int socket, struct sockaddr *restrict addr, - socklen_t *restrict addrlen, int flags) -{ - descriptor_table_entry_t *entry = descriptor_table_get_ref(socket); - if (!entry) - return -1; - if (!entry->vtable->accept4) { - errno = EOPNOTSUPP; - return -1; - } - return entry->vtable->accept4(entry->data, addr, addrlen, flags); -} diff --git a/libc-bottom-half/sources/accept.c b/libc-bottom-half/sources/accept.c new file mode 100644 index 000000000..77d718574 --- /dev/null +++ b/libc-bottom-half/sources/accept.c @@ -0,0 +1,20 @@ +#include +#include +#include + +int accept(int socket, struct sockaddr *restrict addr, + socklen_t *restrict addrlen) { + return accept4(socket, addr, addrlen, 0); +} + +int accept4(int socket, struct sockaddr *restrict addr, + socklen_t *restrict addrlen, int flags) { + descriptor_table_entry_t *entry = descriptor_table_get_ref(socket); + if (!entry) + return -1; + if (!entry->vtable->accept4) { + errno = EOPNOTSUPP; + return -1; + } + return entry->vtable->accept4(entry->data, addr, addrlen, flags); +} diff --git a/libc-bottom-half/sources/getentropy.c b/libc-bottom-half/sources/getentropy.c index 8c646eaa0..4bb5b7f49 100644 --- a/libc-bottom-half/sources/getentropy.c +++ b/libc-bottom-half/sources/getentropy.c @@ -11,7 +11,7 @@ int __getentropy(void *buffer, size_t len) { #if defined(__wasip1__) int r = __wasi_random_get(buffer, len); -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) int r = __wasilibc_random(buffer, len); #else #error "Unsupported WASI version" diff --git a/libc-bottom-half/sources/isatty.c b/libc-bottom-half/sources/isatty.c index e91fdab3b..2ac810012 100644 --- a/libc-bottom-half/sources/isatty.c +++ b/libc-bottom-half/sources/isatty.c @@ -1,7 +1,9 @@ #include <__errno.h> #include <__function___isatty.h> +#include #include #include +#include #ifndef __wasip1__ #include @@ -26,7 +28,7 @@ int __isatty(int fd) { } return 1; -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) // Translate the file descriptor into an internal handle descriptor_table_entry_t *entry = descriptor_table_get_ref(fd); if (!entry) diff --git a/libc-bottom-half/sources/preopens.c b/libc-bottom-half/sources/preopens.c index 9419a01b1..cf91ac016 100644 --- a/libc-bottom-half/sources/preopens.c +++ b/libc-bottom-half/sources/preopens.c @@ -15,7 +15,7 @@ #include #include -#ifdef __wasip2__ +#ifndef __wasip1__ #include #include #include @@ -48,7 +48,7 @@ static int preopen_state_get_fd(const preopen_state_t *state) { static void preopen_state_close(preopen_state_t *state) {} -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) typedef struct { int libc_fd; @@ -349,7 +349,7 @@ void __wasilibc_populate_preopens(void) { break; } } -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) filesystem_preopens_list_tuple2_own_descriptor_string_t preopens; filesystem_preopens_get_directories(&preopens); @@ -358,7 +358,11 @@ void __wasilibc_populate_preopens(void) { preopens.ptr[i]; char *prefix = strndup((const char *)name_and_descriptor.f1.ptr, name_and_descriptor.f1.len); +#ifdef __wasip2__ wasip2_string_free(&name_and_descriptor.f1); +#else + wasip3_string_free(&name_and_descriptor.f1); +#endif if (prefix == NULL) { filesystem_descriptor_drop_own(name_and_descriptor.f0); goto software; @@ -380,7 +384,7 @@ void __wasilibc_populate_preopens(void) { UNLOCK(lock); return; -#ifndef __wasip2__ +#ifdef __wasip1__ oserr: _Exit(EX_OSERR); #endif diff --git a/libc-bottom-half/sources/socket.c b/libc-bottom-half/sources/socket.c index 2658f8bc1..104b0ff44 100644 --- a/libc-bottom-half/sources/socket.c +++ b/libc-bottom-half/sources/socket.c @@ -5,10 +5,17 @@ #include #include -static int tcp_socket(network_ip_address_family_t family, bool blocking) { - tcp_create_socket_error_code_t error; - tcp_own_tcp_socket_t socket; - if (!tcp_create_socket_create_tcp_socket(family, &socket, &error)) { +#ifdef __wasip2__ +#define sockets_static_tcp_socket_create tcp_create_socket_create_tcp_socket +#define sockets_static_udp_socket_create udp_create_socket_create_udp_socket +#define SOCKETS_IP_ADDRESS_FAMILY_IPV4 NETWORK_IP_ADDRESS_FAMILY_IPV4 +#define SOCKETS_IP_ADDRESS_FAMILY_IPV6 NETWORK_IP_ADDRESS_FAMILY_IPV6 +#endif + +static int tcp_socket(sockets_ip_address_family_t family, bool blocking) { + sockets_error_code_t error; + sockets_own_tcp_socket_t socket; + if (!sockets_static_tcp_socket_create(family, &socket, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -16,10 +23,10 @@ static int tcp_socket(network_ip_address_family_t family, bool blocking) { return __wasilibc_add_tcp_socket(socket, family, blocking); } -static int udp_socket(network_ip_address_family_t family, bool blocking) { - udp_create_socket_error_code_t error; - udp_own_udp_socket_t socket; - if (!udp_create_socket_create_udp_socket(family, &socket, &error)) { +static int udp_socket(sockets_ip_address_family_t family, bool blocking) { + sockets_error_code_t error; + sockets_own_udp_socket_t socket; + if (!sockets_static_udp_socket_create(family, &socket, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -28,14 +35,14 @@ static int udp_socket(network_ip_address_family_t family, bool blocking) { } int socket(int domain, int type, int protocol) { - network_ip_address_family_t family; + sockets_ip_address_family_t family; switch (domain) { case PF_INET: - family = NETWORK_IP_ADDRESS_FAMILY_IPV4; + family = SOCKETS_IP_ADDRESS_FAMILY_IPV4; break; case PF_INET6: - family = NETWORK_IP_ADDRESS_FAMILY_IPV6; + family = SOCKETS_IP_ADDRESS_FAMILY_IPV6; break; default: diff --git a/libc-bottom-half/sources/sockets_utils.c b/libc-bottom-half/sources/sockets_utils.c index 5fe96dd54..0d51d116f 100644 --- a/libc-bottom-half/sources/sockets_utils.c +++ b/libc-bottom-half/sources/sockets_utils.c @@ -2,10 +2,44 @@ #include #include #include - #include -static network_own_network_t global_network; +// For now favor the naming of wasip3 which uses the "sockets" namespace +// instead of the "network" namespace. The definitions of these types in WIT, +// however, is the same so all that's needed is some renaming here. +#ifdef __wasip2__ +#define SOCKETS_ERROR_CODE_ACCESS_DENIED NETWORK_ERROR_CODE_ACCESS_DENIED +#define SOCKETS_ERROR_CODE_NOT_SUPPORTED NETWORK_ERROR_CODE_NOT_SUPPORTED +#define SOCKETS_ERROR_CODE_INVALID_ARGUMENT NETWORK_ERROR_CODE_INVALID_ARGUMENT +#define SOCKETS_ERROR_CODE_OUT_OF_MEMORY NETWORK_ERROR_CODE_OUT_OF_MEMORY +#define SOCKETS_ERROR_CODE_TIMEOUT NETWORK_ERROR_CODE_TIMEOUT +#define SOCKETS_ERROR_CODE_ADDRESS_NOT_BINDABLE \ + NETWORK_ERROR_CODE_ADDRESS_NOT_BINDABLE +#define SOCKETS_ERROR_CODE_ADDRESS_IN_USE NETWORK_ERROR_CODE_ADDRESS_IN_USE +#define SOCKETS_ERROR_CODE_REMOTE_UNREACHABLE \ + NETWORK_ERROR_CODE_REMOTE_UNREACHABLE +#define SOCKETS_ERROR_CODE_CONNECTION_REFUSED \ + NETWORK_ERROR_CODE_CONNECTION_REFUSED +#define SOCKETS_ERROR_CODE_CONNECTION_RESET NETWORK_ERROR_CODE_CONNECTION_RESET +#define SOCKETS_ERROR_CODE_CONNECTION_ABORTED \ + NETWORK_ERROR_CODE_CONNECTION_ABORTED +#define SOCKETS_ERROR_CODE_DATAGRAM_TOO_LARGE \ + NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE +#define SOCKETS_ERROR_CODE_INVALID_STATE NETWORK_ERROR_CODE_INVALID_STATE +#define SOCKETS_ERROR_CODE_UNKNOWN NETWORK_ERROR_CODE_UNKNOWN + +#define SOCKETS_IP_ADDRESS_FAMILY_IPV4 NETWORK_IP_ADDRESS_FAMILY_IPV4 +#define SOCKETS_IP_ADDRESS_FAMILY_IPV6 NETWORK_IP_ADDRESS_FAMILY_IPV6 +#define SOCKETS_IP_SOCKET_ADDRESS_IPV4 NETWORK_IP_SOCKET_ADDRESS_IPV4 +#define SOCKETS_IP_SOCKET_ADDRESS_IPV6 NETWORK_IP_SOCKET_ADDRESS_IPV6 + +typedef network_ipv4_socket_address_t sockets_ipv4_socket_address_t; +typedef network_ipv4_address_t sockets_ipv4_address_t; +typedef network_ipv6_socket_address_t sockets_ipv6_socket_address_t; +typedef network_ipv6_address_t sockets_ipv6_address_t; +typedef network_ip_socket_address_t sockets_ip_socket_address_t; +#endif + static bool global_network_initialized = false; static const service_entry_t global_services[] = { {"domain", 53, SERVICE_PROTOCOL_TCP | SERVICE_PROTOCOL_UDP}, @@ -29,6 +63,9 @@ static const service_entry_t global_services[] = { }; weak_alias(global_services, __wasi_sockets_services_db); +#ifdef __wasip2__ +static network_own_network_t global_network; + network_borrow_network_t __wasi_sockets_utils__borrow_network() { if (!global_network_initialized) { global_network = instance_network_instance_network(); @@ -37,69 +74,76 @@ network_borrow_network_t __wasi_sockets_utils__borrow_network() { return network_borrow_network(global_network); } +#endif -int __wasi_sockets_utils__map_error(network_error_code_t wasi_error) { +int __wasi_sockets_utils__map_error(sockets_error_code_t wasi_error) { switch (wasi_error) { - case NETWORK_ERROR_CODE_ACCESS_DENIED: + case SOCKETS_ERROR_CODE_ACCESS_DENIED: return EACCES; - case NETWORK_ERROR_CODE_NOT_SUPPORTED: + case SOCKETS_ERROR_CODE_NOT_SUPPORTED: return EOPNOTSUPP; - case NETWORK_ERROR_CODE_INVALID_ARGUMENT: + case SOCKETS_ERROR_CODE_INVALID_ARGUMENT: return EINVAL; - case NETWORK_ERROR_CODE_OUT_OF_MEMORY: + case SOCKETS_ERROR_CODE_OUT_OF_MEMORY: return ENOMEM; - case NETWORK_ERROR_CODE_TIMEOUT: + case SOCKETS_ERROR_CODE_TIMEOUT: return ETIMEDOUT; +#ifdef __wasip2__ case NETWORK_ERROR_CODE_CONCURRENCY_CONFLICT: return EALREADY; case NETWORK_ERROR_CODE_WOULD_BLOCK: return EWOULDBLOCK; case NETWORK_ERROR_CODE_NEW_SOCKET_LIMIT: return EMFILE; - case NETWORK_ERROR_CODE_ADDRESS_NOT_BINDABLE: +#endif + case SOCKETS_ERROR_CODE_ADDRESS_NOT_BINDABLE: return EADDRNOTAVAIL; - case NETWORK_ERROR_CODE_ADDRESS_IN_USE: + case SOCKETS_ERROR_CODE_ADDRESS_IN_USE: return EADDRINUSE; - case NETWORK_ERROR_CODE_REMOTE_UNREACHABLE: + case SOCKETS_ERROR_CODE_REMOTE_UNREACHABLE: return EHOSTUNREACH; - case NETWORK_ERROR_CODE_CONNECTION_REFUSED: + case SOCKETS_ERROR_CODE_CONNECTION_REFUSED: return ECONNREFUSED; - case NETWORK_ERROR_CODE_CONNECTION_RESET: + case SOCKETS_ERROR_CODE_CONNECTION_RESET: return ECONNRESET; - case NETWORK_ERROR_CODE_CONNECTION_ABORTED: + case SOCKETS_ERROR_CODE_CONNECTION_ABORTED: return ECONNABORTED; - case NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE: + case SOCKETS_ERROR_CODE_DATAGRAM_TOO_LARGE: return EMSGSIZE; - case NETWORK_ERROR_CODE_INVALID_STATE: + case SOCKETS_ERROR_CODE_INVALID_STATE: +#ifdef __wasip2__ case NETWORK_ERROR_CODE_NOT_IN_PROGRESS: +#endif abort(); // If our internal state checks are working right, these errors // should never show up. break; +#ifdef __wasip2__ case NETWORK_ERROR_CODE_NAME_UNRESOLVABLE: case NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE: case NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE: abort(); // These errors are specific to getaddrinfo, which should have // filtered these errors out before calling this generic method break; +#endif - case NETWORK_ERROR_CODE_UNKNOWN: + case SOCKETS_ERROR_CODE_UNKNOWN: default: return EOPNOTSUPP; } } bool __wasi_sockets_utils__parse_address( - network_ip_address_family_t expected_family, const struct sockaddr *address, - socklen_t len, network_ip_socket_address_t *result, int *error) { + sockets_ip_address_family_t expected_family, const struct sockaddr *address, + socklen_t len, sockets_ip_socket_address_t *result, int *error) { if (address == NULL || len < sizeof(struct sockaddr)) { *error = EINVAL; return false; } switch (expected_family) { - case NETWORK_IP_ADDRESS_FAMILY_IPV4: { + case SOCKETS_IP_ADDRESS_FAMILY_IPV4: { if (address->sa_family != AF_INET) { *error = EAFNOSUPPORT; return false; @@ -113,8 +157,8 @@ bool __wasi_sockets_utils__parse_address( struct sockaddr_in *ipv4 = (struct sockaddr_in *)address; unsigned ip = ipv4->sin_addr.s_addr; unsigned short port = ipv4->sin_port; - *result = (network_ip_socket_address_t){ - .tag = NETWORK_IP_SOCKET_ADDRESS_IPV4, + *result = (sockets_ip_socket_address_t){ + .tag = SOCKETS_IP_SOCKET_ADDRESS_IPV4, .val = {.ipv4 = { .port = ntohs(port), // (port << 8) | (port >> 8), @@ -124,7 +168,7 @@ bool __wasi_sockets_utils__parse_address( }; return true; } - case NETWORK_IP_ADDRESS_FAMILY_IPV6: { + case SOCKETS_IP_ADDRESS_FAMILY_IPV6: { if (address->sa_family != AF_INET6) { *error = EAFNOSUPPORT; return false; @@ -138,8 +182,8 @@ bool __wasi_sockets_utils__parse_address( struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)address; unsigned char *ip = (unsigned char *)&(ipv6->sin6_addr.s6_addr); unsigned short port = ipv6->sin6_port; - *result = (network_ip_socket_address_t){ - .tag = NETWORK_IP_SOCKET_ADDRESS_IPV6, + *result = (sockets_ip_socket_address_t){ + .tag = SOCKETS_IP_SOCKET_ADDRESS_IPV6, .val = {.ipv6 = { .port = ntohs(port), .address = @@ -165,7 +209,7 @@ bool __wasi_sockets_utils__parse_address( } bool __wasi_sockets_utils__output_addr_validate( - network_ip_address_family_t expected_family, struct sockaddr *addr, + sockets_ip_address_family_t expected_family, struct sockaddr *addr, socklen_t *addrlen, output_sockaddr_t *result) { // The address parameters must be either both null or both _not_ null. @@ -174,7 +218,7 @@ bool __wasi_sockets_utils__output_addr_validate( return true; } else if (addr != NULL && addrlen != NULL) { - if (expected_family == NETWORK_IP_ADDRESS_FAMILY_IPV4) { + if (expected_family == SOCKETS_IP_ADDRESS_FAMILY_IPV4) { if (*addrlen < sizeof(struct sockaddr_in)) { return false; } @@ -186,7 +230,7 @@ bool __wasi_sockets_utils__output_addr_validate( }}; return true; - } else if (expected_family == NETWORK_IP_ADDRESS_FAMILY_IPV6) { + } else if (expected_family == SOCKETS_IP_ADDRESS_FAMILY_IPV6) { if (*addrlen < sizeof(struct sockaddr_in6)) { return false; } @@ -208,15 +252,15 @@ bool __wasi_sockets_utils__output_addr_validate( } void __wasi_sockets_utils__output_addr_write( - const network_ip_socket_address_t input, output_sockaddr_t *output) { + const sockets_ip_socket_address_t input, output_sockaddr_t *output) { switch (input.tag) { - case NETWORK_IP_SOCKET_ADDRESS_IPV4: { + case SOCKETS_IP_SOCKET_ADDRESS_IPV4: { if (output->tag != OUTPUT_SOCKADDR_V4) { abort(); } - network_ipv4_socket_address_t input_v4 = input.val.ipv4; - network_ipv4_address_t ip = input_v4.address; + sockets_ipv4_socket_address_t input_v4 = input.val.ipv4; + sockets_ipv4_address_t ip = input_v4.address; *output->v4.addrlen = sizeof(struct sockaddr_in); *output->v4.addr = (struct sockaddr_in){ @@ -227,13 +271,13 @@ void __wasi_sockets_utils__output_addr_write( }; return; } - case NETWORK_IP_SOCKET_ADDRESS_IPV6: { + case SOCKETS_IP_SOCKET_ADDRESS_IPV6: { if (output->tag != OUTPUT_SOCKADDR_V6) { abort(); } - network_ipv6_socket_address_t input_v6 = input.val.ipv6; - network_ipv6_address_t ip = input_v6.address; + sockets_ipv6_socket_address_t input_v6 = input.val.ipv6; + sockets_ipv6_address_t ip = input_v6.address; *output->v6.addrlen = sizeof(struct sockaddr_in6); *output->v6.addr = (struct sockaddr_in6){ @@ -270,29 +314,29 @@ void __wasi_sockets_utils__output_addr_write( } int __wasi_sockets_utils__posix_family( - network_ip_address_family_t wasi_family) { + sockets_ip_address_family_t wasi_family) { switch (wasi_family) { - case NETWORK_IP_ADDRESS_FAMILY_IPV4: + case SOCKETS_IP_ADDRESS_FAMILY_IPV4: return AF_INET; - case NETWORK_IP_ADDRESS_FAMILY_IPV6: + case SOCKETS_IP_ADDRESS_FAMILY_IPV6: return AF_INET6; default: /* unreachable */ abort(); } } -network_ip_socket_address_t -__wasi_sockets_utils__any_addr(network_ip_address_family_t family) { +sockets_ip_socket_address_t +__wasi_sockets_utils__any_addr(sockets_ip_address_family_t family) { switch (family) { - case NETWORK_IP_ADDRESS_FAMILY_IPV4: - return (network_ip_socket_address_t){.tag = NETWORK_IP_SOCKET_ADDRESS_IPV4, + case SOCKETS_IP_ADDRESS_FAMILY_IPV4: + return (sockets_ip_socket_address_t){.tag = SOCKETS_IP_SOCKET_ADDRESS_IPV4, .val = {.ipv4 = { .port = 0, .address = {0, 0, 0, 0}, }}}; - case NETWORK_IP_ADDRESS_FAMILY_IPV6: - return (network_ip_socket_address_t){ - .tag = NETWORK_IP_SOCKET_ADDRESS_IPV6, + case SOCKETS_IP_ADDRESS_FAMILY_IPV6: + return (sockets_ip_socket_address_t){ + .tag = SOCKETS_IP_SOCKET_ADDRESS_IPV6, .val = {.ipv6 = { .port = 0, .address = {0, 0, 0, 0, 0, 0, 0, 0}, diff --git a/libc-bottom-half/sources/wasip3.c b/libc-bottom-half/sources/wasip3.c new file mode 100644 index 000000000..b58e84ded --- /dev/null +++ b/libc-bottom-half/sources/wasip3.c @@ -0,0 +1,2640 @@ +// Generated by `wit-bindgen` 0.48.0. DO NOT EDIT! +#include "wasi/wasip3.h" +#include +#include + +// Imported Functions from `wasi:cli/environment@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2025-09-16"), __import_name__("get-environment"))) +extern void __wasm_import_environment_get_environment(uint8_t *); + +__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2025-09-16"), __import_name__("get-arguments"))) +extern void __wasm_import_environment_get_arguments(uint8_t *); + +__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2025-09-16"), __import_name__("get-initial-cwd"))) +extern void __wasm_import_environment_get_initial_cwd(uint8_t *); + +// Imported Functions from `wasi:cli/exit@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:cli/exit@0.3.0-rc-2025-09-16"), __import_name__("exit"))) +_Noreturn extern void __wasm_import_exit_exit(int32_t); + +// Imported Functions from `wasi:cli/stdin@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("read-via-stream"))) +extern void __wasm_import_stdin_read_via_stream(uint8_t *); + +// Imported Functions from `wasi:cli/stdout@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:cli/stdout@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]write-via-stream"))) +extern int32_t __wasm_import_stdout_write_via_stream(int32_t, uint8_t *); + +// Imported Functions from `wasi:cli/stderr@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:cli/stderr@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]write-via-stream"))) +extern int32_t __wasm_import_stderr_write_via_stream(int32_t, uint8_t *); + +// Imported Functions from `wasi:cli/terminal-stdin@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:cli/terminal-stdin@0.3.0-rc-2025-09-16"), __import_name__("get-terminal-stdin"))) +extern void __wasm_import_terminal_stdin_get_terminal_stdin(uint8_t *); + +// Imported Functions from `wasi:cli/terminal-stdout@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:cli/terminal-stdout@0.3.0-rc-2025-09-16"), __import_name__("get-terminal-stdout"))) +extern void __wasm_import_terminal_stdout_get_terminal_stdout(uint8_t *); + +// Imported Functions from `wasi:cli/terminal-stderr@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:cli/terminal-stderr@0.3.0-rc-2025-09-16"), __import_name__("get-terminal-stderr"))) +extern void __wasm_import_terminal_stderr_get_terminal_stderr(uint8_t *); + +// Imported Functions from `wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16"), __import_name__("now"))) +extern int64_t __wasm_import_monotonic_clock_now(void); + +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16"), __import_name__("get-resolution"))) +extern int64_t __wasm_import_monotonic_clock_get_resolution(void); + +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]wait-until"))) +extern int32_t __wasm_import_monotonic_clock_wait_until(int64_t); + +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]wait-for"))) +extern int32_t __wasm_import_monotonic_clock_wait_for(int64_t); + +// Imported Functions from `wasi:clocks/wall-clock@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:clocks/wall-clock@0.3.0-rc-2025-09-16"), __import_name__("now"))) +extern void __wasm_import_wall_clock_now(uint8_t *); + +__attribute__((__import_module__("wasi:clocks/wall-clock@0.3.0-rc-2025-09-16"), __import_name__("get-resolution"))) +extern void __wasm_import_wall_clock_get_resolution(uint8_t *); + +// Imported Functions from `wasi:filesystem/types@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[method]descriptor.read-via-stream"))) +extern void __wasm_import_filesystem_method_descriptor_read_via_stream(int32_t, int64_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.write-via-stream"))) +extern int32_t __wasm_import_filesystem_method_descriptor_write_via_stream(int32_t, int32_t, int64_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.append-via-stream"))) +extern int32_t __wasm_import_filesystem_method_descriptor_append_via_stream(int32_t, int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.advise"))) +extern int32_t __wasm_import_filesystem_method_descriptor_advise(int32_t, int64_t, int64_t, int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.sync-data"))) +extern int32_t __wasm_import_filesystem_method_descriptor_sync_data(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.get-flags"))) +extern int32_t __wasm_import_filesystem_method_descriptor_get_flags(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.get-type"))) +extern int32_t __wasm_import_filesystem_method_descriptor_get_type(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.set-size"))) +extern int32_t __wasm_import_filesystem_method_descriptor_set_size(int32_t, int64_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.set-times"))) +extern int32_t __wasm_import_filesystem_method_descriptor_set_times(uint8_t *, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.read-directory"))) +extern int32_t __wasm_import_filesystem_method_descriptor_read_directory(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.sync"))) +extern int32_t __wasm_import_filesystem_method_descriptor_sync(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.create-directory-at"))) +extern int32_t __wasm_import_filesystem_method_descriptor_create_directory_at(int32_t, uint8_t *, size_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.stat"))) +extern int32_t __wasm_import_filesystem_method_descriptor_stat(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.stat-at"))) +extern int32_t __wasm_import_filesystem_method_descriptor_stat_at(int32_t, int32_t, uint8_t *, size_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.set-times-at"))) +extern int32_t __wasm_import_filesystem_method_descriptor_set_times_at(uint8_t *, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.link-at"))) +extern int32_t __wasm_import_filesystem_method_descriptor_link_at(uint8_t *, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.open-at"))) +extern int32_t __wasm_import_filesystem_method_descriptor_open_at(uint8_t *, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.readlink-at"))) +extern int32_t __wasm_import_filesystem_method_descriptor_readlink_at(int32_t, uint8_t *, size_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.remove-directory-at"))) +extern int32_t __wasm_import_filesystem_method_descriptor_remove_directory_at(int32_t, uint8_t *, size_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.rename-at"))) +extern int32_t __wasm_import_filesystem_method_descriptor_rename_at(uint8_t *, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.symlink-at"))) +extern int32_t __wasm_import_filesystem_method_descriptor_symlink_at(uint8_t *, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.unlink-file-at"))) +extern int32_t __wasm_import_filesystem_method_descriptor_unlink_file_at(int32_t, uint8_t *, size_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.is-same-object"))) +extern int32_t __wasm_import_filesystem_method_descriptor_is_same_object(int32_t, int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.metadata-hash"))) +extern int32_t __wasm_import_filesystem_method_descriptor_metadata_hash(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.metadata-hash-at"))) +extern int32_t __wasm_import_filesystem_method_descriptor_metadata_hash_at(int32_t, int32_t, uint8_t *, size_t, uint8_t *); + +// Imported Functions from `wasi:filesystem/preopens@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:filesystem/preopens@0.3.0-rc-2025-09-16"), __import_name__("get-directories"))) +extern void __wasm_import_filesystem_preopens_get_directories(uint8_t *); + +// Imported Functions from `wasi:sockets/types@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[static]tcp-socket.create"))) +extern void __wasm_import_sockets_static_tcp_socket_create(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.bind"))) +extern void __wasm_import_sockets_method_tcp_socket_bind(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]tcp-socket.connect"))) +extern int32_t __wasm_import_sockets_method_tcp_socket_connect(uint8_t *, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.listen"))) +extern void __wasm_import_sockets_method_tcp_socket_listen(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]tcp-socket.send"))) +extern int32_t __wasm_import_sockets_method_tcp_socket_send(int32_t, int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.receive"))) +extern void __wasm_import_sockets_method_tcp_socket_receive(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-local-address"))) +extern void __wasm_import_sockets_method_tcp_socket_get_local_address(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-remote-address"))) +extern void __wasm_import_sockets_method_tcp_socket_get_remote_address(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-is-listening"))) +extern int32_t __wasm_import_sockets_method_tcp_socket_get_is_listening(int32_t); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-address-family"))) +extern int32_t __wasm_import_sockets_method_tcp_socket_get_address_family(int32_t); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-listen-backlog-size"))) +extern void __wasm_import_sockets_method_tcp_socket_set_listen_backlog_size(int32_t, int64_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-keep-alive-enabled"))) +extern void __wasm_import_sockets_method_tcp_socket_get_keep_alive_enabled(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-keep-alive-enabled"))) +extern void __wasm_import_sockets_method_tcp_socket_set_keep_alive_enabled(int32_t, int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-keep-alive-idle-time"))) +extern void __wasm_import_sockets_method_tcp_socket_get_keep_alive_idle_time(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-keep-alive-idle-time"))) +extern void __wasm_import_sockets_method_tcp_socket_set_keep_alive_idle_time(int32_t, int64_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-keep-alive-interval"))) +extern void __wasm_import_sockets_method_tcp_socket_get_keep_alive_interval(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-keep-alive-interval"))) +extern void __wasm_import_sockets_method_tcp_socket_set_keep_alive_interval(int32_t, int64_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-keep-alive-count"))) +extern void __wasm_import_sockets_method_tcp_socket_get_keep_alive_count(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-keep-alive-count"))) +extern void __wasm_import_sockets_method_tcp_socket_set_keep_alive_count(int32_t, int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-hop-limit"))) +extern void __wasm_import_sockets_method_tcp_socket_get_hop_limit(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-hop-limit"))) +extern void __wasm_import_sockets_method_tcp_socket_set_hop_limit(int32_t, int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-receive-buffer-size"))) +extern void __wasm_import_sockets_method_tcp_socket_get_receive_buffer_size(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-receive-buffer-size"))) +extern void __wasm_import_sockets_method_tcp_socket_set_receive_buffer_size(int32_t, int64_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-send-buffer-size"))) +extern void __wasm_import_sockets_method_tcp_socket_get_send_buffer_size(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-send-buffer-size"))) +extern void __wasm_import_sockets_method_tcp_socket_set_send_buffer_size(int32_t, int64_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[static]udp-socket.create"))) +extern void __wasm_import_sockets_static_udp_socket_create(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.bind"))) +extern void __wasm_import_sockets_method_udp_socket_bind(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.connect"))) +extern void __wasm_import_sockets_method_udp_socket_connect(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.disconnect"))) +extern void __wasm_import_sockets_method_udp_socket_disconnect(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]udp-socket.send"))) +extern int32_t __wasm_import_sockets_method_udp_socket_send(uint8_t *, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]udp-socket.receive"))) +extern int32_t __wasm_import_sockets_method_udp_socket_receive(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-local-address"))) +extern void __wasm_import_sockets_method_udp_socket_get_local_address(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-remote-address"))) +extern void __wasm_import_sockets_method_udp_socket_get_remote_address(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-address-family"))) +extern int32_t __wasm_import_sockets_method_udp_socket_get_address_family(int32_t); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-unicast-hop-limit"))) +extern void __wasm_import_sockets_method_udp_socket_get_unicast_hop_limit(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.set-unicast-hop-limit"))) +extern void __wasm_import_sockets_method_udp_socket_set_unicast_hop_limit(int32_t, int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-receive-buffer-size"))) +extern void __wasm_import_sockets_method_udp_socket_get_receive_buffer_size(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.set-receive-buffer-size"))) +extern void __wasm_import_sockets_method_udp_socket_set_receive_buffer_size(int32_t, int64_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-send-buffer-size"))) +extern void __wasm_import_sockets_method_udp_socket_get_send_buffer_size(int32_t, uint8_t *); + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.set-send-buffer-size"))) +extern void __wasm_import_sockets_method_udp_socket_set_send_buffer_size(int32_t, int64_t, uint8_t *); + +// Imported Functions from `wasi:sockets/ip-name-lookup@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]resolve-addresses"))) +extern int32_t __wasm_import_ip_name_lookup_resolve_addresses(uint8_t *, size_t, uint8_t *); + +// Imported Functions from `wasi:random/random@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:random/random@0.3.0-rc-2025-09-16"), __import_name__("get-random-bytes"))) +extern void __wasm_import_random_get_random_bytes(int64_t, uint8_t *); + +__attribute__((__import_module__("wasi:random/random@0.3.0-rc-2025-09-16"), __import_name__("get-random-u64"))) +extern int64_t __wasm_import_random_get_random_u64(void); + +// Imported Functions from `wasi:random/insecure@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:random/insecure@0.3.0-rc-2025-09-16"), __import_name__("get-insecure-random-bytes"))) +extern void __wasm_import_random_insecure_get_insecure_random_bytes(int64_t, uint8_t *); + +__attribute__((__import_module__("wasi:random/insecure@0.3.0-rc-2025-09-16"), __import_name__("get-insecure-random-u64"))) +extern int64_t __wasm_import_random_insecure_get_insecure_random_u64(void); + +// Imported Functions from `wasi:random/insecure-seed@0.3.0-rc-2025-09-16` + +__attribute__((__import_module__("wasi:random/insecure-seed@0.3.0-rc-2025-09-16"), __import_name__("get-insecure-seed"))) +extern void __wasm_import_random_insecure_seed_get_insecure_seed(uint8_t *); + +// Canonical ABI intrinsics + +__attribute__((__weak__, __export_name__("cabi_realloc"))) +void *cabi_realloc(void *ptr, size_t old_size, size_t align, size_t new_size) { + (void) old_size; + if (new_size == 0) return (void*) align; + void *ret = realloc(ptr, new_size); + if (!ret) abort(); + return ret; +} + +// Helper Functions + +void wasip3_tuple2_string_string_free(wasip3_tuple2_string_string_t *ptr) { + wasip3_string_free(&ptr->f0); + wasip3_string_free(&ptr->f1); +} + +void wasip3_list_tuple2_string_string_free(wasip3_list_tuple2_string_string_t *ptr) { + size_t list_len = ptr->len; + if (list_len > 0) { + wasip3_tuple2_string_string_t *list_ptr = ptr->ptr; + for (size_t i = 0; i < list_len; i++) { + wasip3_tuple2_string_string_free(&list_ptr[i]); + } + free(list_ptr); + } +} + +void wasip3_list_string_free(wasip3_list_string_t *ptr) { + size_t list_len = ptr->len; + if (list_len > 0) { + wasip3_string_t *list_ptr = ptr->ptr; + for (size_t i = 0; i < list_len; i++) { + wasip3_string_free(&list_ptr[i]); + } + free(list_ptr); + } +} + +void wasip3_option_string_free(wasip3_option_string_t *ptr) { + if (ptr->is_some) { + wasip3_string_free(&ptr->val); + } +} + +void exit_result_void_void_free(exit_result_void_void_t *ptr) { + if (!ptr->is_err) { + } +} + +void stdin_result_void_error_code_free(stdin_result_void_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0]read-via-stream"))) +extern uint64_t stdin_stream_u8__new(void); +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0]read-via-stream"))) +extern uint32_t stdin_stream_u8__read(uint32_t, uint8_t*, size_t); +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0]read-via-stream"))) +extern uint32_t stdin_stream_u8__write(uint32_t, const uint8_t*, size_t); +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0]read-via-stream"))) +extern uint32_t stdin_stream_u8__cancel_read(uint32_t); +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0]read-via-stream"))) +extern uint32_t stdin_stream_u8__cancel_write(uint32_t); +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0]read-via-stream"))) +extern void stdin_stream_u8__drop_readable(uint32_t); +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0]read-via-stream"))) +extern void stdin_stream_u8__drop_writable(uint32_t); + +stdin_stream_u8_t stdin_stream_u8_new(stdin_stream_u8_writer_t *writer) { + uint64_t packed = stdin_stream_u8__new(); + *writer = (uint32_t) (packed >> 32); + return (uint32_t) packed; +} + +wasip3_waitable_status_t stdin_stream_u8_read(stdin_stream_u8_t reader, uint8_t *buf, size_t amt) { + return stdin_stream_u8__read(reader, (uint8_t*) buf, amt); +} + +wasip3_waitable_status_t stdin_stream_u8_write(stdin_stream_u8_writer_t writer, const uint8_t *buf, size_t amt) { + return stdin_stream_u8__write(writer, (const uint8_t*) buf, amt); +} + +wasip3_waitable_status_t stdin_stream_u8_cancel_read(stdin_stream_u8_t reader){ + return stdin_stream_u8__cancel_read(reader); +} + +wasip3_waitable_status_t stdin_stream_u8_cancel_write(stdin_stream_u8_writer_t writer) { + return stdin_stream_u8__cancel_write(writer); +} + +void stdin_stream_u8_drop_readable(stdin_stream_u8_t reader){ + stdin_stream_u8__drop_readable(reader); +} + +void stdin_stream_u8_drop_writable(stdin_stream_u8_writer_t writer) { + stdin_stream_u8__drop_writable(writer); +} + + +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-new-1]read-via-stream"))) +extern uint64_t stdin_future_result_void_error_code__new(void); +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-read-1]read-via-stream"))) +extern uint32_t stdin_future_result_void_error_code__read(uint32_t, uint8_t*); +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-write-1]read-via-stream"))) +extern uint32_t stdin_future_result_void_error_code__write(uint32_t, const uint8_t*); +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-read-1]read-via-stream"))) +extern uint32_t stdin_future_result_void_error_code__cancel_read(uint32_t); +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-write-1]read-via-stream"))) +extern uint32_t stdin_future_result_void_error_code__cancel_write(uint32_t); +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-readable-1]read-via-stream"))) +extern void stdin_future_result_void_error_code__drop_readable(uint32_t); +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-writable-1]read-via-stream"))) +extern void stdin_future_result_void_error_code__drop_writable(uint32_t); + +stdin_future_result_void_error_code_t stdin_future_result_void_error_code_new(stdin_future_result_void_error_code_writer_t *writer) { + uint64_t packed = stdin_future_result_void_error_code__new(); + *writer = (uint32_t) (packed >> 32); + return (uint32_t) packed; +} + +wasip3_waitable_status_t stdin_future_result_void_error_code_read(stdin_future_result_void_error_code_t reader, stdin_result_void_error_code_t *buf) { + return stdin_future_result_void_error_code__read(reader, (uint8_t*) buf); +} + +wasip3_waitable_status_t stdin_future_result_void_error_code_write(stdin_future_result_void_error_code_writer_t writer, const stdin_result_void_error_code_t *buf) { + return stdin_future_result_void_error_code__write(writer, (const uint8_t*) buf); +} + +wasip3_waitable_status_t stdin_future_result_void_error_code_cancel_read(stdin_future_result_void_error_code_t reader){ + return stdin_future_result_void_error_code__cancel_read(reader); +} + +wasip3_waitable_status_t stdin_future_result_void_error_code_cancel_write(stdin_future_result_void_error_code_writer_t writer) { + return stdin_future_result_void_error_code__cancel_write(writer); +} + +void stdin_future_result_void_error_code_drop_readable(stdin_future_result_void_error_code_t reader){ + stdin_future_result_void_error_code__drop_readable(reader); +} + +void stdin_future_result_void_error_code_drop_writable(stdin_future_result_void_error_code_writer_t writer) { + stdin_future_result_void_error_code__drop_writable(writer); +} + + +void stdout_result_void_error_code_free(stdout_result_void_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void stderr_result_void_error_code_free(stderr_result_void_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +__attribute__((__import_module__("wasi:cli/terminal-input@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]terminal-input"))) +extern void __wasm_import_terminal_input_terminal_input_drop(int32_t handle); + +void terminal_input_terminal_input_drop_own(terminal_input_own_terminal_input_t handle) { + __wasm_import_terminal_input_terminal_input_drop(handle.__handle); +} + +terminal_input_borrow_terminal_input_t terminal_input_borrow_terminal_input(terminal_input_own_terminal_input_t arg) { + return (terminal_input_borrow_terminal_input_t) { arg.__handle }; +} + +__attribute__((__import_module__("wasi:cli/terminal-output@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]terminal-output"))) +extern void __wasm_import_terminal_output_terminal_output_drop(int32_t handle); + +void terminal_output_terminal_output_drop_own(terminal_output_own_terminal_output_t handle) { + __wasm_import_terminal_output_terminal_output_drop(handle.__handle); +} + +terminal_output_borrow_terminal_output_t terminal_output_borrow_terminal_output(terminal_output_own_terminal_output_t arg) { + return (terminal_output_borrow_terminal_output_t) { arg.__handle }; +} + +void terminal_stdin_option_own_terminal_input_free(terminal_stdin_option_own_terminal_input_t *ptr) { + if (ptr->is_some) { + } +} + +void terminal_stdout_option_own_terminal_output_free(terminal_stdout_option_own_terminal_output_t *ptr) { + if (ptr->is_some) { + } +} + +void terminal_stderr_option_own_terminal_output_free(terminal_stderr_option_own_terminal_output_t *ptr) { + if (ptr->is_some) { + } +} + +void filesystem_option_datetime_free(filesystem_option_datetime_t *ptr) { + if (ptr->is_some) { + } +} + +void filesystem_descriptor_stat_free(filesystem_descriptor_stat_t *ptr) { + filesystem_option_datetime_free(&ptr->data_access_timestamp); + filesystem_option_datetime_free(&ptr->data_modification_timestamp); + filesystem_option_datetime_free(&ptr->status_change_timestamp); +} + +void filesystem_new_timestamp_free(filesystem_new_timestamp_t *ptr) { + switch ((int32_t) ptr->tag) { + case 2: { + break; + } + } +} + +void filesystem_directory_entry_free(filesystem_directory_entry_t *ptr) { + wasip3_string_free(&ptr->name); +} + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]descriptor"))) +extern void __wasm_import_filesystem_descriptor_drop(int32_t handle); + +void filesystem_descriptor_drop_own(filesystem_own_descriptor_t handle) { + __wasm_import_filesystem_descriptor_drop(handle.__handle); +} + +filesystem_borrow_descriptor_t filesystem_borrow_descriptor(filesystem_own_descriptor_t arg) { + return (filesystem_borrow_descriptor_t) { arg.__handle }; +} + +void filesystem_result_void_error_code_free(filesystem_result_void_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void filesystem_result_descriptor_flags_error_code_free(filesystem_result_descriptor_flags_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void filesystem_result_descriptor_type_error_code_free(filesystem_result_descriptor_type_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void filesystem_result_descriptor_stat_error_code_free(filesystem_result_descriptor_stat_error_code_t *ptr) { + if (!ptr->is_err) { + filesystem_descriptor_stat_free(&ptr->val.ok); + } else { + } +} + +void filesystem_result_own_descriptor_error_code_free(filesystem_result_own_descriptor_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void filesystem_result_string_error_code_free(filesystem_result_string_error_code_t *ptr) { + if (!ptr->is_err) { + wasip3_string_free(&ptr->val.ok); + } else { + } +} + +void filesystem_result_metadata_hash_value_error_code_free(filesystem_result_metadata_hash_value_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0][method]descriptor.read-via-stream"))) +extern uint64_t filesystem_stream_u8__new(void); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0][method]descriptor.read-via-stream"))) +extern uint32_t filesystem_stream_u8__read(uint32_t, uint8_t*, size_t); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0][method]descriptor.read-via-stream"))) +extern uint32_t filesystem_stream_u8__write(uint32_t, const uint8_t*, size_t); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0][method]descriptor.read-via-stream"))) +extern uint32_t filesystem_stream_u8__cancel_read(uint32_t); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0][method]descriptor.read-via-stream"))) +extern uint32_t filesystem_stream_u8__cancel_write(uint32_t); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0][method]descriptor.read-via-stream"))) +extern void filesystem_stream_u8__drop_readable(uint32_t); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0][method]descriptor.read-via-stream"))) +extern void filesystem_stream_u8__drop_writable(uint32_t); + +filesystem_stream_u8_t filesystem_stream_u8_new(filesystem_stream_u8_writer_t *writer) { + uint64_t packed = filesystem_stream_u8__new(); + *writer = (uint32_t) (packed >> 32); + return (uint32_t) packed; +} + +wasip3_waitable_status_t filesystem_stream_u8_read(filesystem_stream_u8_t reader, uint8_t *buf, size_t amt) { + return filesystem_stream_u8__read(reader, (uint8_t*) buf, amt); +} + +wasip3_waitable_status_t filesystem_stream_u8_write(filesystem_stream_u8_writer_t writer, const uint8_t *buf, size_t amt) { + return filesystem_stream_u8__write(writer, (const uint8_t*) buf, amt); +} + +wasip3_waitable_status_t filesystem_stream_u8_cancel_read(filesystem_stream_u8_t reader){ + return filesystem_stream_u8__cancel_read(reader); +} + +wasip3_waitable_status_t filesystem_stream_u8_cancel_write(filesystem_stream_u8_writer_t writer) { + return filesystem_stream_u8__cancel_write(writer); +} + +void filesystem_stream_u8_drop_readable(filesystem_stream_u8_t reader){ + filesystem_stream_u8__drop_readable(reader); +} + +void filesystem_stream_u8_drop_writable(filesystem_stream_u8_writer_t writer) { + filesystem_stream_u8__drop_writable(writer); +} + + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-new-1][method]descriptor.read-via-stream"))) +extern uint64_t filesystem_future_result_void_error_code__new(void); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-read-1][method]descriptor.read-via-stream"))) +extern uint32_t filesystem_future_result_void_error_code__read(uint32_t, uint8_t*); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-write-1][method]descriptor.read-via-stream"))) +extern uint32_t filesystem_future_result_void_error_code__write(uint32_t, const uint8_t*); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-read-1][method]descriptor.read-via-stream"))) +extern uint32_t filesystem_future_result_void_error_code__cancel_read(uint32_t); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-write-1][method]descriptor.read-via-stream"))) +extern uint32_t filesystem_future_result_void_error_code__cancel_write(uint32_t); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-readable-1][method]descriptor.read-via-stream"))) +extern void filesystem_future_result_void_error_code__drop_readable(uint32_t); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-writable-1][method]descriptor.read-via-stream"))) +extern void filesystem_future_result_void_error_code__drop_writable(uint32_t); + +filesystem_future_result_void_error_code_t filesystem_future_result_void_error_code_new(filesystem_future_result_void_error_code_writer_t *writer) { + uint64_t packed = filesystem_future_result_void_error_code__new(); + *writer = (uint32_t) (packed >> 32); + return (uint32_t) packed; +} + +wasip3_waitable_status_t filesystem_future_result_void_error_code_read(filesystem_future_result_void_error_code_t reader, filesystem_result_void_error_code_t *buf) { + return filesystem_future_result_void_error_code__read(reader, (uint8_t*) buf); +} + +wasip3_waitable_status_t filesystem_future_result_void_error_code_write(filesystem_future_result_void_error_code_writer_t writer, const filesystem_result_void_error_code_t *buf) { + return filesystem_future_result_void_error_code__write(writer, (const uint8_t*) buf); +} + +wasip3_waitable_status_t filesystem_future_result_void_error_code_cancel_read(filesystem_future_result_void_error_code_t reader){ + return filesystem_future_result_void_error_code__cancel_read(reader); +} + +wasip3_waitable_status_t filesystem_future_result_void_error_code_cancel_write(filesystem_future_result_void_error_code_writer_t writer) { + return filesystem_future_result_void_error_code__cancel_write(writer); +} + +void filesystem_future_result_void_error_code_drop_readable(filesystem_future_result_void_error_code_t reader){ + filesystem_future_result_void_error_code__drop_readable(reader); +} + +void filesystem_future_result_void_error_code_drop_writable(filesystem_future_result_void_error_code_writer_t writer) { + filesystem_future_result_void_error_code__drop_writable(writer); +} + + +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0][method]descriptor.read-directory"))) +extern uint64_t filesystem_stream_directory_entry__new(void); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0][method]descriptor.read-directory"))) +extern uint32_t filesystem_stream_directory_entry__read(uint32_t, uint8_t*, size_t); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0][method]descriptor.read-directory"))) +extern uint32_t filesystem_stream_directory_entry__write(uint32_t, const uint8_t*, size_t); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0][method]descriptor.read-directory"))) +extern uint32_t filesystem_stream_directory_entry__cancel_read(uint32_t); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0][method]descriptor.read-directory"))) +extern uint32_t filesystem_stream_directory_entry__cancel_write(uint32_t); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0][method]descriptor.read-directory"))) +extern void filesystem_stream_directory_entry__drop_readable(uint32_t); +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0][method]descriptor.read-directory"))) +extern void filesystem_stream_directory_entry__drop_writable(uint32_t); + +filesystem_stream_directory_entry_t filesystem_stream_directory_entry_new(filesystem_stream_directory_entry_writer_t *writer) { + uint64_t packed = filesystem_stream_directory_entry__new(); + *writer = (uint32_t) (packed >> 32); + return (uint32_t) packed; +} + +wasip3_waitable_status_t filesystem_stream_directory_entry_read(filesystem_stream_directory_entry_t reader, filesystem_directory_entry_t *buf, size_t amt) { + return filesystem_stream_directory_entry__read(reader, (uint8_t*) buf, amt); +} + +wasip3_waitable_status_t filesystem_stream_directory_entry_write(filesystem_stream_directory_entry_writer_t writer, const filesystem_directory_entry_t *buf, size_t amt) { + return filesystem_stream_directory_entry__write(writer, (const uint8_t*) buf, amt); +} + +wasip3_waitable_status_t filesystem_stream_directory_entry_cancel_read(filesystem_stream_directory_entry_t reader){ + return filesystem_stream_directory_entry__cancel_read(reader); +} + +wasip3_waitable_status_t filesystem_stream_directory_entry_cancel_write(filesystem_stream_directory_entry_writer_t writer) { + return filesystem_stream_directory_entry__cancel_write(writer); +} + +void filesystem_stream_directory_entry_drop_readable(filesystem_stream_directory_entry_t reader){ + filesystem_stream_directory_entry__drop_readable(reader); +} + +void filesystem_stream_directory_entry_drop_writable(filesystem_stream_directory_entry_writer_t writer) { + filesystem_stream_directory_entry__drop_writable(writer); +} + + +void filesystem_preopens_tuple2_own_descriptor_string_free(filesystem_preopens_tuple2_own_descriptor_string_t *ptr) { + wasip3_string_free(&ptr->f1); +} + +void filesystem_preopens_list_tuple2_own_descriptor_string_free(filesystem_preopens_list_tuple2_own_descriptor_string_t *ptr) { + size_t list_len = ptr->len; + if (list_len > 0) { + filesystem_preopens_tuple2_own_descriptor_string_t *list_ptr = ptr->ptr; + for (size_t i = 0; i < list_len; i++) { + filesystem_preopens_tuple2_own_descriptor_string_free(&list_ptr[i]); + } + free(list_ptr); + } +} + +void sockets_ip_address_free(sockets_ip_address_t *ptr) { + switch ((int32_t) ptr->tag) { + case 0: { + break; + } + case 1: { + break; + } + } +} + +void sockets_ip_socket_address_free(sockets_ip_socket_address_t *ptr) { + switch ((int32_t) ptr->tag) { + case 0: { + break; + } + case 1: { + break; + } + } +} + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]tcp-socket"))) +extern void __wasm_import_sockets_tcp_socket_drop(int32_t handle); + +void sockets_tcp_socket_drop_own(sockets_own_tcp_socket_t handle) { + __wasm_import_sockets_tcp_socket_drop(handle.__handle); +} + +sockets_borrow_tcp_socket_t sockets_borrow_tcp_socket(sockets_own_tcp_socket_t arg) { + return (sockets_borrow_tcp_socket_t) { arg.__handle }; +} + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]udp-socket"))) +extern void __wasm_import_sockets_udp_socket_drop(int32_t handle); + +void sockets_udp_socket_drop_own(sockets_own_udp_socket_t handle) { + __wasm_import_sockets_udp_socket_drop(handle.__handle); +} + +sockets_borrow_udp_socket_t sockets_borrow_udp_socket(sockets_own_udp_socket_t arg) { + return (sockets_borrow_udp_socket_t) { arg.__handle }; +} + +void sockets_result_own_tcp_socket_error_code_free(sockets_result_own_tcp_socket_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void sockets_result_void_error_code_free(sockets_result_void_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void sockets_result_stream_own_tcp_socket_error_code_free(sockets_result_stream_own_tcp_socket_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void sockets_result_ip_socket_address_error_code_free(sockets_result_ip_socket_address_error_code_t *ptr) { + if (!ptr->is_err) { + sockets_ip_socket_address_free(&ptr->val.ok); + } else { + } +} + +void sockets_result_bool_error_code_free(sockets_result_bool_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void sockets_result_duration_error_code_free(sockets_result_duration_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void sockets_result_u32_error_code_free(sockets_result_u32_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void sockets_result_u8_error_code_free(sockets_result_u8_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void sockets_result_u64_error_code_free(sockets_result_u64_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void sockets_result_own_udp_socket_error_code_free(sockets_result_own_udp_socket_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void wasip3_list_u8_free(wasip3_list_u8_t *ptr) { + size_t list_len = ptr->len; + if (list_len > 0) { + uint8_t *list_ptr = ptr->ptr; + for (size_t i = 0; i < list_len; i++) { + } + free(list_ptr); + } +} + +void sockets_option_ip_socket_address_free(sockets_option_ip_socket_address_t *ptr) { + if (ptr->is_some) { + sockets_ip_socket_address_free(&ptr->val); + } +} + +void sockets_tuple2_list_u8_ip_socket_address_free(sockets_tuple2_list_u8_ip_socket_address_t *ptr) { + wasip3_list_u8_free(&ptr->f0); + sockets_ip_socket_address_free(&ptr->f1); +} + +void sockets_result_tuple2_list_u8_ip_socket_address_error_code_free(sockets_result_tuple2_list_u8_ip_socket_address_error_code_t *ptr) { + if (!ptr->is_err) { + sockets_tuple2_list_u8_ip_socket_address_free(&ptr->val.ok); + } else { + } +} + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0][method]tcp-socket.listen"))) +extern uint64_t sockets_stream_own_tcp_socket__new(void); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0][method]tcp-socket.listen"))) +extern uint32_t sockets_stream_own_tcp_socket__read(uint32_t, uint8_t*, size_t); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0][method]tcp-socket.listen"))) +extern uint32_t sockets_stream_own_tcp_socket__write(uint32_t, const uint8_t*, size_t); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0][method]tcp-socket.listen"))) +extern uint32_t sockets_stream_own_tcp_socket__cancel_read(uint32_t); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0][method]tcp-socket.listen"))) +extern uint32_t sockets_stream_own_tcp_socket__cancel_write(uint32_t); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0][method]tcp-socket.listen"))) +extern void sockets_stream_own_tcp_socket__drop_readable(uint32_t); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0][method]tcp-socket.listen"))) +extern void sockets_stream_own_tcp_socket__drop_writable(uint32_t); + +sockets_stream_own_tcp_socket_t sockets_stream_own_tcp_socket_new(sockets_stream_own_tcp_socket_writer_t *writer) { + uint64_t packed = sockets_stream_own_tcp_socket__new(); + *writer = (uint32_t) (packed >> 32); + return (uint32_t) packed; +} + +wasip3_waitable_status_t sockets_stream_own_tcp_socket_read(sockets_stream_own_tcp_socket_t reader, sockets_own_tcp_socket_t *buf, size_t amt) { + return sockets_stream_own_tcp_socket__read(reader, (uint8_t*) buf, amt); +} + +wasip3_waitable_status_t sockets_stream_own_tcp_socket_write(sockets_stream_own_tcp_socket_writer_t writer, const sockets_own_tcp_socket_t *buf, size_t amt) { + return sockets_stream_own_tcp_socket__write(writer, (const uint8_t*) buf, amt); +} + +wasip3_waitable_status_t sockets_stream_own_tcp_socket_cancel_read(sockets_stream_own_tcp_socket_t reader){ + return sockets_stream_own_tcp_socket__cancel_read(reader); +} + +wasip3_waitable_status_t sockets_stream_own_tcp_socket_cancel_write(sockets_stream_own_tcp_socket_writer_t writer) { + return sockets_stream_own_tcp_socket__cancel_write(writer); +} + +void sockets_stream_own_tcp_socket_drop_readable(sockets_stream_own_tcp_socket_t reader){ + sockets_stream_own_tcp_socket__drop_readable(reader); +} + +void sockets_stream_own_tcp_socket_drop_writable(sockets_stream_own_tcp_socket_writer_t writer) { + sockets_stream_own_tcp_socket__drop_writable(writer); +} + + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0][method]tcp-socket.send"))) +extern uint64_t sockets_stream_u8__new(void); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0][method]tcp-socket.send"))) +extern uint32_t sockets_stream_u8__read(uint32_t, uint8_t*, size_t); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0][method]tcp-socket.send"))) +extern uint32_t sockets_stream_u8__write(uint32_t, const uint8_t*, size_t); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0][method]tcp-socket.send"))) +extern uint32_t sockets_stream_u8__cancel_read(uint32_t); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0][method]tcp-socket.send"))) +extern uint32_t sockets_stream_u8__cancel_write(uint32_t); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0][method]tcp-socket.send"))) +extern void sockets_stream_u8__drop_readable(uint32_t); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0][method]tcp-socket.send"))) +extern void sockets_stream_u8__drop_writable(uint32_t); + +sockets_stream_u8_t sockets_stream_u8_new(sockets_stream_u8_writer_t *writer) { + uint64_t packed = sockets_stream_u8__new(); + *writer = (uint32_t) (packed >> 32); + return (uint32_t) packed; +} + +wasip3_waitable_status_t sockets_stream_u8_read(sockets_stream_u8_t reader, uint8_t *buf, size_t amt) { + return sockets_stream_u8__read(reader, (uint8_t*) buf, amt); +} + +wasip3_waitable_status_t sockets_stream_u8_write(sockets_stream_u8_writer_t writer, const uint8_t *buf, size_t amt) { + return sockets_stream_u8__write(writer, (const uint8_t*) buf, amt); +} + +wasip3_waitable_status_t sockets_stream_u8_cancel_read(sockets_stream_u8_t reader){ + return sockets_stream_u8__cancel_read(reader); +} + +wasip3_waitable_status_t sockets_stream_u8_cancel_write(sockets_stream_u8_writer_t writer) { + return sockets_stream_u8__cancel_write(writer); +} + +void sockets_stream_u8_drop_readable(sockets_stream_u8_t reader){ + sockets_stream_u8__drop_readable(reader); +} + +void sockets_stream_u8_drop_writable(sockets_stream_u8_writer_t writer) { + sockets_stream_u8__drop_writable(writer); +} + + +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-new-1][method]tcp-socket.receive"))) +extern uint64_t sockets_future_result_void_error_code__new(void); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-read-1][method]tcp-socket.receive"))) +extern uint32_t sockets_future_result_void_error_code__read(uint32_t, uint8_t*); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-write-1][method]tcp-socket.receive"))) +extern uint32_t sockets_future_result_void_error_code__write(uint32_t, const uint8_t*); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-read-1][method]tcp-socket.receive"))) +extern uint32_t sockets_future_result_void_error_code__cancel_read(uint32_t); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-write-1][method]tcp-socket.receive"))) +extern uint32_t sockets_future_result_void_error_code__cancel_write(uint32_t); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-readable-1][method]tcp-socket.receive"))) +extern void sockets_future_result_void_error_code__drop_readable(uint32_t); +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-writable-1][method]tcp-socket.receive"))) +extern void sockets_future_result_void_error_code__drop_writable(uint32_t); + +sockets_future_result_void_error_code_t sockets_future_result_void_error_code_new(sockets_future_result_void_error_code_writer_t *writer) { + uint64_t packed = sockets_future_result_void_error_code__new(); + *writer = (uint32_t) (packed >> 32); + return (uint32_t) packed; +} + +wasip3_waitable_status_t sockets_future_result_void_error_code_read(sockets_future_result_void_error_code_t reader, sockets_result_void_error_code_t *buf) { + return sockets_future_result_void_error_code__read(reader, (uint8_t*) buf); +} + +wasip3_waitable_status_t sockets_future_result_void_error_code_write(sockets_future_result_void_error_code_writer_t writer, const sockets_result_void_error_code_t *buf) { + return sockets_future_result_void_error_code__write(writer, (const uint8_t*) buf); +} + +wasip3_waitable_status_t sockets_future_result_void_error_code_cancel_read(sockets_future_result_void_error_code_t reader){ + return sockets_future_result_void_error_code__cancel_read(reader); +} + +wasip3_waitable_status_t sockets_future_result_void_error_code_cancel_write(sockets_future_result_void_error_code_writer_t writer) { + return sockets_future_result_void_error_code__cancel_write(writer); +} + +void sockets_future_result_void_error_code_drop_readable(sockets_future_result_void_error_code_t reader){ + sockets_future_result_void_error_code__drop_readable(reader); +} + +void sockets_future_result_void_error_code_drop_writable(sockets_future_result_void_error_code_writer_t writer) { + sockets_future_result_void_error_code__drop_writable(writer); +} + + +void ip_name_lookup_ip_address_free(ip_name_lookup_ip_address_t *ptr) { + sockets_ip_address_free(ptr); +} + +void ip_name_lookup_list_ip_address_free(ip_name_lookup_list_ip_address_t *ptr) { + size_t list_len = ptr->len; + if (list_len > 0) { + ip_name_lookup_ip_address_t *list_ptr = ptr->ptr; + for (size_t i = 0; i < list_len; i++) { + ip_name_lookup_ip_address_free(&list_ptr[i]); + } + free(list_ptr); + } +} + +void ip_name_lookup_result_list_ip_address_error_code_free(ip_name_lookup_result_list_ip_address_error_code_t *ptr) { + if (!ptr->is_err) { + ip_name_lookup_list_ip_address_free(&ptr->val.ok); + } else { + } +} + +void wasip3_string_set(wasip3_string_t *ret, const char*s) { + ret->ptr = (uint8_t*) s; + ret->len = strlen(s); +} + +void wasip3_string_dup(wasip3_string_t *ret, const char*s) { + ret->len = strlen(s); + ret->ptr = (uint8_t*) cabi_realloc(NULL, 0, 1, ret->len * 1); + memcpy(ret->ptr, s, ret->len * 1); +} + +void wasip3_string_free(wasip3_string_t *ret) { + if (ret->len > 0) { + free(ret->ptr); + } + ret->ptr = NULL; + ret->len = 0; +} + +// Async Helper Functions + +__attribute__((__import_module__("$root"), __import_name__("[subtask-cancel]"))) +extern uint32_t __subtask_cancel(uint32_t handle); + +wasip3_subtask_status_t wasip3_subtask_cancel(wasip3_subtask_t subtask) { + return __subtask_cancel(subtask); +} + +__attribute__((__import_module__("$root"), __import_name__("[subtask-drop]"))) +extern void __subtask_drop(uint32_t handle); + +void wasip3_subtask_drop(wasip3_subtask_t subtask) { + __subtask_drop(subtask); +} + +__attribute__((__import_module__("$root"), __import_name__("[waitable-set-new]"))) +extern uint32_t __waitable_set_new(void); + +wasip3_waitable_set_t wasip3_waitable_set_new(void) { + return __waitable_set_new(); +} + +__attribute__((__import_module__("$root"), __import_name__("[waitable-join]"))) +extern void __waitable_join(uint32_t, uint32_t); + +void wasip3_waitable_join(uint32_t waitable, wasip3_waitable_set_t set) { + __waitable_join(waitable, set); +} + +__attribute__((__import_module__("$root"), __import_name__("[waitable-set-drop]"))) +extern void __waitable_set_drop(uint32_t); + +void wasip3_waitable_set_drop(wasip3_waitable_set_t set) { + __waitable_set_drop(set); +} + +__attribute__((__import_module__("$root"), __import_name__("[waitable-set-wait]"))) +extern uint32_t __waitable_set_wait(uint32_t, uint32_t*); +__attribute__((__import_module__("$root"), __import_name__("[waitable-set-poll]"))) +extern uint32_t __waitable_set_poll(uint32_t, uint32_t*); + +void wasip3_waitable_set_wait(wasip3_waitable_set_t set, wasip3_event_t *event) { + event->event = (wasip3_event_code_t) __waitable_set_wait(set, &event->waitable); +} + +void wasip3_waitable_set_poll(wasip3_waitable_set_t set, wasip3_event_t *event) { + event->event = (wasip3_event_code_t) __waitable_set_poll(set, &event->waitable); +} + +__attribute__((__import_module__("[export]$root"), __import_name__("[task-cancel]"))) +extern void __task_cancel(void); + +void wasip3_task_cancel() { + __task_cancel(); +} + +__attribute__((__import_module__("$root"), __import_name__("[backpressure-set]"))) +extern void __backpressure_set(bool enable); + +void wasip3_backpressure_set(bool enable) { + __backpressure_set(enable); +} + +__attribute__((__import_module__("$root"), __import_name__("[backpressure-inc]"))) +extern void __backpressure_inc(void); + +void wasip3_backpressure_inc(void) { + __backpressure_inc(); +} + +__attribute__((__import_module__("$root"), __import_name__("[backpressure-dec]"))) +extern void __backpressure_dec(void); + +void wasip3_backpressure_dec(void) { + __backpressure_dec(); +} + +__attribute__((__import_module__("$root"), __import_name__("[context-get-0]"))) +extern void* __context_get(void); + +void* wasip3_context_get() { + return __context_get(); +} + +__attribute__((__import_module__("$root"), __import_name__("[context-set-0]"))) +extern void __context_set(void*); + +void wasip3_context_set(void *val) { + return __context_set(val); +} + +__attribute__((__import_module__("$root"), __import_name__("[thread-yield]"))) +extern uint32_t __thread_yield(void); + +void wasip3_yield(void) { + __thread_yield(); +} + +__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-yield]"))) +extern uint32_t __thread_yield_cancellable(void); + +uint32_t wasip3_yield_cancellable(void) { + return __thread_yield_cancellable(); +} + + + +// Component Adapters + +void environment_get_environment(wasip3_list_tuple2_string_string_t *ret) { + __attribute__((__aligned__(sizeof(void*)))) + uint8_t ret_area[(2*sizeof(void*))]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_environment_get_environment(ptr); + *ret = (wasip3_list_tuple2_string_string_t) { (wasip3_tuple2_string_string_t*)(*((uint8_t **) (ptr + 0))), (*((size_t*) (ptr + sizeof(void*)))) }; +} + +void environment_get_arguments(wasip3_list_string_t *ret) { + __attribute__((__aligned__(sizeof(void*)))) + uint8_t ret_area[(2*sizeof(void*))]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_environment_get_arguments(ptr); + *ret = (wasip3_list_string_t) { (wasip3_string_t*)(*((uint8_t **) (ptr + 0))), (*((size_t*) (ptr + sizeof(void*)))) }; +} + +bool environment_get_initial_cwd(wasip3_string_t *ret) { + __attribute__((__aligned__(sizeof(void*)))) + uint8_t ret_area[(3*sizeof(void*))]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_environment_get_initial_cwd(ptr); + wasip3_option_string_t option; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + option.val = (wasip3_string_t) { (uint8_t*)(*((uint8_t **) (ptr + sizeof(void*)))), (*((size_t*) (ptr + (2*sizeof(void*))))) }; + break; + } + } + *ret = option.val; + return option.is_some; +} + +void exit_exit(exit_result_void_void_t *status) { + int32_t result; + if ((*status).is_err) { + result = 1; + } else { + result = 0; + } + __wasm_import_exit_exit(result); +} + +void stdin_read_via_stream(stdin_tuple2_stream_u8_future_result_void_error_code_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_stdin_read_via_stream(ptr); + *ret = (stdin_tuple2_stream_u8_future_result_void_error_code_t) { + (stdin_stream_u8_t) ((uint32_t) *((int32_t*) (ptr + 0))), + (stdin_future_result_void_error_code_t) ((uint32_t) *((int32_t*) (ptr + 4))), + }; +} + +wasip3_subtask_status_t stdout_write_via_stream(stdin_stream_u8_t data, stdout_result_void_error_code_t *result) { + return __wasm_import_stdout_write_via_stream(((int32_t) data), (uint8_t*) result); +} + +wasip3_subtask_status_t stderr_write_via_stream(stdin_stream_u8_t data, stderr_result_void_error_code_t *result) { + return __wasm_import_stderr_write_via_stream(((int32_t) data), (uint8_t*) result); +} + +bool terminal_stdin_get_terminal_stdin(terminal_stdin_own_terminal_input_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_terminal_stdin_get_terminal_stdin(ptr); + terminal_stdin_option_own_terminal_input_t option; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + option.val = (terminal_stdin_own_terminal_input_t) { *((int32_t*) (ptr + 4)) }; + break; + } + } + *ret = option.val; + return option.is_some; +} + +bool terminal_stdout_get_terminal_stdout(terminal_stdout_own_terminal_output_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_terminal_stdout_get_terminal_stdout(ptr); + terminal_stdout_option_own_terminal_output_t option; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + option.val = (terminal_stdout_own_terminal_output_t) { *((int32_t*) (ptr + 4)) }; + break; + } + } + *ret = option.val; + return option.is_some; +} + +bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_terminal_stderr_get_terminal_stderr(ptr); + terminal_stderr_option_own_terminal_output_t option; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + option.val = (terminal_stderr_own_terminal_output_t) { *((int32_t*) (ptr + 4)) }; + break; + } + } + *ret = option.val; + return option.is_some; +} + +monotonic_clock_instant_t monotonic_clock_now(void) { + int64_t ret = __wasm_import_monotonic_clock_now(); + return (uint64_t) (ret); +} + +monotonic_clock_duration_t monotonic_clock_get_resolution(void) { + int64_t ret = __wasm_import_monotonic_clock_get_resolution(); + return (uint64_t) (ret); +} + +wasip3_subtask_status_t monotonic_clock_wait_until(monotonic_clock_instant_t when) { + return __wasm_import_monotonic_clock_wait_until((int64_t) (when)); +} + +wasip3_subtask_status_t monotonic_clock_wait_for(monotonic_clock_duration_t how_long) { + return __wasm_import_monotonic_clock_wait_for((int64_t) (how_long)); +} + +void wall_clock_now(wall_clock_datetime_t *ret) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_wall_clock_now(ptr); + *ret = (wall_clock_datetime_t) { + (uint64_t) (uint64_t) (*((int64_t*) (ptr + 0))), + (uint32_t) (uint32_t) (*((int32_t*) (ptr + 8))), + }; +} + +void wall_clock_get_resolution(wall_clock_datetime_t *ret) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_wall_clock_get_resolution(ptr); + *ret = (wall_clock_datetime_t) { + (uint64_t) (uint64_t) (*((int64_t*) (ptr + 0))), + (uint32_t) (uint32_t) (*((int32_t*) (ptr + 8))), + }; +} + +void filesystem_method_descriptor_read_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_tuple2_stream_u8_future_result_void_error_code_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_filesystem_method_descriptor_read_via_stream((self).__handle, (int64_t) (offset), ptr); + *ret = (filesystem_tuple2_stream_u8_future_result_void_error_code_t) { + (filesystem_stream_u8_t) ((uint32_t) *((int32_t*) (ptr + 0))), + (filesystem_future_result_void_error_code_t) ((uint32_t) *((int32_t*) (ptr + 4))), + }; +} + +wasip3_subtask_status_t filesystem_method_descriptor_write_via_stream(filesystem_borrow_descriptor_t self, filesystem_stream_u8_t data, filesystem_filesize_t offset, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_write_via_stream((self).__handle, ((int32_t) data), (int64_t) (offset), (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_append_via_stream(filesystem_borrow_descriptor_t self, filesystem_stream_u8_t data, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_append_via_stream((self).__handle, ((int32_t) data), (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_advise(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_filesize_t length, filesystem_advice_t advice, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_advise((self).__handle, (int64_t) (offset), (int64_t) (length), (int32_t) advice, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_sync_data(filesystem_borrow_descriptor_t self, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_sync_data((self).__handle, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_get_flags(filesystem_borrow_descriptor_t self, filesystem_result_descriptor_flags_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_get_flags((self).__handle, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_get_type(filesystem_borrow_descriptor_t self, filesystem_result_descriptor_type_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_get_type((self).__handle, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_set_size(filesystem_borrow_descriptor_t self, filesystem_filesize_t size, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_set_size((self).__handle, (int64_t) (size), (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_set_times(filesystem_method_descriptor_set_times_args_t *args, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_set_times((uint8_t*) args, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_read_directory(filesystem_borrow_descriptor_t self, filesystem_tuple2_stream_directory_entry_future_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_read_directory((self).__handle, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_sync(filesystem_borrow_descriptor_t self, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_sync((self).__handle, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_create_directory_at(filesystem_borrow_descriptor_t self, wasip3_string_t path, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_create_directory_at((self).__handle, (uint8_t *) (path).ptr, (path).len, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_stat(filesystem_borrow_descriptor_t self, filesystem_result_descriptor_stat_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_stat((self).__handle, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_stat_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip3_string_t path, filesystem_result_descriptor_stat_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_stat_at((self).__handle, path_flags, (uint8_t *) (path).ptr, (path).len, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_set_times_at(filesystem_method_descriptor_set_times_at_args_t *args, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_set_times_at((uint8_t*) args, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_link_at(filesystem_method_descriptor_link_at_args_t *args, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_link_at((uint8_t*) args, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_open_at(filesystem_method_descriptor_open_at_args_t *args, filesystem_result_own_descriptor_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_open_at((uint8_t*) args, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_readlink_at(filesystem_borrow_descriptor_t self, wasip3_string_t path, filesystem_result_string_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_readlink_at((self).__handle, (uint8_t *) (path).ptr, (path).len, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_remove_directory_at(filesystem_borrow_descriptor_t self, wasip3_string_t path, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_remove_directory_at((self).__handle, (uint8_t *) (path).ptr, (path).len, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_rename_at(filesystem_method_descriptor_rename_at_args_t *args, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_rename_at((uint8_t*) args, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_symlink_at(filesystem_method_descriptor_symlink_at_args_t *args, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_symlink_at((uint8_t*) args, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_unlink_file_at(filesystem_borrow_descriptor_t self, wasip3_string_t path, filesystem_result_void_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_unlink_file_at((self).__handle, (uint8_t *) (path).ptr, (path).len, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_is_same_object(filesystem_borrow_descriptor_t self, filesystem_borrow_descriptor_t other, bool *result) { + return __wasm_import_filesystem_method_descriptor_is_same_object((self).__handle, (other).__handle, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_metadata_hash(filesystem_borrow_descriptor_t self, filesystem_result_metadata_hash_value_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_metadata_hash((self).__handle, (uint8_t*) result); +} + +wasip3_subtask_status_t filesystem_method_descriptor_metadata_hash_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip3_string_t path, filesystem_result_metadata_hash_value_error_code_t *result) { + return __wasm_import_filesystem_method_descriptor_metadata_hash_at((self).__handle, path_flags, (uint8_t *) (path).ptr, (path).len, (uint8_t*) result); +} + +void filesystem_preopens_get_directories(filesystem_preopens_list_tuple2_own_descriptor_string_t *ret) { + __attribute__((__aligned__(sizeof(void*)))) + uint8_t ret_area[(2*sizeof(void*))]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_filesystem_preopens_get_directories(ptr); + *ret = (filesystem_preopens_list_tuple2_own_descriptor_string_t) { (filesystem_preopens_tuple2_own_descriptor_string_t*)(*((uint8_t **) (ptr + 0))), (*((size_t*) (ptr + sizeof(void*)))) }; +} + +bool sockets_static_tcp_socket_create(sockets_ip_address_family_t address_family, sockets_own_tcp_socket_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_static_tcp_socket_create((int32_t) address_family, ptr); + sockets_result_own_tcp_socket_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (sockets_own_tcp_socket_t) { *((int32_t*) (ptr + 4)) }; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 4)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_bind(sockets_borrow_tcp_socket_t self, sockets_ip_socket_address_t *local_address, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t variant; + int32_t variant1; + int32_t variant2; + int32_t variant3; + int32_t variant4; + int32_t variant5; + int32_t variant6; + int32_t variant7; + int32_t variant8; + int32_t variant9; + int32_t variant10; + int32_t variant11; + switch ((int32_t) (*local_address).tag) { + case 0: { + const sockets_ipv4_socket_address_t *payload = &(*local_address).val.ipv4; + variant = 0; + variant1 = (int32_t) ((*payload).port); + variant2 = (int32_t) (((*payload).address).f0); + variant3 = (int32_t) (((*payload).address).f1); + variant4 = (int32_t) (((*payload).address).f2); + variant5 = (int32_t) (((*payload).address).f3); + variant6 = 0; + variant7 = 0; + variant8 = 0; + variant9 = 0; + variant10 = 0; + variant11 = 0; + break; + } + case 1: { + const sockets_ipv6_socket_address_t *payload0 = &(*local_address).val.ipv6; + variant = 1; + variant1 = (int32_t) ((*payload0).port); + variant2 = (int32_t) ((*payload0).flow_info); + variant3 = (int32_t) (((*payload0).address).f0); + variant4 = (int32_t) (((*payload0).address).f1); + variant5 = (int32_t) (((*payload0).address).f2); + variant6 = (int32_t) (((*payload0).address).f3); + variant7 = (int32_t) (((*payload0).address).f4); + variant8 = (int32_t) (((*payload0).address).f5); + variant9 = (int32_t) (((*payload0).address).f6); + variant10 = (int32_t) (((*payload0).address).f7); + variant11 = (int32_t) ((*payload0).scope_id); + break; + } + } + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_bind((self).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +wasip3_subtask_status_t sockets_method_tcp_socket_connect(sockets_method_tcp_socket_connect_args_t *args, sockets_result_void_error_code_t *result) { + return __wasm_import_sockets_method_tcp_socket_connect((uint8_t*) args, (uint8_t*) result); +} + +bool sockets_method_tcp_socket_listen(sockets_borrow_tcp_socket_t self, sockets_stream_own_tcp_socket_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_listen((self).__handle, ptr); + sockets_result_stream_own_tcp_socket_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = ((uint32_t) *((int32_t*) (ptr + 4))); + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 4)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +wasip3_subtask_status_t sockets_method_tcp_socket_send(sockets_borrow_tcp_socket_t self, sockets_stream_u8_t data, sockets_result_void_error_code_t *result) { + return __wasm_import_sockets_method_tcp_socket_send((self).__handle, ((int32_t) data), (uint8_t*) result); +} + +void sockets_method_tcp_socket_receive(sockets_borrow_tcp_socket_t self, sockets_tuple2_stream_u8_future_result_void_error_code_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_receive((self).__handle, ptr); + *ret = (sockets_tuple2_stream_u8_future_result_void_error_code_t) { + (sockets_stream_u8_t) ((uint32_t) *((int32_t*) (ptr + 0))), + (sockets_future_result_void_error_code_t) ((uint32_t) *((int32_t*) (ptr + 4))), + }; +} + +bool sockets_method_tcp_socket_get_local_address(sockets_borrow_tcp_socket_t self, sockets_ip_socket_address_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[36]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_get_local_address((self).__handle, ptr); + sockets_result_ip_socket_address_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + sockets_ip_socket_address_t variant; + variant.tag = (int32_t) *((uint8_t*) (ptr + 4)); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (sockets_ipv4_socket_address_t) { + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 8))), + (sockets_ipv4_address_t) (sockets_ipv4_address_t) { + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 10))), + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 11))), + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 12))), + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 13))), + }, + }; + break; + } + case 1: { + variant.val.ipv6 = (sockets_ipv6_socket_address_t) { + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 8))), + (uint32_t) (uint32_t) (*((int32_t*) (ptr + 12))), + (sockets_ipv6_address_t) (sockets_ipv6_address_t) { + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 16))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 18))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 20))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 22))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 24))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 26))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 28))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 30))), + }, + (uint32_t) (uint32_t) (*((int32_t*) (ptr + 32))), + }; + break; + } + } + + result.val.ok = variant; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 4)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_get_remote_address(sockets_borrow_tcp_socket_t self, sockets_ip_socket_address_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[36]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_get_remote_address((self).__handle, ptr); + sockets_result_ip_socket_address_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + sockets_ip_socket_address_t variant; + variant.tag = (int32_t) *((uint8_t*) (ptr + 4)); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (sockets_ipv4_socket_address_t) { + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 8))), + (sockets_ipv4_address_t) (sockets_ipv4_address_t) { + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 10))), + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 11))), + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 12))), + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 13))), + }, + }; + break; + } + case 1: { + variant.val.ipv6 = (sockets_ipv6_socket_address_t) { + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 8))), + (uint32_t) (uint32_t) (*((int32_t*) (ptr + 12))), + (sockets_ipv6_address_t) (sockets_ipv6_address_t) { + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 16))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 18))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 20))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 22))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 24))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 26))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 28))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 30))), + }, + (uint32_t) (uint32_t) (*((int32_t*) (ptr + 32))), + }; + break; + } + } + + result.val.ok = variant; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 4)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_get_is_listening(sockets_borrow_tcp_socket_t self) { + int32_t ret = __wasm_import_sockets_method_tcp_socket_get_is_listening((self).__handle); + return ret; +} + +sockets_ip_address_family_t sockets_method_tcp_socket_get_address_family(sockets_borrow_tcp_socket_t self) { + int32_t ret = __wasm_import_sockets_method_tcp_socket_get_address_family((self).__handle); + return ret; +} + +bool sockets_method_tcp_socket_set_listen_backlog_size(sockets_borrow_tcp_socket_t self, uint64_t value, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_set_listen_backlog_size((self).__handle, (int64_t) (value), ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_get_keep_alive_enabled(sockets_borrow_tcp_socket_t self, bool *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_get_keep_alive_enabled((self).__handle, ptr); + sockets_result_bool_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_set_keep_alive_enabled(sockets_borrow_tcp_socket_t self, bool value, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_set_keep_alive_enabled((self).__handle, value, ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_get_keep_alive_idle_time(sockets_borrow_tcp_socket_t self, sockets_duration_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_get_keep_alive_idle_time((self).__handle, ptr); + sockets_result_duration_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (uint64_t) (*((int64_t*) (ptr + 8))); + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 8)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_set_keep_alive_idle_time(sockets_borrow_tcp_socket_t self, sockets_duration_t value, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_set_keep_alive_idle_time((self).__handle, (int64_t) (value), ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_get_keep_alive_interval(sockets_borrow_tcp_socket_t self, sockets_duration_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_get_keep_alive_interval((self).__handle, ptr); + sockets_result_duration_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (uint64_t) (*((int64_t*) (ptr + 8))); + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 8)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_set_keep_alive_interval(sockets_borrow_tcp_socket_t self, sockets_duration_t value, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_set_keep_alive_interval((self).__handle, (int64_t) (value), ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_get_keep_alive_count(sockets_borrow_tcp_socket_t self, uint32_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_get_keep_alive_count((self).__handle, ptr); + sockets_result_u32_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (uint32_t) (*((int32_t*) (ptr + 4))); + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 4)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_set_keep_alive_count(sockets_borrow_tcp_socket_t self, uint32_t value, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_set_keep_alive_count((self).__handle, (int32_t) (value), ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_get_hop_limit(sockets_borrow_tcp_socket_t self, uint8_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_get_hop_limit((self).__handle, ptr); + sockets_result_u8_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (uint8_t) ((int32_t) *((uint8_t*) (ptr + 1))); + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_set_hop_limit(sockets_borrow_tcp_socket_t self, uint8_t value, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_set_hop_limit((self).__handle, (int32_t) (value), ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_get_receive_buffer_size(sockets_borrow_tcp_socket_t self, uint64_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_get_receive_buffer_size((self).__handle, ptr); + sockets_result_u64_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (uint64_t) (*((int64_t*) (ptr + 8))); + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 8)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_set_receive_buffer_size(sockets_borrow_tcp_socket_t self, uint64_t value, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_set_receive_buffer_size((self).__handle, (int64_t) (value), ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_get_send_buffer_size(sockets_borrow_tcp_socket_t self, uint64_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_get_send_buffer_size((self).__handle, ptr); + sockets_result_u64_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (uint64_t) (*((int64_t*) (ptr + 8))); + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 8)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_tcp_socket_set_send_buffer_size(sockets_borrow_tcp_socket_t self, uint64_t value, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_tcp_socket_set_send_buffer_size((self).__handle, (int64_t) (value), ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_static_udp_socket_create(sockets_ip_address_family_t address_family, sockets_own_udp_socket_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_static_udp_socket_create((int32_t) address_family, ptr); + sockets_result_own_udp_socket_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (sockets_own_udp_socket_t) { *((int32_t*) (ptr + 4)) }; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 4)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_udp_socket_bind(sockets_borrow_udp_socket_t self, sockets_ip_socket_address_t *local_address, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t variant; + int32_t variant1; + int32_t variant2; + int32_t variant3; + int32_t variant4; + int32_t variant5; + int32_t variant6; + int32_t variant7; + int32_t variant8; + int32_t variant9; + int32_t variant10; + int32_t variant11; + switch ((int32_t) (*local_address).tag) { + case 0: { + const sockets_ipv4_socket_address_t *payload = &(*local_address).val.ipv4; + variant = 0; + variant1 = (int32_t) ((*payload).port); + variant2 = (int32_t) (((*payload).address).f0); + variant3 = (int32_t) (((*payload).address).f1); + variant4 = (int32_t) (((*payload).address).f2); + variant5 = (int32_t) (((*payload).address).f3); + variant6 = 0; + variant7 = 0; + variant8 = 0; + variant9 = 0; + variant10 = 0; + variant11 = 0; + break; + } + case 1: { + const sockets_ipv6_socket_address_t *payload0 = &(*local_address).val.ipv6; + variant = 1; + variant1 = (int32_t) ((*payload0).port); + variant2 = (int32_t) ((*payload0).flow_info); + variant3 = (int32_t) (((*payload0).address).f0); + variant4 = (int32_t) (((*payload0).address).f1); + variant5 = (int32_t) (((*payload0).address).f2); + variant6 = (int32_t) (((*payload0).address).f3); + variant7 = (int32_t) (((*payload0).address).f4); + variant8 = (int32_t) (((*payload0).address).f5); + variant9 = (int32_t) (((*payload0).address).f6); + variant10 = (int32_t) (((*payload0).address).f7); + variant11 = (int32_t) ((*payload0).scope_id); + break; + } + } + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_udp_socket_bind((self).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_udp_socket_connect(sockets_borrow_udp_socket_t self, sockets_ip_socket_address_t *remote_address, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t variant; + int32_t variant1; + int32_t variant2; + int32_t variant3; + int32_t variant4; + int32_t variant5; + int32_t variant6; + int32_t variant7; + int32_t variant8; + int32_t variant9; + int32_t variant10; + int32_t variant11; + switch ((int32_t) (*remote_address).tag) { + case 0: { + const sockets_ipv4_socket_address_t *payload = &(*remote_address).val.ipv4; + variant = 0; + variant1 = (int32_t) ((*payload).port); + variant2 = (int32_t) (((*payload).address).f0); + variant3 = (int32_t) (((*payload).address).f1); + variant4 = (int32_t) (((*payload).address).f2); + variant5 = (int32_t) (((*payload).address).f3); + variant6 = 0; + variant7 = 0; + variant8 = 0; + variant9 = 0; + variant10 = 0; + variant11 = 0; + break; + } + case 1: { + const sockets_ipv6_socket_address_t *payload0 = &(*remote_address).val.ipv6; + variant = 1; + variant1 = (int32_t) ((*payload0).port); + variant2 = (int32_t) ((*payload0).flow_info); + variant3 = (int32_t) (((*payload0).address).f0); + variant4 = (int32_t) (((*payload0).address).f1); + variant5 = (int32_t) (((*payload0).address).f2); + variant6 = (int32_t) (((*payload0).address).f3); + variant7 = (int32_t) (((*payload0).address).f4); + variant8 = (int32_t) (((*payload0).address).f5); + variant9 = (int32_t) (((*payload0).address).f6); + variant10 = (int32_t) (((*payload0).address).f7); + variant11 = (int32_t) ((*payload0).scope_id); + break; + } + } + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_udp_socket_connect((self).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_udp_socket_disconnect(sockets_borrow_udp_socket_t self, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_udp_socket_disconnect((self).__handle, ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +wasip3_subtask_status_t sockets_method_udp_socket_send(sockets_method_udp_socket_send_args_t *args, sockets_result_void_error_code_t *result) { + return __wasm_import_sockets_method_udp_socket_send((uint8_t*) args, (uint8_t*) result); +} + +wasip3_subtask_status_t sockets_method_udp_socket_receive(sockets_borrow_udp_socket_t self, sockets_result_tuple2_list_u8_ip_socket_address_error_code_t *result) { + return __wasm_import_sockets_method_udp_socket_receive((self).__handle, (uint8_t*) result); +} + +bool sockets_method_udp_socket_get_local_address(sockets_borrow_udp_socket_t self, sockets_ip_socket_address_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[36]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_udp_socket_get_local_address((self).__handle, ptr); + sockets_result_ip_socket_address_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + sockets_ip_socket_address_t variant; + variant.tag = (int32_t) *((uint8_t*) (ptr + 4)); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (sockets_ipv4_socket_address_t) { + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 8))), + (sockets_ipv4_address_t) (sockets_ipv4_address_t) { + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 10))), + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 11))), + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 12))), + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 13))), + }, + }; + break; + } + case 1: { + variant.val.ipv6 = (sockets_ipv6_socket_address_t) { + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 8))), + (uint32_t) (uint32_t) (*((int32_t*) (ptr + 12))), + (sockets_ipv6_address_t) (sockets_ipv6_address_t) { + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 16))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 18))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 20))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 22))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 24))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 26))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 28))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 30))), + }, + (uint32_t) (uint32_t) (*((int32_t*) (ptr + 32))), + }; + break; + } + } + + result.val.ok = variant; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 4)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_udp_socket_get_remote_address(sockets_borrow_udp_socket_t self, sockets_ip_socket_address_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[36]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_udp_socket_get_remote_address((self).__handle, ptr); + sockets_result_ip_socket_address_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + sockets_ip_socket_address_t variant; + variant.tag = (int32_t) *((uint8_t*) (ptr + 4)); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (sockets_ipv4_socket_address_t) { + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 8))), + (sockets_ipv4_address_t) (sockets_ipv4_address_t) { + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 10))), + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 11))), + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 12))), + (uint8_t) (uint8_t) ((int32_t) *((uint8_t*) (ptr + 13))), + }, + }; + break; + } + case 1: { + variant.val.ipv6 = (sockets_ipv6_socket_address_t) { + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 8))), + (uint32_t) (uint32_t) (*((int32_t*) (ptr + 12))), + (sockets_ipv6_address_t) (sockets_ipv6_address_t) { + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 16))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 18))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 20))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 22))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 24))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 26))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 28))), + (uint16_t) (uint16_t) ((int32_t) *((uint16_t*) (ptr + 30))), + }, + (uint32_t) (uint32_t) (*((int32_t*) (ptr + 32))), + }; + break; + } + } + + result.val.ok = variant; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 4)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +sockets_ip_address_family_t sockets_method_udp_socket_get_address_family(sockets_borrow_udp_socket_t self) { + int32_t ret = __wasm_import_sockets_method_udp_socket_get_address_family((self).__handle); + return ret; +} + +bool sockets_method_udp_socket_get_unicast_hop_limit(sockets_borrow_udp_socket_t self, uint8_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_udp_socket_get_unicast_hop_limit((self).__handle, ptr); + sockets_result_u8_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (uint8_t) ((int32_t) *((uint8_t*) (ptr + 1))); + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_udp_socket_set_unicast_hop_limit(sockets_borrow_udp_socket_t self, uint8_t value, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_udp_socket_set_unicast_hop_limit((self).__handle, (int32_t) (value), ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_udp_socket_get_receive_buffer_size(sockets_borrow_udp_socket_t self, uint64_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_udp_socket_get_receive_buffer_size((self).__handle, ptr); + sockets_result_u64_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (uint64_t) (*((int64_t*) (ptr + 8))); + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 8)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_udp_socket_set_receive_buffer_size(sockets_borrow_udp_socket_t self, uint64_t value, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_udp_socket_set_receive_buffer_size((self).__handle, (int64_t) (value), ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_udp_socket_get_send_buffer_size(sockets_borrow_udp_socket_t self, uint64_t *ret, sockets_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_udp_socket_get_send_buffer_size((self).__handle, ptr); + sockets_result_u64_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (uint64_t) (*((int64_t*) (ptr + 8))); + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 8)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool sockets_method_udp_socket_set_send_buffer_size(sockets_borrow_udp_socket_t self, uint64_t value, sockets_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_sockets_method_udp_socket_set_send_buffer_size((self).__handle, (int64_t) (value), ptr); + sockets_result_void_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 1)); + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +wasip3_subtask_status_t ip_name_lookup_resolve_addresses(wasip3_string_t name, ip_name_lookup_result_list_ip_address_error_code_t *result) { + return __wasm_import_ip_name_lookup_resolve_addresses((uint8_t *) (name).ptr, (name).len, (uint8_t*) result); +} + +void random_get_random_bytes(uint64_t len, wasip3_list_u8_t *ret) { + __attribute__((__aligned__(sizeof(void*)))) + uint8_t ret_area[(2*sizeof(void*))]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_random_get_random_bytes((int64_t) (len), ptr); + *ret = (wasip3_list_u8_t) { (uint8_t*)(*((uint8_t **) (ptr + 0))), (*((size_t*) (ptr + sizeof(void*)))) }; +} + +uint64_t random_get_random_u64(void) { + int64_t ret = __wasm_import_random_get_random_u64(); + return (uint64_t) (ret); +} + +void random_insecure_get_insecure_random_bytes(uint64_t len, wasip3_list_u8_t *ret) { + __attribute__((__aligned__(sizeof(void*)))) + uint8_t ret_area[(2*sizeof(void*))]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_random_insecure_get_insecure_random_bytes((int64_t) (len), ptr); + *ret = (wasip3_list_u8_t) { (uint8_t*)(*((uint8_t **) (ptr + 0))), (*((size_t*) (ptr + sizeof(void*)))) }; +} + +uint64_t random_insecure_get_insecure_random_u64(void) { + int64_t ret = __wasm_import_random_insecure_get_insecure_random_u64(); + return (uint64_t) (ret); +} + +void random_insecure_seed_get_insecure_seed(wasip3_tuple2_u64_u64_t *ret) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_random_insecure_seed_get_insecure_seed(ptr); + *ret = (wasip3_tuple2_u64_u64_t) { + (uint64_t) (uint64_t) (*((int64_t*) (ptr + 0))), + (uint64_t) (uint64_t) (*((int64_t*) (ptr + 8))), + }; +} + +// Ensure that the *_component_type.o object is linked in + +extern void __component_type_object_force_link_wasip3(void); +__attribute__((used)) +void __component_type_object_force_link_wasip3_public_use_in_this_compilation_unit(void) { + __component_type_object_force_link_wasip3(); +} diff --git a/libc-bottom-half/sources/wasip3_component_type.o b/libc-bottom-half/sources/wasip3_component_type.o new file mode 100644 index 0000000000000000000000000000000000000000..2134f29a58f9add8550532cd099d3c263b8317a3 GIT binary patch literal 8092 zcmb_h>2}-36`mo$O%iD>wiWMdyhD$}@d6vR;|!pzDR zv3N7LQ!jpbbVQ#=zIW^}@QxU`uUwvcnbnYs(1~0xoSLlv_qY6q4*%f=KUm>WCrx?G z_&ZX^E=)yciSX1*qA-9G-r;ddYlg{2v}PyMoEB2pb|P20C6^a^nP>Z!Gk1BjJ;TxY(*qVlprRqFyIoqTT7-`rdrXR zj=?$#BR?2)up@|v@(|Magnxn;oO8hqM73j5*eE!OuwCoav#m74*MNf4C{8o%iB_@6 z4|>0&>5!YQo!K4Qo%MO*!DB^_X|Q{>gU}P@`rvi{---}rtw%k6fD{{NA_=?@TjYgt zo*CHTr?r{OYg#FNDdj><3Aaiy&(4Y|7PWG)jjY!)ri{e!td-bckMomGSqqy~3$+Py z6FK6oape3BUV#DqwjZShtH_&LeCc7!gsrv-AR`+zQTWW}ul)}SvCro#JTD1GRH}26 z4ct7jGcO8dC4O0MUF4jkyXP0<7$IA&Ir+gF7088UVI;ioh3F(-PK1-#2qN%NTq4Qf0qa~q8_4>Ql_J**67(cJQ*aLQ?QAXg_*!utl>Rm~2f zFv_CPb1cV)AKIi_=LcP$bo!}qqR>s}tDzl6<&OpVVP_)q0%}jCtmOU;#Snpr3~)h+MdKOp+~EoO+H}cV>2C zJIK%S!O-;*;bc*=Felz58l{WiIPwt)-wRLH5;4tvJF!S|FNGM9A-i3XI*Av9Ne(iD znLO;7)GNEPlWh?>T0|zMXlx5BU4+gSb-UKHiwX7kG!w2>bU-3p4{{6=VKsKKbw%OC zx2GwppND)5Tgggm68V0F0IbAzHnU2K0T0cd1EVt0_&5|F9Y0UKQ!&VrJan)KwkQ^1 z#kN8@xFW?m5faH@Yy5=sq-RoUca@cqDPw&}I%YeLNK=dUAK4qk<7@J9fU!OCpa!X` zEN&OG(!yqhQ=u#@2bZV}c7cB|hGA3^WAF>mA;Yy+8ESZsziY$Czc zMgt^d$--b;JhQDY@))~~5 z;6|KaetpbjWmy#FH7ALXL4`v|K?JMDJC}ISgWe>t{gnb25nSsfcIZaIa1PvLg+jPP zH-fkHjRKO0JVkc*Y?lh(VB1KEE-VzuybEXWVY012WVX!InVrro>`D&GD^TAgfx-Fg zS_P3V10vl7M7nW{zw4N(@F&-M(PWYeBuF%|qi zO&jSo5nk62QVX*vqWnw#p7;6XhU0;rgNB3bS^Ob5x+=#blU>v3kmv#3h(B&3QS^Nn zrDMSM$ok<=>e%bs*5>Eh*5-H=|H{2us?{{b<*s^r1w;@Asa0vF@zA@c|G)v55mmh)pICnTQF9-1VhL=zhd!qvpC=%3dy|Bq;Ni@<5?r$U@HVs2~+*rFLm|-NTiP9q|r!QCUNy6h4`2ij-P`K6JuQ%oh4<_x@ySc|r|Jpxk2RZ8jn2Kz#pObS2c3BOXc zh3#>fA1Yhj#1*zOLC_RvB){j^q|tIhZL{kN%29ZHAbSz=8xrl6-FaJrtefXqmjYt( zTR??hVC>(#jkuI5?kF=rQ2|sfaQxzTVbX?b(me&lDfCqHOL5}&P4;Eg*jj|kp#fT} ztw9s5ds&MKjkNF^7p#C9H4ELuM>-b5(hW`oFYO{i(^G{=Rz8 z#VMcq9Dmj_fRh0_2`vK}2>^+@fVCW!XGnyYKhu-9#nX|K$SpXyP#px?eE9ng$_oHY zBP0jV$4y&+L9roL*aQ11JY80qYx*kT99O1xe@h5(=QQ@wA z*f?|iNOs%r(P`gqAVB}1X;L0Y_t`%&(&|B=@Khc5pfOYJwF)I|+;Xoy zRC-{Gu+?i18|iA}Y%#SO=Z_5&%HmN~ku9bi_p)}X=J_A%y($`>EDs$!W$sz_KQ(IA z0%@t$W&BSq#mk*u5pZ6~{H&CWLar^DpY*gO`b^3EY_JCsgBO72a~JX30Kw}D5-Z<| zA>)*Xbcr4G^g#Fw^xcqWBm%6smOrJLbQNa+Ks!5GpmEScbeM_l`FSF)(&d;f--5Q6 zV1at;h4+^nS#B0dPC8P0DYsFwRlo@c0lbzguJbGJf$XGBxKKRFW9@bR6}rwxExzLh z?tpNkiuZ7`FUm_b`3^G0RK(E(_hiKlezB6je#H^OBHYCl+-~uq)pPZ%o-3pWw~@j@ zJgkDZrEptEQfe+<&z71iFtLQMy{8z>fFJ zw-?^7N86lfPg^Ei9dW$QDJYOo?8hN)gWcQ_Ny^vom9ETj_kX +#include + +#ifdef __wasip3__ + +int __wasilibc_add_file(filesystem_own_descriptor_t file_handle, int oflag) { + // TODO(wasip3) + errno = EOPNOTSUPP; + return -1; +} + +#endif // __wasip3__ diff --git a/libc-bottom-half/sources/wasip3_stdio.c b/libc-bottom-half/sources/wasip3_stdio.c new file mode 100644 index 000000000..5de4aa9f6 --- /dev/null +++ b/libc-bottom-half/sources/wasip3_stdio.c @@ -0,0 +1,11 @@ +#include +#include + +#ifdef __wasip3__ + +int __wasilibc_init_stdio() { + // TODO(wasip3) + errno = EOPNOTSUPP; + return -1; +} +#endif // __wasip3__ diff --git a/libc-bottom-half/sources/wasip3_tcp.c b/libc-bottom-half/sources/wasip3_tcp.c new file mode 100644 index 000000000..8861cbbbf --- /dev/null +++ b/libc-bottom-half/sources/wasip3_tcp.c @@ -0,0 +1,13 @@ +#include +#include + +#ifdef __wasip3__ + +int __wasilibc_add_tcp_socket(sockets_own_tcp_socket_t socket, + sockets_ip_address_family_t family, + bool blocking) { + // TODO(wasip3) + errno = ENOTSUP; + return -1; +} +#endif // __wasip3__ diff --git a/libc-bottom-half/sources/wasip3_udp.c b/libc-bottom-half/sources/wasip3_udp.c new file mode 100644 index 000000000..bd696e65a --- /dev/null +++ b/libc-bottom-half/sources/wasip3_udp.c @@ -0,0 +1,13 @@ +#include +#include + +#ifdef __wasip3__ + +int __wasilibc_add_udp_socket(sockets_own_tcp_socket_t socket, + sockets_ip_address_family_t family, + bool blocking) { + // TODO(wasip3) + errno = ENOTSUP; + return -1; +} +#endif // __wasip3__ diff --git a/libc-top-half/CMakeLists.txt b/libc-top-half/CMakeLists.txt index 7d76d1b2f..8dcf63abc 100644 --- a/libc-top-half/CMakeLists.txt +++ b/libc-top-half/CMakeLists.txt @@ -383,7 +383,7 @@ list(REMOVE_ITEM globbed_sources list(APPEND top_half_sources ${globbed_sources}) -if (WASI STREQUAL "p2") +if (NOT (WASI STREQUAL "p1")) list(APPEND top_half_sources musl/src/network/gai_strerror.c ) diff --git a/libc-top-half/musl/src/env/__stack_chk_fail.c b/libc-top-half/musl/src/env/__stack_chk_fail.c index 0d3b11082..17d77d890 100644 --- a/libc-top-half/musl/src/env/__stack_chk_fail.c +++ b/libc-top-half/musl/src/env/__stack_chk_fail.c @@ -46,7 +46,7 @@ static void __wasilibc_init_ssp(void) { uintptr_t entropy; #if defined(__wasip1__) int r = __wasi_random_get((uint8_t *)&entropy, sizeof(uintptr_t)); -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) int len = sizeof(uintptr_t); int r = __wasilibc_random(&entropy, len); #else diff --git a/libc-top-half/sources/arc4random.c b/libc-top-half/sources/arc4random.c index 957e612fe..f108a92aa 100644 --- a/libc-top-half/sources/arc4random.c +++ b/libc-top-half/sources/arc4random.c @@ -17,7 +17,7 @@ void arc4random_buf(void* buffer, size_t len) // raw-entropy-style implementation. #if defined(__wasip1__) int r = __wasi_random_get(buffer, len); -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) int r = __wasilibc_random(buffer, len); #else # error "Unknown WASI version" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4ad3ee728..e33c39a02 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -24,7 +24,7 @@ if(NOT ENGINE OR ENGINE STREQUAL "") ba_download( wasmtime "https://github.com/bytecodealliance/wasmtime" - "v38.0.2" + "v40.0.0" ) ExternalProject_Get_Property(wasmtime SOURCE_DIR) set(ENGINE "${SOURCE_DIR}/wasmtime") @@ -98,8 +98,9 @@ endfunction() # * `ENV a=b b=c` - set env vars for when executing this test # * `NETWORK` - this test uses the network and sockets. # * `PASS_REGULAR_EXPRESSION` - a regex that must match the test output to pass +# * `FAILP3` - this test fails on wasip3 targets function(register_test test_name executable_name) - set(options FS NETWORK) + set(options FS NETWORK FAILP3) set(oneValueArgs CLIENT PASS_REGULAR_EXPRESSION) set(multiValueArgs ARGV ENV LDFLAGS CFLAGS) cmake_parse_arguments(PARSE_ARGV 1 arg "${options}" "${oneValueArgs}" "${multiValueArgs}") @@ -117,7 +118,11 @@ function(register_test test_name executable_name) list(APPEND wasmtime_args --env ${env}) endforeach() if (TARGET_TRIPLE MATCHES "-threads") - list(APPEND wasmtime_args --wasi threads) + list(APPEND wasmtime_args --wasi threads --wasm shared-memory) + endif() + if (WASI STREQUAL "p3") + list(APPEND wasmtime_args --wasm component-model-async) + list(APPEND wasmtime_args --wasi p3) endif() add_test( @@ -149,6 +154,10 @@ function(register_test test_name executable_name) endif() set_tests_properties(${test_name} PROPERTIES TIMEOUT 10) + if (arg_FAILP3 AND (WASI STREQUAL "p3")) + set_tests_properties(${test_name} PROPERTIES WILL_FAIL TRUE) + endif() + add_dependencies(${test_name} engine) endfunction() @@ -227,48 +236,48 @@ endfunction() # TODO: this test fails with `-Sthreads` in Wasmtime since that uses a different # implementation of WASI which causes this test to fail. if (NOT TARGET_TRIPLE MATCHES "-threads") - add_wasilibc_test(access.c FS) + add_wasilibc_test(access.c FS FAILP3) endif() -add_wasilibc_test(append.c FS) +add_wasilibc_test(append.c FS FAILP3) add_wasilibc_test(argv_two_args.c ARGV foo bar) -add_wasilibc_test(clock_nanosleep.c) -add_wasilibc_test(chdir.c FS) -add_wasilibc_test(close.c FS) +add_wasilibc_test(clock_nanosleep.c FAILP3) +add_wasilibc_test(chdir.c FS FAILP3) +add_wasilibc_test(close.c FS FAILP3) add_wasilibc_test(external_env.c ENV VAR1=foo VAR2=bar) -add_wasilibc_test(fadvise.c FS) -add_wasilibc_test(fallocate.c FS) -add_wasilibc_test(fcntl.c FS) -add_wasilibc_test(fdatasync.c FS) -add_wasilibc_test(fdopen.c FS) -add_wasilibc_test(feof.c FS) -add_wasilibc_test(file_permissions.c FS) -add_wasilibc_test(file_nonblocking.c FS) -add_wasilibc_test(fseek.c FS) -add_wasilibc_test(fstat.c FS) -add_wasilibc_test(fsync.c FS) -add_wasilibc_test(ftruncate.c FS) -add_wasilibc_test(fts.c FS) -add_wasilibc_test(fwscanf.c FS) +add_wasilibc_test(fadvise.c FS FAILP3) +add_wasilibc_test(fallocate.c FS FAILP3) +add_wasilibc_test(fcntl.c FS FAILP3) +add_wasilibc_test(fdatasync.c FS FAILP3) +add_wasilibc_test(fdopen.c FS FAILP3) +add_wasilibc_test(feof.c FS FAILP3) +add_wasilibc_test(file_permissions.c FS FAILP3) +add_wasilibc_test(file_nonblocking.c FS FAILP3) +add_wasilibc_test(fseek.c FS FAILP3) +add_wasilibc_test(fstat.c FS FAILP3) +add_wasilibc_test(fsync.c FS FAILP3) +add_wasilibc_test(ftruncate.c FS FAILP3) +add_wasilibc_test(fts.c FS FAILP3) +add_wasilibc_test(fwscanf.c FS FAILP3) add_wasilibc_test(getentropy.c) -add_wasilibc_test(hello.c PASS_REGULAR_EXPRESSION "Hello, World!") -add_wasilibc_test(ioctl.c FS) -add_wasilibc_test(isatty.c FS) -add_wasilibc_test(link.c FS) -add_wasilibc_test(lseek.c FS) +add_wasilibc_test(hello.c PASS_REGULAR_EXPRESSION "Hello, World!" FAILP3) +add_wasilibc_test(ioctl.c FS FAILP3) +add_wasilibc_test(isatty.c FS FAILP3) +add_wasilibc_test(link.c FS FAILP3) +add_wasilibc_test(lseek.c FS FAILP3) add_wasilibc_test(memchr.c LDFLAGS -Wl,--stack-first -Wl,--initial-memory=327680) add_wasilibc_test(memcmp.c LDFLAGS -Wl,--stack-first -Wl,--initial-memory=327680) -add_wasilibc_test(opendir.c FS ARGV /) -add_wasilibc_test(open_relative_path.c FS ARGV /) -add_wasilibc_test(poll.c FS) -add_wasilibc_test(preadvwritev.c FS) -add_wasilibc_test(preadwrite.c FS) -add_wasilibc_test(readlink.c FS) -add_wasilibc_test(readv.c FS) -add_wasilibc_test(rename.c FS) -add_wasilibc_test(rmdir.c FS) -add_wasilibc_test(scandir.c FS) -add_wasilibc_test(stat.c FS) -add_wasilibc_test(stdio.c FS) +add_wasilibc_test(opendir.c FS FAILP3 ARGV /) +add_wasilibc_test(open_relative_path.c FS FAILP3 ARGV /) +add_wasilibc_test(poll.c FS FAILP3) +add_wasilibc_test(preadvwritev.c FS FAILP3) +add_wasilibc_test(preadwrite.c FS FAILP3) +add_wasilibc_test(readlink.c FS FAILP3) +add_wasilibc_test(readv.c FS FAILP3) +add_wasilibc_test(rename.c FS FAILP3) +add_wasilibc_test(rmdir.c FS FAILP3) +add_wasilibc_test(scandir.c FS FAILP3) +add_wasilibc_test(stat.c FS FAILP3) +add_wasilibc_test(stdio.c FS FAILP3) add_wasilibc_test(strchrnul.c LDFLAGS -Wl,--stack-first -Wl,--initial-memory=327680) add_wasilibc_test(strlen.c LDFLAGS -Wl,--stack-first -Wl,--initial-memory=327680) add_wasilibc_test(strptime.c) @@ -277,12 +286,12 @@ add_wasilibc_test(time_and_times.c CFLAGS -D_WASI_EMULATED_PROCESS_CLOCKS LDFLAGS -lwasi-emulated-process-clocks) add_wasilibc_test(time.c) -add_wasilibc_test(utime.c FS) -add_wasilibc_test(rewinddir.c FS) -add_wasilibc_test(seekdir.c FS) -add_wasilibc_test(usleep.c) -add_wasilibc_test(nanosleep.c) -add_wasilibc_test(write.c FS) +add_wasilibc_test(utime.c FS FAILP3) +add_wasilibc_test(rewinddir.c FS FAILP3) +add_wasilibc_test(seekdir.c FS FAILP3) +add_wasilibc_test(usleep.c FAILP3) +add_wasilibc_test(nanosleep.c FAILP3) +add_wasilibc_test(write.c FS FAILP3) if (TARGET_TRIPLE MATCHES "-threads") add_wasilibc_test(busywait.c) @@ -293,12 +302,12 @@ endif() # ========= sockets-related tests =============================== -if (TARGET_TRIPLE MATCHES "wasip2") - add_wasilibc_test(poll-nonblocking-socket.c NETWORK) - add_wasilibc_test(setsockopt.c NETWORK) - add_wasilibc_test(sockets-nonblocking-udp.c NETWORK) - add_wasilibc_test(sockets-nonblocking-multiple.c NETWORK) - add_wasilibc_test(sockets-nonblocking-udp-multiple.c NETWORK) +if (NOT (WASI STREQUAL "p1")) + add_wasilibc_test(poll-nonblocking-socket.c NETWORK FAILP3) + add_wasilibc_test(setsockopt.c NETWORK FAILP3) + add_wasilibc_test(sockets-nonblocking-udp.c NETWORK FAILP3) + add_wasilibc_test(sockets-nonblocking-multiple.c NETWORK FAILP3) + add_wasilibc_test(sockets-nonblocking-udp-multiple.c NETWORK FAILP3) # TODO: flaky tests # add_wasilibc_test(sockets-nonblocking.c NETWORK) @@ -330,7 +339,7 @@ if (TARGET_TRIPLE MATCHES "wasip2") add_sockets_test_executable(sockets-multiple-server.c) function(sockets_test test_name client server) - set(options) + set(options FAILP3) set(oneValueArgs NCLIENTS) set(multiValueArgs) cmake_parse_arguments(PARSE_ARGV 1 arg "${options}" "${oneValueArgs}" "${multiValueArgs}") @@ -346,34 +355,48 @@ if (TARGET_TRIPLE MATCHES "wasip2") -P ${CMAKE_CURRENT_SOURCE_DIR}/socket-test.cmake ) set_tests_properties(${test_name} PROPERTIES RESOURCE_LOCK socket-test) + + if (arg_FAILP3 AND (WASI STREQUAL "p3")) + set_tests_properties(${test_name} PROPERTIES WILL_FAIL TRUE) + endif() endfunction() - sockets_test(sockets sockets-client.wasm sockets-server.wasm) - sockets_test(sockets-udp-blocking sockets-client-udp-blocking.wasm sockets-server-udp-blocking.wasm) + sockets_test(sockets sockets-client.wasm sockets-server.wasm FAILP3) + sockets_test(sockets-udp-blocking sockets-client-udp-blocking.wasm + sockets-server-udp-blocking.wasm FAILP3) sockets_test(sockets-multiple sockets-multiple-client.wasm sockets-multiple-server.wasm - NCLIENTS 10) + NCLIENTS 10 FAILP3) # Various forms of client hangups sockets_test(sockets-client-hangup-after-connect - sockets-client-hangup-after-connect.wasm sockets-server-handle-hangups.wasm) + sockets-client-hangup-after-connect.wasm sockets-server-handle-hangups.wasm + FAILP3) sockets_test(sockets-client-hangup-while-sending - sockets-client-hangup-while-sending.wasm sockets-server-handle-hangups.wasm) + sockets-client-hangup-while-sending.wasm sockets-server-handle-hangups.wasm + FAILP3) sockets_test(sockets-client-hangup-after-sending - sockets-client-hangup-after-sending.wasm sockets-server-handle-hangups.wasm) + sockets-client-hangup-after-sending.wasm sockets-server-handle-hangups.wasm + FAILP3) sockets_test(sockets-client-hangup-while-receiving - sockets-client-hangup-while-receiving.wasm sockets-server-handle-hangups.wasm) + sockets-client-hangup-while-receiving.wasm sockets-server-handle-hangups.wasm + FAILP3) # Various forms of server hangups, including when there's no server at all sockets_test(sockets-server-hangup-before-send - sockets-client-handle-hangups.wasm sockets-server-hangup-before-send.wasm) + sockets-client-handle-hangups.wasm sockets-server-hangup-before-send.wasm + FAILP3) sockets_test(sockets-server-hangup-during-send - sockets-client-handle-hangups.wasm sockets-server-hangup-during-send.wasm) + sockets-client-handle-hangups.wasm sockets-server-hangup-during-send.wasm + FAILP3) sockets_test(sockets-server-hangup-before-recv - sockets-client-handle-hangups.wasm sockets-server-hangup-before-recv.wasm) + sockets-client-handle-hangups.wasm sockets-server-hangup-before-recv.wasm + FAILP3) sockets_test(sockets-server-hangup-during-recv - sockets-client-handle-hangups.wasm sockets-server-hangup-during-recv.wasm) + sockets-client-handle-hangups.wasm sockets-server-hangup-during-recv.wasm + FAILP3) sockets_test(sockets-client-handle-hangups - sockets-client-handle-hangups.wasm hello.wasm) + sockets-client-handle-hangups.wasm hello.wasm + FAILP3) endif() # Flag some tests as failing in V8 diff --git a/test/scripts/browser-test/harness.mjs b/test/scripts/browser-test/harness.mjs index 6996ccd32..6a6a74129 100755 --- a/test/scripts/browser-test/harness.mjs +++ b/test/scripts/browser-test/harness.mjs @@ -92,6 +92,10 @@ async function main() { type: "string", multiple: true, }, + wasm: { + type: "string", + multiple: true, + }, dir: { type: "string", multiple: true, diff --git a/test/socket-test.cmake b/test/socket-test.cmake index 5ae9b1e3b..684f1d060 100644 --- a/test/socket-test.cmake +++ b/test/socket-test.cmake @@ -10,11 +10,11 @@ if (NOT NCLIENTS) endif() foreach(i RANGE 1 ${NCLIENTS}) - list(APPEND CLIENTS COMMAND bash -c "exec ${ENGINE} -Sinherit-network ${CLIENT} 1>&2") + list(APPEND CLIENTS COMMAND bash -c "exec ${ENGINE} -Sp3,inherit-network ${CLIENT} 1>&2") endforeach() execute_process( - COMMAND bash -c "exec ${ENGINE} -Sinherit-network ${SERVER} 1>&2" + COMMAND bash -c "exec ${ENGINE} -Sp3,inherit-network ${SERVER} 1>&2" ${CLIENTS} TIMEOUT 5 COMMAND_ERROR_IS_FATAL ANY diff --git a/test/src/ioctl.c b/test/src/ioctl.c index 282373428..d3494dfb4 100644 --- a/test/src/ioctl.c +++ b/test/src/ioctl.c @@ -28,8 +28,8 @@ int main(void) { #if defined(__wasip1__) // Always returns 0? TEST(ioctl(fd, FIONREAD, &nbytes) == 0); -#elif defined(__wasip2__) - // Not supported on wasip2 +#elif defined(__wasip2__) || defined(__wasip3__) + // Not supported on wasip{2,3} TEST(ioctl(fd, FIONREAD, &nbytes) == -1); #else #error "Unknown WASI version" diff --git a/test/src/sockets-multiple-server.c b/test/src/sockets-multiple-server.c index 863e2f30a..3b8a63233 100644 --- a/test/src/sockets-multiple-server.c +++ b/test/src/sockets-multiple-server.c @@ -39,6 +39,9 @@ void run_tcp_server() { int server_port = 4001; // Use blocking sockets int server_socket_fd = socket(AF_INET, SOCK_STREAM, 0); + TEST(server_socket_fd != -1); + if (server_socket_fd == -1) + return; // Bind server to socket struct sockaddr_in server_address; diff --git a/test/src/sockets-nonblocking-udp.c b/test/src/sockets-nonblocking-udp.c index 6d2deb1ea..91d9e0780 100644 --- a/test/src/sockets-nonblocking-udp.c +++ b/test/src/sockets-nonblocking-udp.c @@ -25,6 +25,9 @@ void test_udp_client() { int server_port = 4001; // Use non-blocking sockets int server_socket_fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, 0); + TEST(server_socket_fd != -1); + if (server_socket_fd == -1) + return; // Bind server to socket struct sockaddr_in server_address; diff --git a/test/src/sockets-server-udp-blocking.c b/test/src/sockets-server-udp-blocking.c index 16af04091..88b5c68ac 100644 --- a/test/src/sockets-server-udp-blocking.c +++ b/test/src/sockets-server-udp-blocking.c @@ -26,6 +26,9 @@ void run_udp_server() { int server_port = 4001; // Use blocking sockets int server_socket_fd = socket(AF_INET, SOCK_DGRAM, 0); + TEST(server_socket_fd != -1); + if (server_socket_fd == -1) + return; // Bind server to socket struct sockaddr_in server_address; diff --git a/test/src/sockets-server.c b/test/src/sockets-server.c index cc1a6f95f..0063a7ba9 100644 --- a/test/src/sockets-server.c +++ b/test/src/sockets-server.c @@ -25,6 +25,9 @@ void run_tcp_server() { int server_port = 4001; // Use blocking sockets int server_socket_fd = socket(AF_INET, SOCK_STREAM, 0); + TEST(server_socket_fd != -1); + if (server_socket_fd == -1) + return; // Bind server to socket struct sockaddr_in server_address; From c3fd350f2265c4ba3d39544c9dd3fc5dd9820a53 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 6 Jan 2026 11:27:25 -0800 Subject: [PATCH 02/41] Fix bindings target with wit-bindgen in environment --- cmake/bindings.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index 9ffd02b8e..1d4e6a1d5 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -31,6 +31,7 @@ if (NOT WIT_BINDGEN_EXECUTABLE) ExternalProject_Get_Property(wit-bindgen SOURCE_DIR) set(wit_bindgen "${SOURCE_DIR}/wit-bindgen") else() + add_custom_target(wit-bindgen) set(wit_bindgen ${WIT_BINDGEN_EXECUTABLE}) endif() From 99eb7153929563e59c7f64d224aabc59a9fd299b Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 7 Jan 2026 14:27:46 -0800 Subject: [PATCH 03/41] wasip2: Improve "command" startup flow This commit is an improvement to the WASIp2 target which changes how the interface `wasi:cli/run` is defined and exported. Previously the `wasm32-wasip2` target would define a `_start` wasm export which required the use of the WASIp1-to-WASIp2 adapter to hook it up to `wasi:cli/run`. This meant that despite libc not actually using any WASIp2 APIs the adapter was still used. The purpose of this commit is to change this. The changes made here are: * The linker-level `_start` symbol now has a wasm-level export name of `wasi:cli/run@0.2.0#run`. This means that `_start` isn't a wasm-level export any more, meaning there's nothing for the adapter to import. * The signature of the C-level `_start` function is now different based on WASI version (returns an `int` in WASIp2, nothing on WASIp1) * The `crt1-command.o` object file now contains type information for `wasi:cli/run` (which previously wasn't present anywhere in wasi-libc). This means that when this object is linked in `wit-component` will know what to do after linking. The end result is that binaries are now produced entirely without the WASIp1-to-WASIp2 adapter and linking with `-Wl,--wasi-adapter=none`, for example, produces a working binary. Another minor change made in this commit is that the `crt1-*.c` files are now included in `clang-format` like all other source files. Build-wise this requires the usage of `wasm-tools` at build-time to embed type information in the clang-produced object file for `crt1-command.o`. --- CMakeLists.txt | 1 + cmake/bindings.cmake | 1 + cmake/wasm-tools.cmake | 15 ++++++ libc-bottom-half/CMakeLists.txt | 73 ++++++++++++++++++------- libc-bottom-half/crt/crt1-command.c | 83 ++++++++++++++++------------- libc-bottom-half/crt/crt1-reactor.c | 29 +++++----- libc-bottom-half/crt/crt1.c | 3 -- 7 files changed, 130 insertions(+), 75 deletions(-) create mode 100644 cmake/wasm-tools.cmake delete mode 100644 libc-bottom-half/crt/crt1.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d2630581..35dfaaa4d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -143,6 +143,7 @@ if (NOT (WASI STREQUAL "p1")) endif() include(check-symbols) include(clang-format) +include(wasm-tools) # ============================================================================= # Generic top-level build flags/settings diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index dc2806485..d928c3bee 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -31,6 +31,7 @@ if (NOT WIT_BINDGEN_EXECUTABLE) ExternalProject_Get_Property(wit-bindgen SOURCE_DIR) set(wit_bindgen "${SOURCE_DIR}/wit-bindgen") else() + add_custom_target(wit-bindgen) set(wit_bindgen ${WIT_BINDGEN_EXECUTABLE}) endif() diff --git a/cmake/wasm-tools.cmake b/cmake/wasm-tools.cmake new file mode 100644 index 000000000..6018a9918 --- /dev/null +++ b/cmake/wasm-tools.cmake @@ -0,0 +1,15 @@ +# Favor `wasm-tools` on the system +find_program(WASM_TOOLS_EXECUTABLE NAMES wasm-tools) +if (NOT WASM_TOOLS_EXECUTABLE) + include(ba-download) + ba_download( + wasm-tools + "https://github.com/bytecodealliance/wasm-tools" + "1.244.0" + ) + ExternalProject_Get_Property(wasm-tools SOURCE_DIR) + set(wasm_tools "${SOURCE_DIR}/wasm-tools") +else() + add_custom_target(wasm-tools) + set(wasm_tools ${WASM_TOOLS_EXECUTABLE}) +endif() diff --git a/libc-bottom-half/CMakeLists.txt b/libc-bottom-half/CMakeLists.txt index 999474805..299f9a453 100644 --- a/libc-bottom-half/CMakeLists.txt +++ b/libc-bottom-half/CMakeLists.txt @@ -161,31 +161,66 @@ foreach(obj bottom-half-shared bottom-half-static) ) endforeach() -add_custom_target(sysroot-startup-objects) -add_dependencies(sysroot sysroot-startup-objects) # ============================================================================= # startup objects # -foreach(file crt/crt1.c - crt/crt1-command.c +# This is the logic for building `crt1{,-reactor,-command}.o` objects which +# Clang will link by default based on compiler flags. These are compiled into +# "object libraries" with CMake and then they're copied into the final location +# with adjustments based on WASI versions. +foreach(file crt/crt1-command.c crt/crt1-reactor.c) - # get the filename without the directory and extension - cmake_path(GET file STEM filename) + cmake_path(GET file STEM stem) + add_library(${stem} OBJECT ${file}) + clang_format_target(${stem}) + target_link_libraries(${stem} PUBLIC musl-top-half-interface) + set_pic(${stem}) + target_compile_options(${stem} PRIVATE -fvisibility=default) +endforeach() - # create a custom target for each file - add_library(${filename}.o OBJECT ${file}) - target_link_libraries(${filename}.o PUBLIC musl-top-half-interface) - set_pic(${filename}.o) - target_compile_options(${filename}.o PRIVATE -fvisibility=default) +# crt1-reactor.o is a straight copy of what CMake produces +add_custom_command( + OUTPUT ${SYSROOT_LIB}/crt1-reactor.o + COMMAND ${CMAKE_COMMAND} -E copy $ ${SYSROOT_LIB}/crt1-reactor.o + DEPENDS crt1-reactor $ +) - # add a custom command to compile the file - set(dst ${SYSROOT_LIB}/${filename}.o) +if (WASI STREQUAL "p1") + # wasip1: crt1-command.o is a straight copy of what CMake produces add_custom_command( - OUTPUT ${dst} - COMMAND ${CMAKE_COMMAND} -E copy $ ${dst} - DEPENDS ${filename}.o + OUTPUT ${SYSROOT_LIB}/crt1-command.o + COMMAND ${CMAKE_COMMAND} -E copy $ ${SYSROOT_LIB}/crt1-command.o + DEPENDS crt1-command $ ) - add_custom_target(sysroot-startup-${filename}.o DEPENDS ${dst}) - add_dependencies(sysroot-startup-objects sysroot-startup-${filename}.o) -endforeach() +else() + # wasip2+: crt1-command.o is modified from what CMake produces to + # additionally have a custom section representing the type information needed + # for its contained export. This is the `wasi:cli/run` interface, for example. + add_custom_command( + OUTPUT ${SYSROOT_LIB}/crt1-command.o + COMMAND + ${wasm_tools} component embed + ${wit_dir} + $ + --world wasi:cli/command@0.2.0 + -o ${SYSROOT_LIB}/crt1-command.o + DEPENDS crt1-command wasi-wits $ + ) +endif() + +# Provide a plain crt1.o for toolchain compatibility, identical to +# `crt1-command.c` +add_custom_command( + OUTPUT ${SYSROOT_LIB}/crt1.o + COMMAND ${CMAKE_COMMAND} -E copy ${SYSROOT_LIB}/crt1-command.o ${SYSROOT_LIB}/crt1.o + DEPENDS ${SYSROOT_LIB}/crt1-command.o +) + +add_custom_target(sysroot-startup-objects + DEPENDS + ${SYSROOT_LIB}/crt1-reactor.o + ${SYSROOT_LIB}/crt1-command.o + ${SYSROOT_LIB}/crt1.o +) +add_dependencies(sysroot sysroot-startup-objects) diff --git a/libc-bottom-half/crt/crt1-command.c b/libc-bottom-half/crt/crt1-command.c index 0f5d30211..b108b2309 100644 --- a/libc-bottom-half/crt/crt1-command.c +++ b/libc-bottom-half/crt/crt1-command.c @@ -9,54 +9,61 @@ extern void __wasm_call_ctors(void); extern int __main_void(void); extern void __wasm_call_dtors(void); -__attribute__((export_name("_start"))) -void _start(void) { - // Commands should only be called once per instance. This simple check - // ensures that the `_start` function isn't started more than once. - // - // We use `volatile` here to prevent the store to `started` from being - // sunk past any subsequent code, and to prevent any compiler from - // optimizing based on the knowledge that `_start` is the program - // entrypoint. +#if defined(__wasip1__) +__attribute__((export_name("_start"))) void _start(void) +#elif defined(__wasip2__) +// Note that this is manually doing what `wit-bindgen` might otherwise be +// doing. Given the special nature of this symbol this skip the typical +// `wit-bindgen` rigamarole and the signature of this function is simple enough +// that this shouldn't be too problematic (in theory). +__attribute__((export_name("wasi:cli/run@0.2.0#run"))) int _start(void) +#else +#error "Unsupported WASI version" +#endif +{ + // Commands should only be called once per instance. This simple check + // ensures that the `_start` function isn't started more than once. + // + // We use `volatile` here to prevent the store to `started` from being + // sunk past any subsequent code, and to prevent any compiler from + // optimizing based on the knowledge that `_start` is the program + // entrypoint. #ifdef _REENTRANT - static volatile _Atomic int started = 0; - int expected = 0; - if (!atomic_compare_exchange_strong(&started, &expected, 1)) { - __builtin_trap(); - } + static volatile _Atomic int started = 0; + int expected = 0; + if (!atomic_compare_exchange_strong(&started, &expected, 1)) { + __builtin_trap(); + } #else - static volatile int started = 0; - if (started != 0) { - __builtin_trap(); - } - started = 1; + static volatile int started = 0; + if (started != 0) { + __builtin_trap(); + } + started = 1; #endif - __wasi_init_tp(); + __wasi_init_tp(); - // The linker synthesizes this to call constructors. - __wasm_call_ctors(); + // The linker synthesizes this to call constructors. + __wasm_call_ctors(); - // Call `__main_void` which will either be the application's zero-argument - // `__main_void` function or a libc routine which obtains the command-line - // arguments and calls `__main_argv_argc`. - int r = __main_void(); + // Call `__main_void` which will either be the application's zero-argument + // `__main_void` function or a libc routine which obtains the command-line + // arguments and calls `__main_argv_argc`. + int r = __main_void(); - // Call atexit functions, destructors, stdio cleanup, etc. - __wasm_call_dtors(); + // Call atexit functions, destructors, stdio cleanup, etc. + __wasm_call_dtors(); - // If main exited successfully, just return, otherwise call - // `__wasi_proc_exit`. + // If main exited successfully, just return, otherwise call + // `__wasi_proc_exit`. #if defined(__wasip1__) - if (r != 0) { - __wasi_proc_exit(r); - } + if (r != 0) { + __wasi_proc_exit(r); + } #elif defined(__wasip2__) - if (r != 0) { - exit_result_void_void_t status = { .is_err = true }; - exit_exit(&status); - } + return r != 0; #else -# error "Unsupported WASI version" +#error "Unsupported WASI version" #endif } diff --git a/libc-bottom-half/crt/crt1-reactor.c b/libc-bottom-half/crt/crt1-reactor.c index 3e9a27b98..bd693245e 100644 --- a/libc-bottom-half/crt/crt1-reactor.c +++ b/libc-bottom-half/crt/crt1-reactor.c @@ -4,23 +4,22 @@ extern void __wasi_init_tp(void); extern void __wasm_call_ctors(void); -__attribute__((export_name("_initialize"))) -void _initialize(void) { +__attribute__((export_name("_initialize"))) void _initialize(void) { #if defined(_REENTRANT) - static volatile atomic_int initialized = 0; - int expected = 0; - if (!atomic_compare_exchange_strong(&initialized, &expected, 1)) { - __builtin_trap(); - } + static volatile atomic_int initialized = 0; + int expected = 0; + if (!atomic_compare_exchange_strong(&initialized, &expected, 1)) { + __builtin_trap(); + } #else - static volatile int initialized = 0; - if (initialized != 0) { - __builtin_trap(); - } - initialized = 1; + static volatile int initialized = 0; + if (initialized != 0) { + __builtin_trap(); + } + initialized = 1; #endif - __wasi_init_tp(); + __wasi_init_tp(); - // The linker synthesizes this to call constructors. - __wasm_call_ctors(); + // The linker synthesizes this to call constructors. + __wasm_call_ctors(); } diff --git a/libc-bottom-half/crt/crt1.c b/libc-bottom-half/crt/crt1.c deleted file mode 100644 index cbbe07379..000000000 --- a/libc-bottom-half/crt/crt1.c +++ /dev/null @@ -1,3 +0,0 @@ -// We compile a plain crt1.o for toolchain compatibility, but it's -// identical to crt1-command.o. -#include "crt1-command.c" From 58982366fc0e50324bbce32d3576f0cbea9da640 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 7 Jan 2026 15:37:36 -0800 Subject: [PATCH 04/41] Fix build --- cmake/ba-download.cmake | 2 +- libc-bottom-half/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/ba-download.cmake b/cmake/ba-download.cmake index c89a8449c..24ee922b5 100644 --- a/cmake/ba-download.cmake +++ b/cmake/ba-download.cmake @@ -33,7 +33,7 @@ function(ba_download target repo version) set(fmt tar.gz) endif() - if (target STREQUAL wit-bindgen) + if (target STREQUAL wit-bindgen OR target STREQUAL wasm-tools) set(tag v${version}) else() set(tag ${version}) diff --git a/libc-bottom-half/CMakeLists.txt b/libc-bottom-half/CMakeLists.txt index 299f9a453..a8fcb09d1 100644 --- a/libc-bottom-half/CMakeLists.txt +++ b/libc-bottom-half/CMakeLists.txt @@ -205,7 +205,7 @@ else() $ --world wasi:cli/command@0.2.0 -o ${SYSROOT_LIB}/crt1-command.o - DEPENDS crt1-command wasi-wits $ + DEPENDS crt1-command wasi-wits $ wasm-tools ) endif() From 13502fb3ced9f7564d36f61c075f367852c299ce Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 7 Jan 2026 15:49:12 -0800 Subject: [PATCH 05/41] Fix windows build --- cmake/ba-download.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/ba-download.cmake b/cmake/ba-download.cmake index 24ee922b5..c3e2dc46f 100644 --- a/cmake/ba-download.cmake +++ b/cmake/ba-download.cmake @@ -27,7 +27,8 @@ function(ba_download target repo version) if (target STREQUAL wasmtime) set(fmt tar.xz) - elseif ((target STREQUAL wasm-component-ld) AND (os STREQUAL windows)) + elseif ((os STREQUAL windows) AND + ((target STREQUAL wasm-component-ld) OR (target STREQUAL wasm-tools))) set(fmt zip) else() set(fmt tar.gz) From eaabc985bea0754207e95040c40b61c5ade45782 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 8 Jan 2026 11:32:47 +0000 Subject: [PATCH 06/41] Initial work --- CMakeLists.txt | 6 +- cmake/bindings.cmake | 20 +- libc-bottom-half/CMakeLists.txt | 31 ++- .../cloudlibc/src/libc/sched/sched_yield.c | 16 +- .../cloudlibc/src/libc/stdlib/_Exit.c | 7 +- libc-bottom-half/crt/crt1-command.c | 41 +-- libc-bottom-half/crt/crt1-reactor.c | 17 +- .../crt/wasm32/wasip3-crt1-command.s | 31 +++ .../crt/wasm32/wasip3-crt1-reactor.s | 32 +++ .../headers/public/wasi/__generated_wasip2.h | 7 +- .../headers/public/wasi/__generated_wasip3.h | 24 +- libc-bottom-half/sources/__main_void.c | 35 ++- libc-bottom-half/sources/abort.c | 3 +- libc-bottom-half/sources/wasip2.c | 8 +- .../sources/wasip2_component_type.o | Bin 10846 -> 10846 bytes libc-bottom-half/sources/wasip3.c | 90 +++++-- .../sources/wasip3_component_type.o | Bin 8092 -> 8092 bytes libc-top-half/CMakeLists.txt | 10 +- libc-top-half/musl/src/env/__init_tls.c | 127 +++++---- .../musl/src/thread/pthread_create.c | 247 ++++++++++++------ .../src/thread/wasm32/wasip3_thread_start.s | 54 ++++ test/src/coop_thread.c | 44 ++++ 22 files changed, 631 insertions(+), 219 deletions(-) create mode 100644 libc-bottom-half/crt/wasm32/wasip3-crt1-command.s create mode 100644 libc-bottom-half/crt/wasm32/wasip3-crt1-reactor.s create mode 100644 libc-top-half/musl/src/thread/wasm32/wasip3_thread_start.s create mode 100644 test/src/coop_thread.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 1fe4d6e13..33f76d6d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,7 +67,8 @@ elseif(TARGET_TRIPLE MATCHES "-wasip2$") set(SHARED ON) elseif(TARGET_TRIPLE MATCHES "-wasip3$") set(WASI p3) - set(SHARED ON) + # TODO: wasip3_thread_start.s also uses non-position-independent code. + set(SHARED OFF) else() message(FATAL_ERROR "Unknown WASI target triple: ${TARGET_TRIPLE}") endif() @@ -86,6 +87,9 @@ endif() if(TARGET_TRIPLE MATCHES "-threads$") set(THREADS ON) add_compile_options(-mthread-model posix -pthread -ftls-model=local-exec -matomics) +elseif(TARGET_TRIPLE MATCHES "-wasip3$") + set(THREADS OFF) + add_compile_options(-mthread-model posix -pthread -ftls-model=local-exec -matomics) else() set(THREADS OFF) add_compile_options(-mthread-model single) diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index 1d4e6a1d5..bdfa87721 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -7,19 +7,7 @@ endif() # If `wit-bindgen` is on the system and has the right version, favor that, # otherwise download a known good version. find_program(WIT_BINDGEN_EXECUTABLE NAMES wit-bindgen) -if(WIT_BINDGEN_EXECUTABLE) - message(STATUS "Found wit-bindgen: ${WIT_BINDGEN_EXECUTABLE}") - - execute_process( - COMMAND ${WIT_BINDGEN_EXECUTABLE} --version - OUTPUT_VARIABLE WIT_BINDGEN_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE) - - if (NOT (WIT_BINDGEN_VERSION MATCHES "0\\.48\\.0")) - message(WARNING "wit-bindgen version 0.48.0 is required, found: ${WIT_BINDGEN_VERSION}") - set(WIT_BINDGEN_EXECUTABLE "") - endif() -endif() +set(WIT_BINDGEN_EXECUTABLE "/Users/sybrand/src/bytecodealliance/wit-bindgen/target/debug/wit-bindgen") if (NOT WIT_BINDGEN_EXECUTABLE) include(ba-download) @@ -142,9 +130,9 @@ add_custom_target(bindings DEPENDS bindings-p2 bindings-p3) function(wit_bindgen_edit p) add_custom_target( bindings-${p}-edit - COMMAND sed -i "'s_#include .wasi${p}\.h._#include \"wasi/wasi${p}.h\"_'" ${bottom_half}/sources/wasi${p}.c - COMMAND sed -i "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/__generated_wasi${p}.h - COMMAND sed -i "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasi${p}.c + COMMAND sed -i '' "'s_#include .wasi${p}\.h._#include \"wasi/wasi${p}.h\"_'" "${bottom_half}/sources/wasi${p}.c" + COMMAND sed -i '' "s/extern void exit_exit/_Noreturn extern void exit_exit/" "${bottom_half}/headers/public/wasi/__generated_wasi${p}.h" + COMMAND sed -i '' "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" "${bottom_half}/sources/wasi${p}.c" DEPENDS bindings-${p} ) add_dependencies(bindings bindings-${p}-edit) diff --git a/libc-bottom-half/CMakeLists.txt b/libc-bottom-half/CMakeLists.txt index 84c1d5b5a..1045a61b2 100644 --- a/libc-bottom-half/CMakeLists.txt +++ b/libc-bottom-half/CMakeLists.txt @@ -192,13 +192,32 @@ foreach(file crt/crt1.c set_pic(${filename}.o) target_compile_options(${filename}.o PRIVATE -fvisibility=default) - # add a custom command to compile the file set(dst ${SYSROOT_LIB}/${filename}.o) - add_custom_command( - OUTPUT ${dst} - COMMAND ${CMAKE_COMMAND} -E copy $ ${dst} - DEPENDS ${filename}.o - ) + + # for wasip3, also build the the ASM trampolines + if(WASI STREQUAL "p3") + if(filename STREQUAL "crt1-reactor") + set(asm_stub crt/wasm32/wasip3-crt1-reactor.s) + elseif(filename STREQUAL "crt1" OR filename STREQUAL "crt1-command") + set(asm_stub crt/wasm32/wasip3-crt1-command.s) + endif() + add_library(${filename}_trampoline.o OBJECT ${asm_stub}) + + # perform a relocatable link to create the final startup object + add_custom_command( + OUTPUT ${dst} + COMMAND ${CMAKE_C_COMPILER} -r $ $ -o ${dst} -nostdlib + DEPENDS ${filename}.o ${filename}_trampoline.o + ) + else() + # add a custom command to compile the file + add_custom_command( + OUTPUT ${dst} + COMMAND ${CMAKE_COMMAND} -E copy $ ${dst} + DEPENDS ${filename}.o + ) + endif() + add_custom_target(sysroot-startup-${filename}.o DEPENDS ${dst}) add_dependencies(sysroot-startup-objects sysroot-startup-${filename}.o) endforeach() diff --git a/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c b/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c index fc13322b6..f6a78a850 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c +++ b/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c @@ -5,15 +5,21 @@ #include #include #include +#include -int sched_yield(void) { -#ifdef __wasip1__ +int sched_yield(void) +{ +#if defined(__wasip1__) __wasi_errno_t error = __wasi_sched_yield(); - if (error != 0) { + if (error != 0) + { errno = error; return -1; } -#endif +#elif defined(__wasip3__) + wasip3_thread_yield(); + return 0; +#else return 0; +#endif } - diff --git a/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c b/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c index ace4bcd9c..9116a54de 100644 --- a/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c +++ b/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c @@ -7,14 +7,15 @@ #include #include -noreturn void _Exit(int status) { +noreturn void _Exit(int status) +{ #if defined(__wasip1__) __wasi_proc_exit(status); #elif defined(__wasip2__) || defined(__wasip3__) - exit_result_void_void_t exit_status = { .is_err = status != 0 }; + exit_result_void_void_t exit_status = {.is_err = status != 0}; exit_exit(&exit_status); #else -# error "Unknown WASI version" +#error "Unknown WASI version" #endif } diff --git a/libc-bottom-half/crt/crt1-command.c b/libc-bottom-half/crt/crt1-command.c index 69f340f4b..28e96bba2 100644 --- a/libc-bottom-half/crt/crt1-command.c +++ b/libc-bottom-half/crt/crt1-command.c @@ -9,24 +9,33 @@ extern void __wasm_call_ctors(void); extern int __main_void(void); extern void __wasm_call_dtors(void); -__attribute__((export_name("_start"))) -void _start(void) { - // Commands should only be called once per instance. This simple check - // ensures that the `_start` function isn't started more than once. - // - // We use `volatile` here to prevent the store to `started` from being - // sunk past any subsequent code, and to prevent any compiler from - // optimizing based on the knowledge that `_start` is the program - // entrypoint. +// On WASIP3, the _start function is implemented in crt/wasm32/wasip3-crt1-command-start.s +// so that it can initialize the stack pointer and TLS before calling the real +// _start function (renamed to _libc_start here). +#ifdef __wasip3__ +void _libc_start(void) +#else +__attribute__((export_name("_start"))) void _start(void) +#endif +{ +// Commands should only be called once per instance. This simple check +// ensures that the `_start` function isn't started more than once. +// +// We use `volatile` here to prevent the store to `started` from being +// sunk past any subsequent code, and to prevent any compiler from +// optimizing based on the knowledge that `_start` is the program +// entrypoint. #ifdef _REENTRANT static volatile _Atomic int started = 0; int expected = 0; - if (!atomic_compare_exchange_strong(&started, &expected, 1)) { + if (!atomic_compare_exchange_strong(&started, &expected, 1)) + { __builtin_trap(); } #else static volatile int started = 0; - if (started != 0) { + if (started != 0) + { __builtin_trap(); } started = 1; @@ -48,15 +57,17 @@ void _start(void) { // If main exited successfully, just return, otherwise call // `__wasi_proc_exit`. #if defined(__wasip1__) - if (r != 0) { + if (r != 0) + { __wasi_proc_exit(r); } #elif defined(__wasip2__) || defined(__wasip3__) - if (r != 0) { - exit_result_void_void_t status = { .is_err = true }; + if (r != 0) + { + exit_result_void_void_t status = {.is_err = true}; exit_exit(&status); } #else -# error "Unsupported WASI version" +#error "Unsupported WASI version" #endif } diff --git a/libc-bottom-half/crt/crt1-reactor.c b/libc-bottom-half/crt/crt1-reactor.c index 3e9a27b98..778363d63 100644 --- a/libc-bottom-half/crt/crt1-reactor.c +++ b/libc-bottom-half/crt/crt1-reactor.c @@ -4,17 +4,26 @@ extern void __wasi_init_tp(void); extern void __wasm_call_ctors(void); -__attribute__((export_name("_initialize"))) -void _initialize(void) { +// On WASIP3, the _initialize function is implemented in crt/wasm32/wasip3-crt1-reactor-start.s +// so that it can initialize the stack pointer and TLS before calling the real +// _initialize function (renamed to _libc_initialize here). +#ifdef __wasip3__ +void _libc_initialize(void) +#else +__attribute__((export_name("_initialize"))) void _initialize(void) +#endif +{ #if defined(_REENTRANT) static volatile atomic_int initialized = 0; int expected = 0; - if (!atomic_compare_exchange_strong(&initialized, &expected, 1)) { + if (!atomic_compare_exchange_strong(&initialized, &expected, 1)) + { __builtin_trap(); } #else static volatile int initialized = 0; - if (initialized != 0) { + if (initialized != 0) + { __builtin_trap(); } initialized = 1; diff --git a/libc-bottom-half/crt/wasm32/wasip3-crt1-command.s b/libc-bottom-half/crt/wasm32/wasip3-crt1-command.s new file mode 100644 index 000000000..b7edbbb05 --- /dev/null +++ b/libc-bottom-half/crt/wasm32/wasip3-crt1-command.s @@ -0,0 +1,31 @@ + .text + + .export_name _start, _start + + .globaltype __init_stack_pointer, i32 + .globaltype __init_tls_base, i32 + + .functype _libc_start () -> () + + .functype __wasm_component_model_builtin_context_set_0 (i32) -> () + .import_module __wasm_component_model_builtin_context_set_0, "$root" + .import_name __wasm_component_model_builtin_context_set_0, "[context-set-0]" + .functype __wasm_component_model_builtin_context_set_1 (i32) -> () + .import_module __wasm_component_model_builtin_context_set_1, "$root" + .import_name __wasm_component_model_builtin_context_set_1, "[context-set-1]" + + .globl _start + .type _start,@function + +_start: + .functype _start () -> () + + global.get __init_stack_pointer + call __wasm_component_model_builtin_context_set_0 + + global.get __init_tls_base + call __wasm_component_model_builtin_context_set_1 + + call _libc_start + + end_function diff --git a/libc-bottom-half/crt/wasm32/wasip3-crt1-reactor.s b/libc-bottom-half/crt/wasm32/wasip3-crt1-reactor.s new file mode 100644 index 000000000..a1f4d6bcd --- /dev/null +++ b/libc-bottom-half/crt/wasm32/wasip3-crt1-reactor.s @@ -0,0 +1,32 @@ + .text + + .export_name _initialize, _initialize + + .globaltype __init_stack_pointer, i32 + .globaltype __init_tls_base, i32 + + .functype _libc_initialize () -> () + + .functype __wasm_component_model_builtin_context_set_0 (i32) -> () + .import_module __wasm_component_model_builtin_context_set_0, "$root" + .import_name __wasm_component_model_builtin_context_set_0, "[context-set-0]" + .functype __wasm_component_model_builtin_context_set_1 (i32) -> () + .import_module __wasm_component_model_builtin_context_set_1, "$root" + .import_name __wasm_component_model_builtin_context_set_1, "[context-set-1]" + + .globl _initialize + .type _initialize,@function + +_initialize: + .functype _initialize () -> () + + global.get __init_stack_pointer + call __wasm_component_model_builtin_context_set_0 + + global.get __init_tls_base + call __wasm_component_model_builtin_context_set_1 + + call _libc_initialize + + end_function + diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip2.h b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h index 54ffac264..eb8f16ba3 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip2.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.48.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.50.0. DO NOT EDIT! #ifndef __BINDINGS_WASIP2_H #define __BINDINGS_WASIP2_H #ifdef __cplusplus @@ -2447,6 +2447,11 @@ void wasip2_string_set(wasip2_string_t *ret, const char*s); // stores it into the component model string `ret`. void wasip2_string_dup(wasip2_string_t *ret, const char*s); +// Creates a copy of the input string `s` with length `len` and +// stores it into the component model string `ret`. +// The length is specified in code units (bytes for UTF-8, 16-bit values for UTF-16). +void wasip2_string_dup_n(wasip2_string_t *ret, const char*s, size_t len); + // Deallocates the string pointed to by `ret`, deallocating // the memory behind the string. void wasip2_string_free(wasip2_string_t *ret); diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h index 8618192ab..cdad5b84c 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.48.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.50.0. DO NOT EDIT! #ifndef __BINDINGS_WASIP3_H #define __BINDINGS_WASIP3_H #ifdef __cplusplus @@ -36,7 +36,6 @@ typedef uint32_t wasip3_callback_code_t; #define WASIP3_CALLBACK_CODE_EXIT 0 #define WASIP3_CALLBACK_CODE_YIELD 1 #define WASIP3_CALLBACK_CODE_WAIT(set) (2 | (set << 4)) -#define WASIP3_CALLBACK_CODE_POLL(set) (3 | (set << 4)) typedef enum wasip3_event_code { WASIP3_EVENT_NONE, @@ -74,13 +73,19 @@ typedef enum wasip3_waitable_state { WASIP3_WAITABLE_CANCELLED, } wasip3_waitable_state_t; -void wasip3_backpressure_set(bool enable); void wasip3_backpressure_inc(void); void wasip3_backpressure_dec(void); -void* wasip3_context_get(void); -void wasip3_context_set(void*); -void wasip3_yield(void); -uint32_t wasip3_yield_cancellable(void); +void* wasip3_context_get(size_t index); +void wasip3_context_set(size_t index, void* value); +void wasip3_thread_yield(void); +uint32_t wasip3_thread_yield_cancellable(void); +uint32_t wasip3_thread_index(void); +uint32_t wasip3_thread_new_indirect(void (*start_function)(void*), void* arg); +void wasip3_thread_switch_to(uint32_t thread); +uint32_t wasip3_thread_switch_to_cancellable(uint32_t thread); +void wasip3_thread_resume_later(uint32_t thread); +void wasip3_thread_yield_to(uint32_t thread); +uint32_t wasip3_thread_yield_to_cancellable(uint32_t thread); @@ -2021,6 +2026,11 @@ void wasip3_string_set(wasip3_string_t *ret, const char*s); // stores it into the component model string `ret`. void wasip3_string_dup(wasip3_string_t *ret, const char*s); +// Creates a copy of the input string `s` with length `len` and +// stores it into the component model string `ret`. +// The length is specified in code units (bytes for UTF-8, 16-bit values for UTF-16). +void wasip3_string_dup_n(wasip3_string_t *ret, const char*s, size_t len); + // Deallocates the string pointed to by `ret`, deallocating // the memory behind the string. void wasip3_string_free(wasip3_string_t *ret); diff --git a/libc-bottom-half/sources/__main_void.c b/libc-bottom-half/sources/__main_void.c index 880d06233..bb7aa76d2 100644 --- a/libc-bottom-half/sources/__main_void.c +++ b/libc-bottom-half/sources/__main_void.c @@ -23,7 +23,8 @@ __attribute__((__weak__)) int __main_argc_argv(int argc, char *argv[]); // as necessary by the Clang driver. However, moving it to crt1-command.c // breaks `--no-gc-sections`, so we'll probably need to create a new file // (e.g. crt0.o or crtend.o) and teach Clang to use it when needed. -__attribute__((__weak__, nodebug)) int __main_void(void) { +__attribute__((__weak__, nodebug)) int __main_void(void) +{ #if defined(__wasip1__) __wasi_errno_t err; @@ -31,26 +32,30 @@ __attribute__((__weak__, nodebug)) int __main_void(void) { size_t argv_buf_size; size_t argc; err = __wasi_args_sizes_get(&argc, &argv_buf_size); - if (err != __WASI_ERRNO_SUCCESS) { + if (err != __WASI_ERRNO_SUCCESS) + { _Exit(EX_OSERR); } // Add 1 for the NULL pointer to mark the end, and check for overflow. size_t num_ptrs = argc + 1; - if (num_ptrs == 0) { + if (num_ptrs == 0) + { _Exit(EX_SOFTWARE); } // Allocate memory for storing the argument chars. char *argv_buf = malloc(argv_buf_size); - if (argv_buf == NULL) { + if (argv_buf == NULL) + { _Exit(EX_SOFTWARE); } // Allocate memory for the array of pointers. This uses `calloc` both to // handle overflow and to initialize the NULL pointer at the end. char **argv = calloc(num_ptrs, sizeof(char *)); - if (argv == NULL) { + if (argv == NULL) + { free(argv_buf); _Exit(EX_SOFTWARE); } @@ -59,7 +64,8 @@ __attribute__((__weak__, nodebug)) int __main_void(void) { // TODO: Remove the casts on `argv_ptrs` and `argv_buf` once the witx is // updated with char8 support. err = __wasi_args_get((uint8_t **)argv, (uint8_t *)argv_buf); - if (err != __WASI_ERRNO_SUCCESS) { + if (err != __WASI_ERRNO_SUCCESS) + { free(argv_buf); free(argv); _Exit(EX_OSERR); @@ -85,7 +91,8 @@ __attribute__((__weak__, nodebug)) int __main_void(void) { // Add 1 for the NULL pointer to mark the end, and check for overflow. size_t argc = argument_list.len; size_t num_ptrs = argc + 1; - if (num_ptrs == 0) { + if (num_ptrs == 0) + { list_string_free(&argument_list); _Exit(EX_SOFTWARE); } @@ -93,17 +100,20 @@ __attribute__((__weak__, nodebug)) int __main_void(void) { // Allocate memory for the array of pointers. This uses `calloc` both to // handle overflow and to initialize the NULL pointer at the end. char **argv = calloc(num_ptrs, sizeof(char *)); - if (argv == NULL) { + if (argv == NULL) + { list_string_free(&argument_list); _Exit(EX_SOFTWARE); } // Copy the arguments - for (size_t i = 0; i < argc; i++) { + for (size_t i = 0; i < argc; i++) + { string_t wasi_string = argument_list.ptr[i]; size_t len = wasi_string.len; argv[i] = malloc(len + 1); - if (!argv[i]) { + if (!argv[i]) + { list_string_free(&argument_list); _Exit(EX_SOFTWARE); } @@ -121,8 +131,9 @@ __attribute__((__weak__, nodebug)) int __main_void(void) { #endif } -#ifdef __wasip2__ -bool exports_wasi_cli_run_run(void) { +#if defined(__wasip2__) || defined(__wasip3__) +bool exports_wasi_cli_run_run(void) +{ // TODO: this is supposed to be unnecessary, but functional/env.c fails // without it __wasilibc_initialize_environ(); diff --git a/libc-bottom-half/sources/abort.c b/libc-bottom-half/sources/abort.c index 9db9e1bbd..4e58f5af7 100644 --- a/libc-bottom-half/sources/abort.c +++ b/libc-bottom-half/sources/abort.c @@ -1,6 +1,7 @@ #include -void abort(void) { +void abort(void) +{ // wasm doesn't support signals, so just trap to halt the program. __builtin_trap(); } diff --git a/libc-bottom-half/sources/wasip2.c b/libc-bottom-half/sources/wasip2.c index ef7c5d627..7305c9c1c 100644 --- a/libc-bottom-half/sources/wasip2.c +++ b/libc-bottom-half/sources/wasip2.c @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.48.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.50.0. DO NOT EDIT! #include "wasi/wasip2.h" #include #include @@ -1032,6 +1032,12 @@ void wasip2_string_dup(wasip2_string_t *ret, const char*s) { memcpy(ret->ptr, s, ret->len * 1); } +void wasip2_string_dup_n(wasip2_string_t *ret, const char*s, size_t len) { + ret->len = len; + ret->ptr = (uint8_t*) cabi_realloc(NULL, 0, 1, ret->len * 1); + memcpy(ret->ptr, s, ret->len * 1); +} + void wasip2_string_free(wasip2_string_t *ret) { if (ret->len > 0) { free(ret->ptr); diff --git a/libc-bottom-half/sources/wasip2_component_type.o b/libc-bottom-half/sources/wasip2_component_type.o index 92cccf9b4a38544eccbccfeaabe600a201aa39a4..c0070fcf99549d4ba9185572701e5764a007ac02 100644 GIT binary patch delta 34 pcmcZ?axY{9x0aZ(o&j%pW{GZ6W?o8qYMyQ~n}MFG!DK}(TL98?3d#Tg delta 34 pcmcZ?axY{9x0aZpo)K?(W{GZ6W?o8qYMyQ~n}ME*#biY-TL99L3ef-n diff --git a/libc-bottom-half/sources/wasip3.c b/libc-bottom-half/sources/wasip3.c index b58e84ded..50a7d6d7a 100644 --- a/libc-bottom-half/sources/wasip3.c +++ b/libc-bottom-half/sources/wasip3.c @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.48.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.50.0. DO NOT EDIT! #include "wasi/wasip3.h" #include #include @@ -1034,6 +1034,12 @@ void wasip3_string_dup(wasip3_string_t *ret, const char*s) { memcpy(ret->ptr, s, ret->len * 1); } +void wasip3_string_dup_n(wasip3_string_t *ret, const char*s, size_t len) { + ret->len = len; + ret->ptr = (uint8_t*) cabi_realloc(NULL, 0, 1, ret->len * 1); + memcpy(ret->ptr, s, ret->len * 1); +} + void wasip3_string_free(wasip3_string_t *ret) { if (ret->len > 0) { free(ret->ptr); @@ -1099,13 +1105,6 @@ void wasip3_task_cancel() { __task_cancel(); } -__attribute__((__import_module__("$root"), __import_name__("[backpressure-set]"))) -extern void __backpressure_set(bool enable); - -void wasip3_backpressure_set(bool enable) { - __backpressure_set(enable); -} - __attribute__((__import_module__("$root"), __import_name__("[backpressure-inc]"))) extern void __backpressure_inc(void); @@ -1121,33 +1120,92 @@ void wasip3_backpressure_dec(void) { } __attribute__((__import_module__("$root"), __import_name__("[context-get-0]"))) -extern void* __context_get(void); +extern void* __context_get_0(void); + +__attribute__((__import_module__("$root"), __import_name__("[context-get-1]"))) +extern void* __context_get_1(void); -void* wasip3_context_get() { - return __context_get(); +void* wasip3_context_get(size_t index) { + if (index == 0) return __context_get_0(); + if (index == 1) return __context_get_1(); + return NULL; } __attribute__((__import_module__("$root"), __import_name__("[context-set-0]"))) -extern void __context_set(void*); +extern void __context_set_0(void*); -void wasip3_context_set(void *val) { - return __context_set(val); +__attribute__((__import_module__("$root"), __import_name__("[context-set-1]"))) +extern void __context_set_1(void*); + +void wasip3_context_set(size_t index, void *value) { + if (index == 0) __context_set_0(value); + else if (index == 1) __context_set_1(value); } __attribute__((__import_module__("$root"), __import_name__("[thread-yield]"))) extern uint32_t __thread_yield(void); -void wasip3_yield(void) { +void wasip3_thread_yield(void) { __thread_yield(); } __attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-yield]"))) extern uint32_t __thread_yield_cancellable(void); -uint32_t wasip3_yield_cancellable(void) { +uint32_t wasip3_thread_yield_cancellable(void) { return __thread_yield_cancellable(); } +__attribute__((__import_module__("$root"), __import_name__("[thread-index]"))) +extern uint32_t __thread_index(void); + +uint32_t wasip3_thread_index(void) { + return __thread_index(); +} + +__attribute__((__import_module__("$root"), __import_name__("[thread-new-indirect-v0]"))) +extern uint32_t __thread_new_indirect(uint32_t, void*); + +uint32_t wasip3_thread_new_indirect(void (*start_function)(void*), void* arg) { + return __thread_new_indirect((uint32_t)(uintptr_t)start_function, arg + ); +} + +__attribute__((__import_module__("$root"), __import_name__("[thread-switch-to]"))) +extern void __thread_switch_to(uint32_t); + +void wasip3_thread_switch_to(uint32_t thread) { + __thread_switch_to(thread); +} + +__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-switch-to]"))) +extern uint32_t __thread_switch_to_cancellable(uint32_t); + +uint32_t wasip3_thread_switch_to_cancellable(uint32_t thread) { + return __thread_switch_to_cancellable(thread); +} + +__attribute__((__import_module__("$root"), __import_name__("[thread-resume-later]"))) +extern void __thread_resume_later(uint32_t); + +void wasip3_thread_resume_later(uint32_t thread) { + __thread_resume_later(thread); +} + +__attribute__((__import_module__("$root"), __import_name__("[thread-yield-to]"))) +extern uint32_t __thread_yield_to(uint32_t); + +void wasip3_thread_yield_to(uint32_t thread) { + __thread_yield_to(thread); +} + +__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-yield-to]"))) +extern uint32_t __thread_yield_to_cancellable(uint32_t); + +uint32_t wasip3_thread_yield_to_cancellable(uint32_t thread) { + return __thread_yield_to_cancellable(thread); +} + // Component Adapters diff --git a/libc-bottom-half/sources/wasip3_component_type.o b/libc-bottom-half/sources/wasip3_component_type.o index 2134f29a58f9add8550532cd099d3c263b8317a3..d30145e7b9e236c6703af6fc362b569e8a842148 100644 GIT binary patch delta 34 pcmbPZKgWK9r@WZ4o&j%pW{GZ6W?o8qYMyQ~n}MFG!Q^;(TL8kP3W5Lt delta 34 pcmbPZKgWK9r@WY #endif +#include #include #include #include "pthread_impl.h" @@ -35,33 +36,56 @@ extern unsigned char __global_base; extern weak unsigned char __stack_high; extern weak unsigned char __stack_low; -struct stack_bounds { +struct stack_bounds +{ void *base; size_t size; }; +static inline unsigned char *get_stack_pointer() +{ + unsigned char *sp; +#ifdef __wasip3__ + __asm__( + ".functype __wasm_component_model_builtin_context_get_0 () -> (i32)\n" + ".import_module __wasm_component_model_builtin_context_get_0, \"$root\"\n" + ".import_name __wasm_component_model_builtin_context_get_0, \"[context-get-0]\"\n" + "call __wasm_component_model_builtin_context_get_0\n" + "local.set %0\n" + : "=r"(sp)); +#else + __asm__( + ".globaltype __stack_pointer, i32\n" + "global.get __stack_pointer\n" + "local.set %0\n" + : "=r"(sp)); +#endif + return sp; +} + static inline struct stack_bounds get_stack_bounds() { struct stack_bounds bounds; - if (&__stack_high) { + if (&__stack_high) + { bounds.base = &__stack_high; bounds.size = &__stack_high - &__stack_low; - } else { + } + else + { /* For non-pic, make a guess using the knowledge about * how wasm-ld lays out things. For pic, just give up. */ #if !defined(__pic__) - unsigned char *sp; - __asm__( - ".globaltype __stack_pointer, i32\n" - "global.get __stack_pointer\n" - "local.set %0\n" - : "=r"(sp)); - if (sp > &__global_base) { + unsigned char *sp = get_stack_pointer(); + if (sp > &__global_base) + { bounds.base = &__heap_base; bounds.size = &__heap_base - &__data_end; - } else { + } + else + { bounds.base = &__global_base; bounds.size = (size_t)&__global_base; } @@ -74,7 +98,8 @@ static inline struct stack_bounds get_stack_bounds() return bounds; } -void __wasi_init_tp() { +void __wasi_init_tp() +{ __init_tp((void *)__get_tp()); } #endif @@ -85,15 +110,16 @@ int __init_tp(void *p) td->self = td; #ifdef __wasilibc_unmodified_upstream int r = __set_thread_area(TP_ADJ(p)); - if (r < 0) return -1; - if (!r) libc.can_do_threads = 1; + if (r < 0) + return -1; + if (!r) + libc.can_do_threads = 1; td->detach_state = DT_JOINABLE; td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock); #else struct stack_bounds bounds = get_stack_bounds(); __default_stacksize = - bounds.size < DEFAULT_STACK_MAX ? - bounds.size : DEFAULT_STACK_MAX; + bounds.size < DEFAULT_STACK_MAX ? bounds.size : DEFAULT_STACK_MAX; td->stack = bounds.base; td->stack_size = bounds.size; td->guard_size = 0; @@ -123,7 +149,8 @@ int __init_tp(void *p) #ifdef __wasilibc_unmodified_upstream -static struct builtin_tls { +static struct builtin_tls +{ char c; struct pthread pt; void *space[16]; @@ -134,7 +161,7 @@ static struct tls_module main_tls; #endif #ifndef __wasilibc_unmodified_upstream -extern void __wasm_init_tls(void*); +extern void __wasm_init_tls(void *); #endif #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) @@ -147,13 +174,14 @@ void *__copy_tls(unsigned char *mem) uintptr_t *dtv; #ifdef TLS_ABOVE_TP - dtv = (uintptr_t*)(mem + libc.tls_size) - (libc.tls_cnt + 1); + dtv = (uintptr_t *)(mem + libc.tls_size) - (libc.tls_cnt + 1); - mem += -((uintptr_t)mem + sizeof(struct pthread)) & (libc.tls_align-1); + mem += -((uintptr_t)mem + sizeof(struct pthread)) & (libc.tls_align - 1); td = (pthread_t)mem; mem += sizeof(struct pthread); - for (i=1, p=libc.tls_head; p; i++, p=p->next) { + for (i = 1, p = libc.tls_head; p; i++, p = p->next) + { dtv[i] = (uintptr_t)(mem + p->offset) + DTP_OFFSET; memcpy(mem + p->offset, p->image, p->len); } @@ -161,10 +189,11 @@ void *__copy_tls(unsigned char *mem) dtv = (uintptr_t *)mem; mem += libc.tls_size - sizeof(struct pthread); - mem -= (uintptr_t)mem & (libc.tls_align-1); + mem -= (uintptr_t)mem & (libc.tls_align - 1); td = (pthread_t)mem; - for (i=1, p=libc.tls_head; p; i++, p=p->next) { + for (i = 1, p = libc.tls_head; p; i++, p = p->next) + { dtv[i] = (uintptr_t)(mem - p->offset) + DTP_OFFSET; memcpy(mem - p->offset, p->image, p->len); } @@ -174,13 +203,14 @@ void *__copy_tls(unsigned char *mem) return td; #else size_t tls_align = __builtin_wasm_tls_align(); - volatile void* tls_base = __builtin_wasm_tls_base(); mem += tls_align; - mem -= (uintptr_t)mem & (tls_align-1); + mem -= (uintptr_t)mem & (tls_align - 1); __wasm_init_tls(mem); - __asm__("local.get %0\n" - "global.set __tls_base\n" - :: "r"(tls_base)); +#ifndef __wasip3__ + volatile void *tls_base = __builtin_wasm_tls_base(); + __asm__("local.get %0\n" + "global.set __tls_base\n" ::"r"(tls_base)); +#endif return mem; #endif } @@ -199,11 +229,12 @@ static void static_init_tls(size_t *aux) { unsigned char *p; size_t n; - Phdr *phdr, *tls_phdr=0; + Phdr *phdr, *tls_phdr = 0; size_t base = 0; void *mem; - for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) { + for (p = (void *)aux[AT_PHDR], n = aux[AT_PHNUM]; n; n--, p += aux[AT_PHENT]) + { phdr = (void *)p; if (phdr->p_type == PT_PHDR) base = aux[AT_PHDR] - phdr->p_vaddr; @@ -212,13 +243,13 @@ static void static_init_tls(size_t *aux) if (phdr->p_type == PT_TLS) tls_phdr = phdr; if (phdr->p_type == PT_GNU_STACK && - phdr->p_memsz > __default_stacksize) + phdr->p_memsz > __default_stacksize) __default_stacksize = - phdr->p_memsz < DEFAULT_STACK_MAX ? - phdr->p_memsz : DEFAULT_STACK_MAX; + phdr->p_memsz < DEFAULT_STACK_MAX ? phdr->p_memsz : DEFAULT_STACK_MAX; } - if (tls_phdr) { + if (tls_phdr) + { main_tls.image = (void *)(base + tls_phdr->p_vaddr); main_tls.len = tls_phdr->p_filesz; main_tls.size = tls_phdr->p_memsz; @@ -227,37 +258,39 @@ static void static_init_tls(size_t *aux) libc.tls_head = &main_tls; } - main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image) - & (main_tls.align-1); + main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image) & (main_tls.align - 1); #ifdef TLS_ABOVE_TP main_tls.offset = GAP_ABOVE_TP; - main_tls.offset += (-GAP_ABOVE_TP + (uintptr_t)main_tls.image) - & (main_tls.align-1); + main_tls.offset += (-GAP_ABOVE_TP + (uintptr_t)main_tls.image) & (main_tls.align - 1); #else main_tls.offset = main_tls.size; #endif - if (main_tls.align < MIN_TLS_ALIGN) main_tls.align = MIN_TLS_ALIGN; + if (main_tls.align < MIN_TLS_ALIGN) + main_tls.align = MIN_TLS_ALIGN; libc.tls_align = main_tls.align; - libc.tls_size = 2*sizeof(void *) + sizeof(struct pthread) + libc.tls_size = 2 * sizeof(void *) + sizeof(struct pthread) #ifdef TLS_ABOVE_TP - + main_tls.offset + + main_tls.offset #endif - + main_tls.size + main_tls.align - + MIN_TLS_ALIGN-1 & -MIN_TLS_ALIGN; + + main_tls.size + main_tls.align + MIN_TLS_ALIGN - 1 & + -MIN_TLS_ALIGN; - if (libc.tls_size > sizeof builtin_tls) { + if (libc.tls_size > sizeof builtin_tls) + { #ifndef SYS_mmap2 #define SYS_mmap2 SYS_mmap #endif mem = (void *)__syscall( SYS_mmap2, - 0, libc.tls_size, PROT_READ|PROT_WRITE, - MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); + 0, libc.tls_size, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); /* -4095...-1 cast to void * will crash on dereference anyway, * so don't bloat the init code checking for error codes and * explicitly calling a_crash(). */ - } else { + } + else + { mem = builtin_tls; } diff --git a/libc-top-half/musl/src/thread/pthread_create.c b/libc-top-half/musl/src/thread/pthread_create.c index 879b48c1f..f9bbc512e 100644 --- a/libc-top-half/musl/src/thread/pthread_create.c +++ b/libc-top-half/musl/src/thread/pthread_create.c @@ -35,7 +35,8 @@ void __tl_lock(void) { int tid = __pthread_self()->tid; int val = __thread_list_lock; - if (val == tid) { + if (val == tid) + { tl_lock_count++; return; } @@ -45,21 +46,25 @@ void __tl_lock(void) void __tl_unlock(void) { - if (tl_lock_count) { + if (tl_lock_count) + { tl_lock_count--; return; } a_store(&__thread_list_lock, 0); - if (tl_lock_waiters) __wake(&__thread_list_lock, 1, 0); + if (tl_lock_waiters) + __wake(&__thread_list_lock, 1, 0); } void __tl_sync(pthread_t td) { a_barrier(); int val = __thread_list_lock; - if (!val) return; + if (!val) + return; __wait(&__thread_list_lock, &tl_lock_waiters, val, 0); - if (tl_lock_waiters) __wake(&__thread_list_lock, 1, 0); + if (tl_lock_waiters) + __wake(&__thread_list_lock, 1, 0); } #ifndef __wasilibc_unmodified_upstream @@ -86,7 +91,8 @@ static void __pthread_exit(void *result) self->cancelasync = 0; self->result = result; - while (self->cancelbuf) { + while (self->cancelbuf) + { void (*f)(void *) = self->cancelbuf->__f; void *x = self->cancelbuf->__x; self->cancelbuf = self->cancelbuf->__next; @@ -103,7 +109,8 @@ static void __pthread_exit(void *result) * call; the loser is responsible for freeing thread resources. */ int state = a_cas(&self->detach_state, DT_JOINABLE, DT_EXITING); - if (state==DT_DETACHED && self->map_base) { + if (state == DT_DETACHED && self->map_base) + { /* Since __unmapself bypasses the normal munmap code path, * explicitly wait for vmlock holders first. This must be * done before any locks are taken, to avoid lock ordering @@ -127,7 +134,8 @@ static void __pthread_exit(void *result) /* If this is the only thread in the list, don't proceed with * termination of the thread, but restore the previous lock and * signal state to prepare for exit to call atexit handlers. */ - if (self->next == self) { + if (self->next == self) + { __tl_unlock(); UNLOCK(self->killlock); self->detach_state = state; @@ -156,9 +164,9 @@ static void __pthread_exit(void *result) __vm_lock(); #endif volatile void *volatile *rp; - while ((rp=self->robust_list.head) && rp != &self->robust_list.head) { - pthread_mutex_t *m = (void *)((char *)rp - - offsetof(pthread_mutex_t, _m_next)); + while ((rp = self->robust_list.head) && rp != &self->robust_list.head) + { + pthread_mutex_t *m = (void *)((char *)rp - offsetof(pthread_mutex_t, _m_next)); int waiters = m->_m_waiters; int priv = (m->_m_type & 128) ^ 128; self->robust_list.pending = rp; @@ -182,13 +190,15 @@ static void __pthread_exit(void *result) * has been called, via the exit futex address pointing at the lock. * This needs to happen after any possible calls to LOCK() that might * skip locking if process appears single-threaded. */ - if (!--libc.threads_minus_1) libc.need_locks = -1; + if (!--libc.threads_minus_1) + libc.need_locks = -1; self->next->prev = self->prev; self->prev->next = self->next; self->prev = self->next = self; #ifdef __wasilibc_unmodified_upstream - if (state==DT_DETACHED && self->map_base) { + if (state == DT_DETACHED && self->map_base) + { /* Detached threads must block even implementation-internal * signals, since they will not have a stack in their last * moments of existence. */ @@ -197,14 +207,15 @@ static void __pthread_exit(void *result) /* Robust list will no longer be valid, and was already * processed above, so unregister it with the kernel. */ if (self->robust_list.off) - __syscall(SYS_set_robust_list, 0, 3*sizeof(long)); + __syscall(SYS_set_robust_list, 0, 3 * sizeof(long)); /* The following call unmaps the thread's stack mapping * and then exits without touching the stack. */ __unmapself(self->map_base, self->map_size); } #else - if (state==DT_DETACHED && self->map_base) { + if (state == DT_DETACHED && self->map_base) + { /* As we use malloc/free which is considerably more complex * than mmap/munmap to call and can even require a valid * thread context, it's difficult to implement __unmapself. @@ -226,7 +237,8 @@ static void __pthread_exit(void *result) __wake(&self->detach_state, 1, 1); #ifdef __wasilibc_unmodified_upstream - for (;;) __syscall(SYS_exit, 0); + for (;;) + __syscall(SYS_exit, 0); #else // Can't use `exit()` here, because it is too high level @@ -235,7 +247,7 @@ static void __pthread_exit(void *result) * this thread terminates. * See also set_tid_address(2) * - * In WebAssembly, we leave it to wasi_thread_start instead. + * In WebAssembly, we leave it to wasi{p3}_thread_start instead. */ #endif } @@ -252,16 +264,17 @@ void __do_cleanup_pop(struct __ptcb *cb) __pthread_self()->cancelbuf = cb->__next; } -struct start_args { +struct start_args +{ #ifdef __wasilibc_unmodified_upstream void *(*start_func)(void *); void *start_arg; volatile int control; - unsigned long sig_mask[_NSIG/8/sizeof(long)]; + unsigned long sig_mask[_NSIG / 8 / sizeof(long)]; #else /* * Note: the offset of the "stack" and "tls_base" members - * in this structure is hardcoded in wasi_thread_start. + * in this structure is hardcoded in wasi{p3}_thread_start. */ void *stack; void *tls_base; @@ -275,18 +288,21 @@ static int start(void *p) { struct start_args *args = p; int state = args->control; - if (state) { - if (a_cas(&args->control, 1, 2)==1) + if (state) + { + if (a_cas(&args->control, 1, 2) == 1) __wait(&args->control, 0, 2, 1); - if (args->control) { + if (args->control) + { #ifdef __wasilibc_unmodified_upstream __syscall(SYS_set_tid_address, &args->control); - for (;;) __syscall(SYS_exit, 0); + for (;;) + __syscall(SYS_exit, 0); #endif } } #ifdef __wasilibc_unmodified_upstream - __syscall(SYS_rt_sigprocmask, SIG_SETMASK, &args->sig_mask, 0, _NSIG/8); + __syscall(SYS_rt_sigprocmask, SIG_SETMASK, &args->sig_mask, 0, _NSIG / 8); #endif __pthread_exit(args->start_func(args->start_arg)); return 0; @@ -295,12 +311,35 @@ static int start(void *p) static int start_c11(void *p) { struct start_args *args = p; - int (*start)(void*) = (int(*)(void*)) args->start_func; + int (*start)(void *) = (int (*)(void *))args->start_func; __pthread_exit((void *)(uintptr_t)start(args->start_arg)); return 0; } #else +#ifdef __wasip3__ +/* + * We want to ensure wasip3_thread_start is linked whenever + * pthread_create is used. The following reference is to ensure that. + * Otherwise, the linker doesn't notice the dependency because + * wasip3_thread_start is used indirectly via a wasm export. + */ +void wasip3_thread_start(void *context); +hidden void *__dummy_reference = wasip3_thread_start; + +hidden void __wasip3_thread_start_C(int tid, void *context) +{ + struct start_args *args = context; + pthread_t self = __pthread_self(); + // Set the thread ID (TID) on the pthread structure. The TID is stored + // atomically since it is also stored by the parent thread; this way, + // whichever thread (parent or child) reaches this point first can proceed + // without waiting. + atomic_store((atomic_int *)&(self->tid), tid); + // Execute the user's start function. + __pthread_exit(args->start_func(args->start_arg)); +} +#else /* * We want to ensure wasi_thread_start is linked whenever * pthread_create is used. The following reference is to ensure that. @@ -318,14 +357,15 @@ hidden void __wasi_thread_start_C(int tid, void *p) // atomically since it is also stored by the parent thread; this way, // whichever thread (parent or child) reaches this point first can proceed // without waiting. - atomic_store((atomic_int *) &(self->tid), tid); + atomic_store((atomic_int *)&(self->tid), tid); // Execute the user's start function. __pthread_exit(args->start_func(args->start_arg)); } #endif +#endif #ifdef __wasilibc_unmodified_upstream -#define ROUND(x) (((x)+PAGE_SIZE-1)&-PAGE_SIZE) +#define ROUND(x) (((x) + PAGE_SIZE - 1) & -PAGE_SIZE) #else /* * As we allocate stack with malloc() instead of mmap/mprotect, @@ -333,13 +373,13 @@ hidden void __wasi_thread_start_C(int tid, void *p) * Instead, round up to a sane alignment. * Note: PAGE_SIZE is rather big on WASM. (65536) */ -#define ROUND(x) (((x)+16-1)&-16) +#define ROUND(x) (((x) + 16 - 1) & -16) #endif /* pthread_key_create.c overrides this */ static volatile size_t dummy = 0; weak_alias(dummy, __pthread_tsd_size); -static void *dummy_tsd[1] = { 0 }; +static void *dummy_tsd[1] = {0}; weak_alias(dummy_tsd, __pthread_tsd_main); static FILE *volatile dummy_file = 0; @@ -349,7 +389,8 @@ weak_alias(dummy_file, __stderr_used); static void init_file_lock(FILE *f) { - if (f && f->lock<0) f->lock = 0; + if (f && f->lock < 0) + f->lock = 0; } int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg) @@ -359,34 +400,36 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att struct pthread *self, *new; unsigned char *map = 0, *stack = 0, *tsd = 0, *stack_limit; #ifdef __wasilibc_unmodified_upstream - unsigned flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND - | CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS - | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | CLONE_DETACHED; + unsigned flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS | CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | CLONE_DETACHED; #endif - pthread_attr_t attr = { 0 }; + pthread_attr_t attr = {0}; sigset_t set; #ifndef __wasilibc_unmodified_upstream size_t tls_size = __builtin_wasm_tls_size(); size_t tls_align = __builtin_wasm_tls_align(); - void* tls_base = __builtin_wasm_tls_base(); - void* new_tls_base; + void *tls_base = __builtin_wasm_tls_base(); + void *new_tls_base; size_t tls_offset; + /* We'll need to allocate space for a correctly-aligned TLS block, + so adjust the size accordingly. */ tls_size += tls_align; #endif #ifdef __wasilibc_unmodified_upstream - if (!libc.can_do_threads) return ENOSYS; + if (!libc.can_do_threads) + return ENOSYS; #endif self = __pthread_self(); - if (!libc.threaded) { - for (FILE *f=*__ofl_lock(); f; f=f->next) + if (!libc.threaded) + { + for (FILE *f = *__ofl_lock(); f; f = f->next) init_file_lock(f); __ofl_unlock(); init_file_lock(__stdin_used); init_file_lock(__stdout_used); init_file_lock(__stderr_used); #ifdef __wasilibc_unmodified_upstream - __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, SIGPT_SET, 0, _NSIG/8); + __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, SIGPT_SET, 0, _NSIG / 8); #endif self->tsd = (void **)__pthread_tsd_main; #ifdef __wasilibc_unmodified_upstream @@ -394,15 +437,18 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att #endif libc.threaded = 1; } - if (attrp && !c11) attr = *attrp; + if (attrp && !c11) + attr = *attrp; __acquire_ptc(); - if (!attrp || c11) { + if (!attrp || c11) + { attr._a_stacksize = __default_stacksize; attr._a_guardsize = __default_guardsize; } - if (attr._a_stackaddr) { + if (attr._a_stackaddr) + { #ifdef __wasilibc_unmodified_upstream size_t need = libc.tls_size + __pthread_tsd_size; #else @@ -414,7 +460,8 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att /* Use application-provided stack for TLS only when * it does not take more than ~12% or 2k of the * application's stack space. */ - if (need < size/8 && need < 2048) { + if (need < size / 8 && need < 2048) + { tsd = stack - __pthread_tsd_size; #ifdef __wasilibc_unmodified_upstream stack = tsd - libc.tls_size; @@ -422,33 +469,43 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att stack = tsd - tls_size; #endif memset(stack, 0, need); - } else { + } + else + { size = ROUND(need); } guard = 0; - } else { + } + else + { guard = ROUND(attr._a_guardsize); size = guard + ROUND(attr._a_stacksize #ifdef __wasilibc_unmodified_upstream - + libc.tls_size + __pthread_tsd_size); + + libc.tls_size + __pthread_tsd_size); #else - + tls_size + __pthread_tsd_size); + + tls_size + __pthread_tsd_size); #endif } - if (!tsd) { + if (!tsd) + { #ifdef __wasilibc_unmodified_upstream - if (guard) { - map = __mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0); - if (map == MAP_FAILED) goto fail; - if (__mprotect(map+guard, size-guard, PROT_READ|PROT_WRITE) - && errno != ENOSYS) { + if (guard) + { + map = __mmap(0, size, PROT_NONE, MAP_PRIVATE | MAP_ANON, -1, 0); + if (map == MAP_FAILED) + goto fail; + if (__mprotect(map + guard, size - guard, PROT_READ | PROT_WRITE) && errno != ENOSYS) + { __munmap(map, size); goto fail; } - } else { - map = __mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); - if (map == MAP_FAILED) goto fail; + } + else + { + map = __mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); + if (map == MAP_FAILED) + goto fail; } #else /* Process the deferred free request if any before @@ -460,13 +517,15 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att process_map_base_deferred_free(); __tl_unlock(); map = malloc(size); - if (!map) goto fail; + if (!map) + goto fail; #endif tsd = map + size - __pthread_tsd_size; #ifndef __wasilibc_unmodified_upstream - memset(tsd, 0, __pthread_tsd_size); + memset(tsd, 0, __pthread_tsd_size); #endif - if (!stack) { + if (!stack) + { #ifdef __wasilibc_unmodified_upstream stack = tsd - libc.tls_size; #else @@ -481,7 +540,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att #else new_tls_base = __copy_tls(tsd - tls_size); tls_offset = new_tls_base - tls_base; - new = (void*)((uintptr_t)self + tls_offset); + new = (void *)((uintptr_t)self + tls_offset); #endif new->map_base = map; new->map_size = size; @@ -491,9 +550,12 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att new->self = new; new->tsd = (void *)tsd; new->locale = &libc.global_locale; - if (attr._a_detach) { + if (attr._a_detach) + { new->detach_state = DT_DETACHED; - } else { + } + else + { new->detach_state = DT_JOINABLE; } new->robust_list.head = &new->robust_list.head; @@ -520,8 +582,8 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att * working with a copy of the set so we can restore the * original mask in the calling thread. */ memcpy(&args->sig_mask, &set, sizeof args->sig_mask); - args->sig_mask[(SIGCANCEL-1)/8/sizeof(long)] &= - ~(1UL<<((SIGCANCEL-1)%(8*sizeof(long)))); + args->sig_mask[(SIGCANCEL - 1) / 8 / sizeof(long)] &= + ~(1UL << ((SIGCANCEL - 1) % (8 * sizeof(long)))); #else /* Align the stack to struct start_args */ stack -= sizeof(struct start_args); @@ -529,26 +591,31 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att struct start_args *args = (void *)stack; /* Align the stack to 16 and store it */ - new->stack = (void *)((uintptr_t) stack & -16); + new->stack = (void *)((uintptr_t)stack & -16); /* Correct the stack size */ new->stack_size = stack - stack_limit; args->stack = new->stack; /* just for convenience of asm trampoline */ args->start_func = entry; args->start_arg = arg; - args->tls_base = (void*)new_tls_base; + args->tls_base = (void *)new_tls_base; #endif __tl_lock(); - if (!libc.threads_minus_1++) libc.need_locks = 1; + if (!libc.threads_minus_1++) + libc.need_locks = 1; #ifdef __wasilibc_unmodified_upstream ret = __clone((c11 ? start_c11 : start), stack, flags, args, &new->tid, TP_ADJ(new), &__thread_list_lock); +#else +#ifdef __wasip3__ + ret = wasip3_thread_new_indirect(wasip3_thread_start, (void *)args); #else /* Instead of `__clone`, WASI uses a host API to instantiate a new version * of the current module and start executing the entry function. The * wasi-threads specification requires the module to export a * `wasi_thread_start` function, which is invoked with `args`. */ - ret = __wasi_thread_spawn((void *) args); + ret = __wasi_thread_spawn((void *)args); +#endif #endif #ifdef __wasilibc_unmodified_upstream @@ -556,12 +623,15 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att * was requested, attempt it before unlocking the thread list so * that the failed thread is never exposed and so that we can * clean up all transient resource usage before returning. */ - if (ret < 0) { + if (ret < 0) + { ret = -EAGAIN; - } else if (attr._a_sched) { + } + else if (attr._a_sched) + { ret = __syscall(SYS_sched_setscheduler, - new->tid, attr._a_policy, &attr._a_prio); - if (a_swap(&args->control, ret ? 3 : 0)==2) + new->tid, attr._a_policy, &attr._a_prio); + if (a_swap(&args->control, ret ? 3 : 0) == 2) __wake(&args->control, 1, 1); if (ret) __wait(&args->control, 0, 3, 0); @@ -578,20 +648,27 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att * to set this field; this way, whichever thread reaches this point first * can continue without waiting. */ assert(ret != 0 && ret <= WASI_THREADS_MAX_TID); - if (ret < 0) { + if (ret < 0) + { ret = -EAGAIN; - } else { - atomic_store((atomic_int *) &(new->tid), ret); + } + else + { + atomic_store((atomic_int *)&(new->tid), ret); } #endif - if (ret >= 0) { + if (ret >= 0) + { new->next = self->next; new->prev = self; new->next->prev = new; new->prev->next = new; - } else { - if (!--libc.threads_minus_1) libc.need_locks = 0; + } + else + { + if (!--libc.threads_minus_1) + libc.need_locks = 0; } __tl_unlock(); #ifdef __wasilibc_unmodified_upstream @@ -599,15 +676,21 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att #endif __release_ptc(); - if (ret < 0) { + if (ret < 0) + { #ifdef __wasilibc_unmodified_upstream - if (map) __munmap(map, size); + if (map) + __munmap(map, size); #else free(map); #endif return -ret; } +#ifdef __wasip3__ + wasip3_thread_yield_to(new->tid); +#endif + *res = new; return 0; fail: diff --git a/libc-top-half/musl/src/thread/wasm32/wasip3_thread_start.s b/libc-top-half/musl/src/thread/wasm32/wasip3_thread_start.s new file mode 100644 index 000000000..b140f618b --- /dev/null +++ b/libc-top-half/musl/src/thread/wasm32/wasip3_thread_start.s @@ -0,0 +1,54 @@ + .text + + .export_name wasip3_thread_start, wasip3_thread_start + + .globaltype __init_stack_pointer, i32 + .functype __wasip3_thread_start_C (i32, i32) -> () + .functype __wasm_component_model_builtin_context_set_0 (i32) -> () + .import_module __wasm_component_model_builtin_context_set_0, "$root" + .import_name __wasm_component_model_builtin_context_set_0, "[context-set-0]" + .functype __wasm_component_model_builtin_context_set_1 (i32) -> () + .import_module __wasm_component_model_builtin_context_set_1, "$root" + .import_name __wasm_component_model_builtin_context_set_1, "[context-set-1]" + .import_module __wasm_component_model_builtin_thread_index, "$root" + .import_name __wasm_component_model_builtin_thread_index, "[thread-index]" + .functype __wasm_component_model_builtin_thread_index () -> (i32) + + .hidden wasip3_thread_start + .globl wasip3_thread_start + .type wasip3_thread_start,@function + +wasip3_thread_start: + .functype wasip3_thread_start (i32) -> () + + # Set up the minimum C environment. + local.get 0 # start_arg + i32.load 0 # stack + call __wasm_component_model_builtin_context_set_0 + + local.get 0 # start_arg + i32.load 4 # tls_base + call __wasm_component_model_builtin_context_set_1 + # Make the C function do the rest of work. + call __wasm_component_model_builtin_thread_index + local.get 0 # start_arg + call __wasip3_thread_start_C + + # Unlock thread list. (as CLONE_CHILD_CLEARTID would do for Linux) + # + # Note: once we unlock the thread list, our "map_base" can be freed + # by a joining thread. It's safe as we are in ASM and no longer use + # our C stack or pthread_t. It's impossible to do this safely in C + # because there is no way to tell the C compiler not to use C stack. + i32.const __thread_list_lock + i32.const 0 + i32.atomic.store 0 + # As an optimization, we can check tl_lock_waiters here. + # But for now, simply wake up unconditionally as + # CLONE_CHILD_CLEARTID does. + i32.const __thread_list_lock + i32.const 1 + memory.atomic.notify 0 + drop + + end_function \ No newline at end of file diff --git a/test/src/coop_thread.c b/test/src/coop_thread.c new file mode 100644 index 000000000..a50fb088e --- /dev/null +++ b/test/src/coop_thread.c @@ -0,0 +1,44 @@ +#include +#include +#include +void *thread_start(void *arg) +{ + // A thread local, which should have a separate address per-thread, but the same initial value. + static _Thread_local int my_thread_local = 55; + static int my_non_thread_local = 100; + printf("Thread started: arg=%lu, my_thread_local(%p)=%d, my_non_thread_local=%d\n", + (uintptr_t)arg, (void *)&my_thread_local, my_thread_local, my_non_thread_local); + + sched_yield(); + printf("Thread resumed: arg=%lu, my_thread_local(%p)=%d, my_non_thread_local=%d\n", + (uintptr_t)arg, (void *)&my_thread_local, my_thread_local, my_non_thread_local); + + // This should not affect other threads' copies of the thread local. + my_thread_local += (uintptr_t)arg; + my_non_thread_local += (uintptr_t)arg; + + return (void *)((uintptr_t)arg + 100); +} + +int main() +{ + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_t threads[3]; + + printf("Creating threads...\n"); + pthread_create(&threads[0], &attr, &thread_start, (void *)12); + pthread_create(&threads[1], &attr, &thread_start, (void *)13); + pthread_create(&threads[2], &attr, &thread_start, (void *)14); + printf("Threads created!\n"); + + void *ret; + pthread_join(threads[0], &ret); + printf("Thread 1 returned: %lu\n", (uintptr_t)ret); + + pthread_join(threads[1], &ret); + printf("Thread 2 returned: %lu\n", (uintptr_t)ret); + + pthread_join(threads[2], &ret); + printf("Thread 3 returned: %lu\n", (uintptr_t)ret); +} From 0b14220b50db568a66e98d745454429383ac7531 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Fri, 9 Jan 2026 12:25:43 +0000 Subject: [PATCH 07/41] Reactor changes --- libc-bottom-half/CMakeLists.txt | 2 +- libc-bottom-half/crt/crt1-reactor.c | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libc-bottom-half/CMakeLists.txt b/libc-bottom-half/CMakeLists.txt index 1045a61b2..e093edfcb 100644 --- a/libc-bottom-half/CMakeLists.txt +++ b/libc-bottom-half/CMakeLists.txt @@ -188,7 +188,7 @@ foreach(file crt/crt1.c # create a custom target for each file add_library(${filename}.o OBJECT ${file}) - target_link_libraries(${filename}.o PUBLIC musl-top-half-interface) + target_link_libraries(${filename}.o PRIVATE musl-top-half-interface) set_pic(${filename}.o) target_compile_options(${filename}.o PRIVATE -fvisibility=default) diff --git a/libc-bottom-half/crt/crt1-reactor.c b/libc-bottom-half/crt/crt1-reactor.c index 778363d63..1d547fc69 100644 --- a/libc-bottom-half/crt/crt1-reactor.c +++ b/libc-bottom-half/crt/crt1-reactor.c @@ -1,6 +1,9 @@ #if defined(_REENTRANT) #include #endif + +#include + extern void __wasi_init_tp(void); extern void __wasm_call_ctors(void); From 3eb98bc96ffb07f1ff97ff19aeb699b02b7791fe Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Tue, 13 Jan 2026 16:04:45 +0000 Subject: [PATCH 08/41] Task init work --- libc-bottom-half/CMakeLists.txt | 14 +++- libc-bottom-half/crt/crt1-command.c | 4 +- .../sources/__wasilibc_init_task.s | 68 +++++++++++++++++++ libc-bottom-half/sources/wasip3.c | 2 +- .../musl/src/internal/pthread_impl.h | 5 ++ .../musl/src/thread/pthread_create.c | 10 +++ libc-top-half/musl/src/thread/pthread_join.c | 11 ++- 7 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 libc-bottom-half/sources/__wasilibc_init_task.s diff --git a/libc-bottom-half/CMakeLists.txt b/libc-bottom-half/CMakeLists.txt index 8acfefdf1..6c6474f87 100644 --- a/libc-bottom-half/CMakeLists.txt +++ b/libc-bottom-half/CMakeLists.txt @@ -99,6 +99,7 @@ set(bottom_half_sources sources/__wasilibc_dt.c sources/__wasilibc_environ.c sources/__wasilibc_fd_renumber.c + sources/__wasilibc_init_task.s sources/__wasilibc_initialize_environ.c sources/__wasilibc_random.c sources/__wasilibc_real.c @@ -216,15 +217,24 @@ else() # wasip2+: crt1-command.o is modified from what CMake produces to # additionally have a custom section representing the type information needed # for its contained export. This is the `wasi:cli/run` interface, for example. + if (WASI STREQUAL "p2") + set(world wasi:cli/command@0.2.0) + set(wit_target wasip2-wits) + set(wit_dir ${wasip2_wit_dir}) + elseif (WASI STREQUAL "p3") + set(world wasi:cli/command@0.3.0-rc-2025-09-16) + set(wit_target wasip3-wits) + set(wit_dir ${wasip3_wit_dir}) + endif() add_custom_command( OUTPUT ${SYSROOT_LIB}/crt1-command.o COMMAND ${wasm_tools} component embed ${wit_dir} $ - --world wasi:cli/command@0.2.0 + --world ${world} -o ${SYSROOT_LIB}/crt1-command.o - DEPENDS crt1-command wasi-wits $ wasm-tools + DEPENDS crt1-command ${wit_target} $ wasm-tools ) endif() diff --git a/libc-bottom-half/crt/crt1-command.c b/libc-bottom-half/crt/crt1-command.c index b108b2309..74bf2e8cb 100644 --- a/libc-bottom-half/crt/crt1-command.c +++ b/libc-bottom-half/crt/crt1-command.c @@ -17,6 +17,8 @@ __attribute__((export_name("_start"))) void _start(void) // `wit-bindgen` rigamarole and the signature of this function is simple enough // that this shouldn't be too problematic (in theory). __attribute__((export_name("wasi:cli/run@0.2.0#run"))) int _start(void) +#elif defined(__wasip3__) +__attribute__((export_name("wasi:cli/run@0.3.0-rc-2025-09-16#run"))) int _start(void) #else #error "Unsupported WASI version" #endif @@ -61,7 +63,7 @@ __attribute__((export_name("wasi:cli/run@0.2.0#run"))) int _start(void) if (r != 0) { __wasi_proc_exit(r); } -#elif defined(__wasip2__) +#elif defined(__wasip2__) || defined(__wasip3__) return r != 0; #else #error "Unsupported WASI version" diff --git a/libc-bottom-half/sources/__wasilibc_init_task.s b/libc-bottom-half/sources/__wasilibc_init_task.s new file mode 100644 index 000000000..e34c310e7 --- /dev/null +++ b/libc-bottom-half/sources/__wasilibc_init_task.s @@ -0,0 +1,68 @@ + .text + + .export_name __wasilibc_init_task, __wasilibc_init_task + .export_name __wasilibc_init_task_async, __wasilibc_init_task_async + + .globaltype __init_stack_pointer, i32 + .globaltype __init_tls_base, i32 + .globaltype __tls_size, i32, immutable + .globaltype __tls_align, i32, immutable + + .functype __wasm_component_model_builtin_context_set_0 (i32) -> () + .import_module __wasm_component_model_builtin_context_set_0, "$root" + .import_name __wasm_component_model_builtin_context_set_0, "[context-set-0]" + .functype __wasm_component_model_builtin_context_set_1 (i32) -> () + .import_module __wasm_component_model_builtin_context_set_1, "$root" + .import_name __wasm_component_model_builtin_context_set_1, "[context-set-1]" + + .functype malloc (i32) -> (i32) + .functype __copy_tls (i32) -> (i32) + + .globl __wasilibc_init_task + .type __wasilibc_init_task,@function + .globl __wasilibc_init_task_async + .type __wasilibc_init_task_async,@function + +__wasilibc_init_task: + .functype __wasilibc_init_task () -> () + + global.get __init_stack_pointer + call __wasm_component_model_builtin_context_set_0 + + global.get __init_tls_base + call __wasm_component_model_builtin_context_set_1 + + # Allocate a new TLS area + global.get __tls_size + # TODO align + call malloc + call __copy_tls + call __wasm_component_model_builtin_context_set_1 + + end_function + +__wasilibc_init_task_async: + .functype __wasilibc_init_task_async () -> () + + # malloc and __init_tls may use the stack pointer and TLS base, so set those first + # to the statically-allocated values used for synchronous tasks. + global.get __init_stack_pointer + call __wasm_component_model_builtin_context_set_0 + + global.get __init_tls_base + call __wasm_component_model_builtin_context_set_1 + + # Allocate a new stack + # Value chosen for parity with __default_stacksize in pthread_impl.h + i32.const 131072 + call malloc + call __wasm_component_model_builtin_context_set_0 + + # Allocate a new TLS area + global.get __tls_size + # TODO align + call malloc + call __copy_tls + call __wasm_component_model_builtin_context_set_1 + + end_function diff --git a/libc-bottom-half/sources/wasip3.c b/libc-bottom-half/sources/wasip3.c index 50a7d6d7a..13fe0a5e1 100644 --- a/libc-bottom-half/sources/wasip3.c +++ b/libc-bottom-half/sources/wasip3.c @@ -1172,7 +1172,7 @@ uint32_t wasip3_thread_new_indirect(void (*start_function)(void*), void* arg) { } __attribute__((__import_module__("$root"), __import_name__("[thread-switch-to]"))) -extern void __thread_switch_to(uint32_t); +extern uint32_t __thread_switch_to(uint32_t); void wasip3_thread_switch_to(uint32_t thread) { __thread_switch_to(thread); diff --git a/libc-top-half/musl/src/internal/pthread_impl.h b/libc-top-half/musl/src/internal/pthread_impl.h index 0106ac385..6c70becb2 100644 --- a/libc-top-half/musl/src/internal/pthread_impl.h +++ b/libc-top-half/musl/src/internal/pthread_impl.h @@ -17,6 +17,8 @@ #include "atomic.h" #include "futex.h" +#include + #include "pthread_arch.h" #define pthread __pthread @@ -66,6 +68,9 @@ struct pthread { volatile int killlock[1]; char *dlerror_buf; void *stdio_locks; + #ifdef __wasip3__ + int joining_tid; + #endif /* Part 3 -- the positions of these fields relative to * the end of the structure is external and internal ABI. */ diff --git a/libc-top-half/musl/src/thread/pthread_create.c b/libc-top-half/musl/src/thread/pthread_create.c index f9bbc512e..45862575f 100644 --- a/libc-top-half/musl/src/thread/pthread_create.c +++ b/libc-top-half/musl/src/thread/pthread_create.c @@ -235,6 +235,14 @@ static void __pthread_exit(void *result) /* Wake any joiner. */ a_store(&self->detach_state, DT_EXITED); __wake(&self->detach_state, 1, 1); + #ifdef __wasip3__ + // Yield to the joining thread, if any. + // Note that we use yield_to here instead of switch_to, + // so that eventually this thread will get rescheduled + // and can exit properly. + if (self->joining_tid != 0) + wasip3_thread_yield_to(self->joining_tid); + #endif #ifdef __wasilibc_unmodified_upstream for (;;) @@ -326,6 +334,8 @@ static int start_c11(void *p) */ void wasip3_thread_start(void *context); hidden void *__dummy_reference = wasip3_thread_start; +void __wasilibc_init_task(void); +hidden void * __dummy_reference_init_task = __wasilibc_init_task; hidden void __wasip3_thread_start_C(int tid, void *context) { diff --git a/libc-top-half/musl/src/thread/pthread_join.c b/libc-top-half/musl/src/thread/pthread_join.c index b06e7e75e..de194d8fa 100644 --- a/libc-top-half/musl/src/thread/pthread_join.c +++ b/libc-top-half/musl/src/thread/pthread_join.c @@ -32,8 +32,17 @@ static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec } int __pthread_join(pthread_t t, void **res) -{ +{ + #ifdef __wasip3__ + if (t->detach_state != DT_EXITED) { + t->joining_tid = __pthread_self()->tid; + wasip3_thread_switch_to(t->tid); + } + if (res) *res = t->result; + return 0; + #else return __pthread_timedjoin_np(t, res, 0); + #endif } static int __pthread_tryjoin_np(pthread_t t, void **res) From 5f346205d984fdd93bd4799b0f89359a4ed34d71 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Tue, 13 Jan 2026 16:43:06 +0000 Subject: [PATCH 09/41] Remove bad change --- cmake/bindings.cmake | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index 32ab63da2..016cf398d 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -7,7 +7,19 @@ endif() # If `wit-bindgen` is on the system and has the right version, favor that, # otherwise download a known good version. find_program(WIT_BINDGEN_EXECUTABLE NAMES wit-bindgen) -set(WIT_BINDGEN_EXECUTABLE "/Users/sybrand/src/bytecodealliance/wit-bindgen/target/debug/wit-bindgen") +if(WIT_BINDGEN_EXECUTABLE) + message(STATUS "Found wit-bindgen: ${WIT_BINDGEN_EXECUTABLE}") + + execute_process( + COMMAND ${WIT_BINDGEN_EXECUTABLE} --version + OUTPUT_VARIABLE WIT_BINDGEN_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (NOT (WIT_BINDGEN_VERSION MATCHES "0\\.48\\.0")) + message(WARNING "wit-bindgen version 0.48.0 is required, found: ${WIT_BINDGEN_VERSION}") + set(WIT_BINDGEN_EXECUTABLE "") + endif() +endif() if (NOT WIT_BINDGEN_EXECUTABLE) include(ba-download) From e862c560cf03cd0a209447f9981d467c3fce2d05 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Tue, 13 Jan 2026 16:44:09 +0000 Subject: [PATCH 10/41] Remove unecessary changes --- libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c b/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c index cedf3b540..b8e589055 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c +++ b/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c @@ -5,13 +5,11 @@ #include #include #include -#include int sched_yield(void) { #ifdef __wasip1__ __wasi_errno_t error = __wasi_sched_yield(); - if (error != 0) - { + if (error != 0) { errno = error; return -1; } From c2b32bc4f4784fca7e05a65bab21171f709ac16a Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Tue, 13 Jan 2026 16:44:47 +0000 Subject: [PATCH 11/41] Remove unecessary changes --- libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c b/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c index 2e019deae..ace4bcd9c 100644 --- a/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c +++ b/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c @@ -7,15 +7,14 @@ #include #include -noreturn void _Exit(int status) -{ +noreturn void _Exit(int status) { #if defined(__wasip1__) __wasi_proc_exit(status); #elif defined(__wasip2__) || defined(__wasip3__) exit_result_void_void_t exit_status = { .is_err = status != 0 }; exit_exit(&exit_status); #else -#error "Unknown WASI version" +# error "Unknown WASI version" #endif } From cfcf4ffec0b4b91445079c8627803d95a4cb34eb Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Tue, 13 Jan 2026 16:47:42 +0000 Subject: [PATCH 12/41] Update bindings --- cmake/bindings.cmake | 8 +- libc-bottom-half/crt/crt1-reactor.c | 2 - .../crt/wasm32/wasip3-crt1-command.s | 31 -------- .../crt/wasm32/wasip3-crt1-reactor.s | 32 -------- .../headers/public/wasi/__generated_wasip3.h | 15 +--- libc-bottom-half/sources/wasip3.c | 75 ++---------------- .../sources/wasip3_component_type.o | Bin 8092 -> 8092 bytes 7 files changed, 16 insertions(+), 147 deletions(-) delete mode 100644 libc-bottom-half/crt/wasm32/wasip3-crt1-command.s delete mode 100644 libc-bottom-half/crt/wasm32/wasip3-crt1-reactor.s diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index 016cf398d..fde6d2535 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -26,7 +26,7 @@ if (NOT WIT_BINDGEN_EXECUTABLE) ba_download( wit-bindgen "https://github.com/bytecodealliance/wit-bindgen" - "0.48.0" + "0.50.0" ) ExternalProject_Get_Property(wit-bindgen SOURCE_DIR) set(wit_bindgen "${SOURCE_DIR}/wit-bindgen") @@ -142,9 +142,9 @@ add_custom_target(bindings DEPENDS bindings-p2 bindings-p3) function(wit_bindgen_edit p) add_custom_target( bindings-${p}-edit - COMMAND sed -i "" "'s_#include .wasi${p}\.h._#include \"wasi/wasi${p}.h\"_'" ${bottom_half}/sources/wasi${p}.c - COMMAND sed -i "" "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/__generated_wasi${p}.h - COMMAND sed -i "" "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasi${p}.c + COMMAND sed -i '' "'s_#include .wasi${p}\.h._#include \"wasi/wasi${p}.h\"_'" ${bottom_half}/sources/wasi${p}.c + COMMAND sed -i '' "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/__generated_wasi${p}.h + COMMAND sed -i '' "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasi${p}.c DEPENDS bindings-${p} ) add_dependencies(bindings bindings-${p}-edit) diff --git a/libc-bottom-half/crt/crt1-reactor.c b/libc-bottom-half/crt/crt1-reactor.c index 45f37e0fb..86cab13cb 100644 --- a/libc-bottom-half/crt/crt1-reactor.c +++ b/libc-bottom-half/crt/crt1-reactor.c @@ -2,8 +2,6 @@ #include #endif -#include - extern void __wasi_init_tp(void); extern void __wasm_call_ctors(void); diff --git a/libc-bottom-half/crt/wasm32/wasip3-crt1-command.s b/libc-bottom-half/crt/wasm32/wasip3-crt1-command.s deleted file mode 100644 index b7edbbb05..000000000 --- a/libc-bottom-half/crt/wasm32/wasip3-crt1-command.s +++ /dev/null @@ -1,31 +0,0 @@ - .text - - .export_name _start, _start - - .globaltype __init_stack_pointer, i32 - .globaltype __init_tls_base, i32 - - .functype _libc_start () -> () - - .functype __wasm_component_model_builtin_context_set_0 (i32) -> () - .import_module __wasm_component_model_builtin_context_set_0, "$root" - .import_name __wasm_component_model_builtin_context_set_0, "[context-set-0]" - .functype __wasm_component_model_builtin_context_set_1 (i32) -> () - .import_module __wasm_component_model_builtin_context_set_1, "$root" - .import_name __wasm_component_model_builtin_context_set_1, "[context-set-1]" - - .globl _start - .type _start,@function - -_start: - .functype _start () -> () - - global.get __init_stack_pointer - call __wasm_component_model_builtin_context_set_0 - - global.get __init_tls_base - call __wasm_component_model_builtin_context_set_1 - - call _libc_start - - end_function diff --git a/libc-bottom-half/crt/wasm32/wasip3-crt1-reactor.s b/libc-bottom-half/crt/wasm32/wasip3-crt1-reactor.s deleted file mode 100644 index a1f4d6bcd..000000000 --- a/libc-bottom-half/crt/wasm32/wasip3-crt1-reactor.s +++ /dev/null @@ -1,32 +0,0 @@ - .text - - .export_name _initialize, _initialize - - .globaltype __init_stack_pointer, i32 - .globaltype __init_tls_base, i32 - - .functype _libc_initialize () -> () - - .functype __wasm_component_model_builtin_context_set_0 (i32) -> () - .import_module __wasm_component_model_builtin_context_set_0, "$root" - .import_name __wasm_component_model_builtin_context_set_0, "[context-set-0]" - .functype __wasm_component_model_builtin_context_set_1 (i32) -> () - .import_module __wasm_component_model_builtin_context_set_1, "$root" - .import_name __wasm_component_model_builtin_context_set_1, "[context-set-1]" - - .globl _initialize - .type _initialize,@function - -_initialize: - .functype _initialize () -> () - - global.get __init_stack_pointer - call __wasm_component_model_builtin_context_set_0 - - global.get __init_tls_base - call __wasm_component_model_builtin_context_set_1 - - call _libc_initialize - - end_function - diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h index cdad5b84c..78128912d 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h @@ -75,17 +75,10 @@ typedef enum wasip3_waitable_state { void wasip3_backpressure_inc(void); void wasip3_backpressure_dec(void); -void* wasip3_context_get(size_t index); -void wasip3_context_set(size_t index, void* value); -void wasip3_thread_yield(void); -uint32_t wasip3_thread_yield_cancellable(void); -uint32_t wasip3_thread_index(void); -uint32_t wasip3_thread_new_indirect(void (*start_function)(void*), void* arg); -void wasip3_thread_switch_to(uint32_t thread); -uint32_t wasip3_thread_switch_to_cancellable(uint32_t thread); -void wasip3_thread_resume_later(uint32_t thread); -void wasip3_thread_yield_to(uint32_t thread); -uint32_t wasip3_thread_yield_to_cancellable(uint32_t thread); +void* wasip3_context_get(void); +void wasip3_context_set(void*); +void wasip3_yield(void); +uint32_t wasip3_yield_cancellable(void); diff --git a/libc-bottom-half/sources/wasip3.c b/libc-bottom-half/sources/wasip3.c index 13fe0a5e1..3194a1149 100644 --- a/libc-bottom-half/sources/wasip3.c +++ b/libc-bottom-half/sources/wasip3.c @@ -1120,92 +1120,33 @@ void wasip3_backpressure_dec(void) { } __attribute__((__import_module__("$root"), __import_name__("[context-get-0]"))) -extern void* __context_get_0(void); +extern void* __context_get(void); -__attribute__((__import_module__("$root"), __import_name__("[context-get-1]"))) -extern void* __context_get_1(void); - -void* wasip3_context_get(size_t index) { - if (index == 0) return __context_get_0(); - if (index == 1) return __context_get_1(); - return NULL; +void* wasip3_context_get() { + return __context_get(); } __attribute__((__import_module__("$root"), __import_name__("[context-set-0]"))) -extern void __context_set_0(void*); - -__attribute__((__import_module__("$root"), __import_name__("[context-set-1]"))) -extern void __context_set_1(void*); +extern void __context_set(void*); -void wasip3_context_set(size_t index, void *value) { - if (index == 0) __context_set_0(value); - else if (index == 1) __context_set_1(value); +void wasip3_context_set(void *val) { + return __context_set(val); } __attribute__((__import_module__("$root"), __import_name__("[thread-yield]"))) extern uint32_t __thread_yield(void); -void wasip3_thread_yield(void) { +void wasip3_yield(void) { __thread_yield(); } __attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-yield]"))) extern uint32_t __thread_yield_cancellable(void); -uint32_t wasip3_thread_yield_cancellable(void) { +uint32_t wasip3_yield_cancellable(void) { return __thread_yield_cancellable(); } -__attribute__((__import_module__("$root"), __import_name__("[thread-index]"))) -extern uint32_t __thread_index(void); - -uint32_t wasip3_thread_index(void) { - return __thread_index(); -} - -__attribute__((__import_module__("$root"), __import_name__("[thread-new-indirect-v0]"))) -extern uint32_t __thread_new_indirect(uint32_t, void*); - -uint32_t wasip3_thread_new_indirect(void (*start_function)(void*), void* arg) { - return __thread_new_indirect((uint32_t)(uintptr_t)start_function, arg - ); -} - -__attribute__((__import_module__("$root"), __import_name__("[thread-switch-to]"))) -extern uint32_t __thread_switch_to(uint32_t); - -void wasip3_thread_switch_to(uint32_t thread) { - __thread_switch_to(thread); -} - -__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-switch-to]"))) -extern uint32_t __thread_switch_to_cancellable(uint32_t); - -uint32_t wasip3_thread_switch_to_cancellable(uint32_t thread) { - return __thread_switch_to_cancellable(thread); -} - -__attribute__((__import_module__("$root"), __import_name__("[thread-resume-later]"))) -extern void __thread_resume_later(uint32_t); - -void wasip3_thread_resume_later(uint32_t thread) { - __thread_resume_later(thread); -} - -__attribute__((__import_module__("$root"), __import_name__("[thread-yield-to]"))) -extern uint32_t __thread_yield_to(uint32_t); - -void wasip3_thread_yield_to(uint32_t thread) { - __thread_yield_to(thread); -} - -__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-yield-to]"))) -extern uint32_t __thread_yield_to_cancellable(uint32_t); - -uint32_t wasip3_thread_yield_to_cancellable(uint32_t thread) { - return __thread_yield_to_cancellable(thread); -} - // Component Adapters diff --git a/libc-bottom-half/sources/wasip3_component_type.o b/libc-bottom-half/sources/wasip3_component_type.o index 2134f29a58f9add8550532cd099d3c263b8317a3..d30145e7b9e236c6703af6fc362b569e8a842148 100644 GIT binary patch delta 34 pcmbPZKgWK9r@WZ4o&j%pW{GZ6W?o8qYMyQ~n}MFG!Q^;(TL8kP3W5Lt delta 34 pcmbPZKgWK9r@WY Date: Tue, 13 Jan 2026 16:50:48 +0000 Subject: [PATCH 13/41] Update bindings --- cmake/bindings.cmake | 6 ++--- libc-bottom-half/crt/crt1-reactor.c | 1 - .../headers/public/wasi/__generated_wasip2.h | 2 +- .../headers/public/wasi/__generated_wasip3.h | 9 +++---- libc-bottom-half/sources/wasip2.c | 2 +- .../sources/wasip2_component_type.o | Bin 10846 -> 10846 bytes libc-bottom-half/sources/wasip3.c | 24 +++++++----------- .../sources/wasip3_component_type.o | Bin 8092 -> 8092 bytes 8 files changed, 18 insertions(+), 26 deletions(-) diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index fde6d2535..d5ef6267b 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -15,8 +15,8 @@ if(WIT_BINDGEN_EXECUTABLE) OUTPUT_VARIABLE WIT_BINDGEN_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) - if (NOT (WIT_BINDGEN_VERSION MATCHES "0\\.48\\.0")) - message(WARNING "wit-bindgen version 0.48.0 is required, found: ${WIT_BINDGEN_VERSION}") + if (NOT (WIT_BINDGEN_VERSION MATCHES "0\\.51\\.0")) + message(WARNING "wit-bindgen version 0.51.0 is required, found: ${WIT_BINDGEN_VERSION}") set(WIT_BINDGEN_EXECUTABLE "") endif() endif() @@ -26,7 +26,7 @@ if (NOT WIT_BINDGEN_EXECUTABLE) ba_download( wit-bindgen "https://github.com/bytecodealliance/wit-bindgen" - "0.50.0" + "0.51.0" ) ExternalProject_Get_Property(wit-bindgen SOURCE_DIR) set(wit_bindgen "${SOURCE_DIR}/wit-bindgen") diff --git a/libc-bottom-half/crt/crt1-reactor.c b/libc-bottom-half/crt/crt1-reactor.c index 86cab13cb..bd693245e 100644 --- a/libc-bottom-half/crt/crt1-reactor.c +++ b/libc-bottom-half/crt/crt1-reactor.c @@ -1,7 +1,6 @@ #if defined(_REENTRANT) #include #endif - extern void __wasi_init_tp(void); extern void __wasm_call_ctors(void); diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip2.h b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h index eb8f16ba3..a533e789f 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip2.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.50.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! #ifndef __BINDINGS_WASIP2_H #define __BINDINGS_WASIP2_H #ifdef __cplusplus diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h index 78128912d..dafe21bce 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.50.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! #ifndef __BINDINGS_WASIP3_H #define __BINDINGS_WASIP3_H #ifdef __cplusplus @@ -75,10 +75,9 @@ typedef enum wasip3_waitable_state { void wasip3_backpressure_inc(void); void wasip3_backpressure_dec(void); -void* wasip3_context_get(void); -void wasip3_context_set(void*); -void wasip3_yield(void); -uint32_t wasip3_yield_cancellable(void); +void* wasip3_context_get_0(void); +void wasip3_context_set_0(void* value); +void wasip3_thread_yield(void); diff --git a/libc-bottom-half/sources/wasip2.c b/libc-bottom-half/sources/wasip2.c index 7305c9c1c..06c555ae5 100644 --- a/libc-bottom-half/sources/wasip2.c +++ b/libc-bottom-half/sources/wasip2.c @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.50.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! #include "wasi/wasip2.h" #include #include diff --git a/libc-bottom-half/sources/wasip2_component_type.o b/libc-bottom-half/sources/wasip2_component_type.o index c0070fcf99549d4ba9185572701e5764a007ac02..abbd242946ebf1c4c3b4933cb92293b05f6a0461 100644 GIT binary patch delta 34 pcmcZ?axY{9x0aZRo&j%pW{GZ6W?o8qYMyQ~n}MFG;bcWETL99M3d{fi delta 34 pcmcZ?axY{9x0aZ(o&j%pW{GZ6W?o8qYMyQ~n}MFG!DK}(TL98?3d#Tg diff --git a/libc-bottom-half/sources/wasip3.c b/libc-bottom-half/sources/wasip3.c index 3194a1149..06efdb249 100644 --- a/libc-bottom-half/sources/wasip3.c +++ b/libc-bottom-half/sources/wasip3.c @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.50.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! #include "wasi/wasip3.h" #include #include @@ -1120,33 +1120,27 @@ void wasip3_backpressure_dec(void) { } __attribute__((__import_module__("$root"), __import_name__("[context-get-0]"))) -extern void* __context_get(void); +extern void* __context_get_0(void); -void* wasip3_context_get() { - return __context_get(); +void* wasip3_context_get_0(void) { + return __context_get_0(); } __attribute__((__import_module__("$root"), __import_name__("[context-set-0]"))) -extern void __context_set(void*); +extern void __context_set_0(void*); -void wasip3_context_set(void *val) { - return __context_set(val); + +void wasip3_context_set_0(void *value) { + __context_set_0(value); } __attribute__((__import_module__("$root"), __import_name__("[thread-yield]"))) extern uint32_t __thread_yield(void); -void wasip3_yield(void) { +void wasip3_thread_yield(void) { __thread_yield(); } -__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-yield]"))) -extern uint32_t __thread_yield_cancellable(void); - -uint32_t wasip3_yield_cancellable(void) { - return __thread_yield_cancellable(); -} - // Component Adapters diff --git a/libc-bottom-half/sources/wasip3_component_type.o b/libc-bottom-half/sources/wasip3_component_type.o index d30145e7b9e236c6703af6fc362b569e8a842148..1bbc77162df643e996ee21d74433728d8365bc09 100644 GIT binary patch delta 34 pcmbPZKgWK9r@WYno&j%pW{GZ6W?o8qYMyQ~n}MFG;pBLETL8ku3WNXv delta 34 pcmbPZKgWK9r@WZ4o&j%pW{GZ6W?o8qYMyQ~n}MFG!Q^;(TL8kP3W5Lt From 6457a9e1bdeb7f59f711cd974aca9a9a84118dd7 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Tue, 13 Jan 2026 16:51:59 +0000 Subject: [PATCH 14/41] Update bindings --- cmake/bindings.cmake | 1 + .../headers/public/wasi/__generated_wasip3.h | 14 +++ libc-bottom-half/sources/wasip3.c | 85 +++++++++++++++++++ 3 files changed, 100 insertions(+) diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index d5ef6267b..73aa0b419 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -107,6 +107,7 @@ add_custom_target( bindings-p3 COMMAND ${wit_bindgen} c + --generate-threading-helpers --autodrop-borrows yes --rename-world wasip3 --type-section-suffix __wasi_libc diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h index dafe21bce..76d736d68 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h @@ -80,6 +80,20 @@ void wasip3_context_set_0(void* value); void wasip3_thread_yield(void); +void* wasip3_context_get_1(void); +void wasip3_context_set_1(void* value); +uint32_t wasip3_thread_yield_cancellable(void); +uint32_t wasip3_thread_index(void); +uint32_t wasip3_thread_new_indirect(void (*start_function)(void*), void* arg); +void wasip3_thread_switch_to(uint32_t thread); +uint32_t wasip3_thread_switch_to_cancellable(uint32_t thread); +void wasip3_thread_resume_later(uint32_t thread); +void wasip3_thread_yield_to(uint32_t thread); +uint32_t wasip3_thread_yield_to_cancellable(uint32_t thread); +void wasip3_thread_suspend(void); +uint32_t wasip3_thread_suspend_cancellable(void); + + typedef struct { wasip3_string_t f0; diff --git a/libc-bottom-half/sources/wasip3.c b/libc-bottom-half/sources/wasip3.c index 06efdb249..5c8978312 100644 --- a/libc-bottom-half/sources/wasip3.c +++ b/libc-bottom-half/sources/wasip3.c @@ -1142,6 +1142,91 @@ void wasip3_thread_yield(void) { } +__attribute__((__import_module__("$root"), __import_name__("[context-get-1]"))) +extern void* __context_get_1(void); + +void* wasip3_context_get_1(void) { + return __context_get_1(); +} + +__attribute__((__import_module__("$root"), __import_name__("[context-set-1]"))) +extern void __context_set_1(void*); + +void wasip3_context_set_1(void* value) { + __context_set_1(value); +} + +__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-yield]"))) +extern uint32_t __thread_yield_cancellable(void); + +uint32_t wasip3_thread_yield_cancellable(void) { + return __thread_yield_cancellable(); +} + +__attribute__((__import_module__("$root"), __import_name__("[thread-index]"))) +extern uint32_t __thread_index(void); + +uint32_t wasip3_thread_index(void) { + return __thread_index(); +} + +__attribute__((__import_module__("$root"), __import_name__("[thread-new-indirect-v0]"))) +extern uint32_t __thread_new_indirect(uint32_t, void*); + +uint32_t wasip3_thread_new_indirect(void (*start_function)(void*), void* arg) { + return __thread_new_indirect((uint32_t)(uintptr_t)start_function, arg + ); +} + +__attribute__((__import_module__("$root"), __import_name__("[thread-switch-to]"))) +extern uint32_t __thread_switch_to(uint32_t); + +void wasip3_thread_switch_to(uint32_t thread) { + __thread_switch_to(thread); +} + +__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-switch-to]"))) +extern uint32_t __thread_switch_to_cancellable(uint32_t); + +uint32_t wasip3_thread_switch_to_cancellable(uint32_t thread) { + return __thread_switch_to_cancellable(thread); +} + +__attribute__((__import_module__("$root"), __import_name__("[thread-resume-later]"))) +extern void __thread_resume_later(uint32_t); + +void wasip3_thread_resume_later(uint32_t thread) { + __thread_resume_later(thread); +} + +__attribute__((__import_module__("$root"), __import_name__("[thread-yield-to]"))) +extern uint32_t __thread_yield_to(uint32_t); + +void wasip3_thread_yield_to(uint32_t thread) { + __thread_yield_to(thread); +} + +__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-yield-to]"))) +extern uint32_t __thread_yield_to_cancellable(uint32_t); + +uint32_t wasip3_thread_yield_to_cancellable(uint32_t thread) { + return __thread_yield_to_cancellable(thread); +} + +__attribute__((__import_module__("$root"), __import_name__("[thread-suspend]"))) +extern uint32_t __thread_suspend(void); + +void wasip3_thread_suspend(void) { + __thread_suspend(); +} + +__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-suspend]"))) +extern uint32_t __thread_suspend_cancellable(void); +uint32_t wasip3_thread_suspend_cancellable(void) { + return __thread_suspend_cancellable(); +} + + // Component Adapters From 7156e73feafe0172a754c5e2b6f793a5a9b01c60 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Tue, 13 Jan 2026 16:52:41 +0000 Subject: [PATCH 15/41] Remove unecessary changes --- libc-bottom-half/sources/__main_void.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/libc-bottom-half/sources/__main_void.c b/libc-bottom-half/sources/__main_void.c index c890bcc6e..880d06233 100644 --- a/libc-bottom-half/sources/__main_void.c +++ b/libc-bottom-half/sources/__main_void.c @@ -23,8 +23,7 @@ __attribute__((__weak__)) int __main_argc_argv(int argc, char *argv[]); // as necessary by the Clang driver. However, moving it to crt1-command.c // breaks `--no-gc-sections`, so we'll probably need to create a new file // (e.g. crt0.o or crtend.o) and teach Clang to use it when needed. -__attribute__((__weak__, nodebug)) int __main_void(void) -{ +__attribute__((__weak__, nodebug)) int __main_void(void) { #if defined(__wasip1__) __wasi_errno_t err; @@ -32,30 +31,26 @@ __attribute__((__weak__, nodebug)) int __main_void(void) size_t argv_buf_size; size_t argc; err = __wasi_args_sizes_get(&argc, &argv_buf_size); - if (err != __WASI_ERRNO_SUCCESS) - { + if (err != __WASI_ERRNO_SUCCESS) { _Exit(EX_OSERR); } // Add 1 for the NULL pointer to mark the end, and check for overflow. size_t num_ptrs = argc + 1; - if (num_ptrs == 0) - { + if (num_ptrs == 0) { _Exit(EX_SOFTWARE); } // Allocate memory for storing the argument chars. char *argv_buf = malloc(argv_buf_size); - if (argv_buf == NULL) - { + if (argv_buf == NULL) { _Exit(EX_SOFTWARE); } // Allocate memory for the array of pointers. This uses `calloc` both to // handle overflow and to initialize the NULL pointer at the end. char **argv = calloc(num_ptrs, sizeof(char *)); - if (argv == NULL) - { + if (argv == NULL) { free(argv_buf); _Exit(EX_SOFTWARE); } @@ -64,8 +59,7 @@ __attribute__((__weak__, nodebug)) int __main_void(void) // TODO: Remove the casts on `argv_ptrs` and `argv_buf` once the witx is // updated with char8 support. err = __wasi_args_get((uint8_t **)argv, (uint8_t *)argv_buf); - if (err != __WASI_ERRNO_SUCCESS) - { + if (err != __WASI_ERRNO_SUCCESS) { free(argv_buf); free(argv); _Exit(EX_OSERR); @@ -127,9 +121,8 @@ __attribute__((__weak__, nodebug)) int __main_void(void) #endif } -#if defined(__wasip2__) || defined(__wasip3__) -bool exports_wasi_cli_run_run(void) -{ +#ifdef __wasip2__ +bool exports_wasi_cli_run_run(void) { // TODO: this is supposed to be unnecessary, but functional/env.c fails // without it __wasilibc_initialize_environ(); From f26cfb5916c58becebec6e038d98559791c41e91 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Tue, 13 Jan 2026 16:57:07 +0000 Subject: [PATCH 16/41] Formatting --- libc-top-half/musl/src/env/__init_tls.c | 65 ++++++++++--------------- 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/libc-top-half/musl/src/env/__init_tls.c b/libc-top-half/musl/src/env/__init_tls.c index c1bd8f9e7..04d136b7a 100644 --- a/libc-top-half/musl/src/env/__init_tls.c +++ b/libc-top-half/musl/src/env/__init_tls.c @@ -36,14 +36,12 @@ extern unsigned char __global_base; extern weak unsigned char __stack_high; extern weak unsigned char __stack_low; -struct stack_bounds -{ +struct stack_bounds { void *base; size_t size; }; -static inline unsigned char *get_stack_pointer() -{ +static inline unsigned char *get_stack_pointer() { unsigned char *sp; #ifdef __wasip3__ __asm__( @@ -67,25 +65,21 @@ static inline struct stack_bounds get_stack_bounds() { struct stack_bounds bounds; - if (&__stack_high) - { + if (&__stack_high) { bounds.base = &__stack_high; bounds.size = &__stack_high - &__stack_low; } - else - { + else { /* For non-pic, make a guess using the knowledge about * how wasm-ld lays out things. For pic, just give up. */ #if !defined(__pic__) unsigned char *sp = get_stack_pointer(); - if (sp > &__global_base) - { + if (sp > &__global_base) { bounds.base = &__heap_base; bounds.size = &__heap_base - &__data_end; } - else - { + else { bounds.base = &__global_base; bounds.size = (size_t)&__global_base; } @@ -98,28 +92,25 @@ static inline struct stack_bounds get_stack_bounds() return bounds; } -void __wasi_init_tp() -{ +void __wasi_init_tp() { __init_tp((void *)__get_tp()); } #endif -int __init_tp(void *p) -{ +int __init_tp(void *p) { pthread_t td = p; td->self = td; #ifdef __wasilibc_unmodified_upstream int r = __set_thread_area(TP_ADJ(p)); - if (r < 0) - return -1; - if (!r) - libc.can_do_threads = 1; + if (r < 0) return -1; + if (!r) libc.can_do_threads = 1; td->detach_state = DT_JOINABLE; td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock); #else struct stack_bounds bounds = get_stack_bounds(); __default_stacksize = - bounds.size < DEFAULT_STACK_MAX ? bounds.size : DEFAULT_STACK_MAX; + bounds.size < DEFAULT_STACK_MAX ? + bounds.size : DEFAULT_STACK_MAX; td->stack = bounds.base; td->stack_size = bounds.size; td->guard_size = 0; @@ -149,8 +140,7 @@ int __init_tp(void *p) #ifdef __wasilibc_unmodified_upstream -static struct builtin_tls -{ +static struct builtin_tls { char c; struct pthread pt; void *space[16]; @@ -161,7 +151,7 @@ static struct tls_module main_tls; #endif #ifndef __wasilibc_unmodified_upstream -extern void __wasm_init_tls(void *); +extern void __wasm_init_tls(void*); #endif #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) @@ -174,14 +164,13 @@ void *__copy_tls(unsigned char *mem) uintptr_t *dtv; #ifdef TLS_ABOVE_TP - dtv = (uintptr_t *)(mem + libc.tls_size) - (libc.tls_cnt + 1); + dtv = (uintptr_t*)(mem + libc.tls_size) - (libc.tls_cnt + 1); - mem += -((uintptr_t)mem + sizeof(struct pthread)) & (libc.tls_align - 1); + mem += -((uintptr_t)mem + sizeof(struct pthread)) & (libc.tls_align-1); td = (pthread_t)mem; mem += sizeof(struct pthread); - for (i = 1, p = libc.tls_head; p; i++, p = p->next) - { + for (i = 1, p = libc.tls_head; p; i++, p = p->next) { dtv[i] = (uintptr_t)(mem + p->offset) + DTP_OFFSET; memcpy(mem + p->offset, p->image, p->len); } @@ -189,11 +178,10 @@ void *__copy_tls(unsigned char *mem) dtv = (uintptr_t *)mem; mem += libc.tls_size - sizeof(struct pthread); - mem -= (uintptr_t)mem & (libc.tls_align - 1); + mem -= (uintptr_t)mem & (libc.tls_align-1); td = (pthread_t)mem; - for (i = 1, p = libc.tls_head; p; i++, p = p->next) - { + for (i = 1, p = libc.tls_head; p; i++, p = p->next) { dtv[i] = (uintptr_t)(mem - p->offset) + DTP_OFFSET; memcpy(mem - p->offset, p->image, p->len); } @@ -204,12 +192,13 @@ void *__copy_tls(unsigned char *mem) #else size_t tls_align = __builtin_wasm_tls_align(); mem += tls_align; - mem -= (uintptr_t)mem & (tls_align - 1); + mem -= (uintptr_t)mem & (tls_align-1); __wasm_init_tls(mem); #ifndef __wasip3__ volatile void *tls_base = __builtin_wasm_tls_base(); __asm__("local.get %0\n" - "global.set __tls_base\n" ::"r"(tls_base)); + "global.set __tls_base\n" + ::"r"(tls_base)); #endif return mem; #endif @@ -229,7 +218,7 @@ static void static_init_tls(size_t *aux) { unsigned char *p; size_t n; - Phdr *phdr, *tls_phdr = 0; + Phdr *phdr, *tls_phdr=0; size_t base = 0; void *mem; @@ -243,13 +232,13 @@ static void static_init_tls(size_t *aux) if (phdr->p_type == PT_TLS) tls_phdr = phdr; if (phdr->p_type == PT_GNU_STACK && - phdr->p_memsz > __default_stacksize) + phdr->p_memsz > __default_stacksize) __default_stacksize = - phdr->p_memsz < DEFAULT_STACK_MAX ? phdr->p_memsz : DEFAULT_STACK_MAX; + phdr->p_memsz < DEFAULT_STACK_MAX ? + phdr->p_memsz : DEFAULT_STACK_MAX; } - if (tls_phdr) - { + if (tls_phdr) { main_tls.image = (void *)(base + tls_phdr->p_vaddr); main_tls.len = tls_phdr->p_filesz; main_tls.size = tls_phdr->p_memsz; From 08bfd944406a5783e1945b7aad5126eec6267b1e Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Tue, 13 Jan 2026 17:00:57 +0000 Subject: [PATCH 17/41] Formatting --- libc-bottom-half/sources/abort.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libc-bottom-half/sources/abort.c b/libc-bottom-half/sources/abort.c index 4e58f5af7..9db9e1bbd 100644 --- a/libc-bottom-half/sources/abort.c +++ b/libc-bottom-half/sources/abort.c @@ -1,7 +1,6 @@ #include -void abort(void) -{ +void abort(void) { // wasm doesn't support signals, so just trap to halt the program. __builtin_trap(); } From 669b118619c08c227bd6f3ff7ad4b6ceae57efd8 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Tue, 13 Jan 2026 17:02:40 +0000 Subject: [PATCH 18/41] Formatting --- libc-top-half/musl/src/env/__init_tls.c | 48 ++++++++++++------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/libc-top-half/musl/src/env/__init_tls.c b/libc-top-half/musl/src/env/__init_tls.c index 04d136b7a..b4cc97b6f 100644 --- a/libc-top-half/musl/src/env/__init_tls.c +++ b/libc-top-half/musl/src/env/__init_tls.c @@ -68,8 +68,7 @@ static inline struct stack_bounds get_stack_bounds() if (&__stack_high) { bounds.base = &__stack_high; bounds.size = &__stack_high - &__stack_low; - } - else { + } else { /* For non-pic, make a guess using the knowledge about * how wasm-ld lays out things. For pic, just give up. */ @@ -78,8 +77,7 @@ static inline struct stack_bounds get_stack_bounds() if (sp > &__global_base) { bounds.base = &__heap_base; bounds.size = &__heap_base - &__data_end; - } - else { + } else { bounds.base = &__global_base; bounds.size = (size_t)&__global_base; } @@ -97,7 +95,8 @@ void __wasi_init_tp() { } #endif -int __init_tp(void *p) { +int __init_tp(void *p) +{ pthread_t td = p; td->self = td; #ifdef __wasilibc_unmodified_upstream @@ -109,7 +108,7 @@ int __init_tp(void *p) { #else struct stack_bounds bounds = get_stack_bounds(); __default_stacksize = - bounds.size < DEFAULT_STACK_MAX ? + bounds.size < DEFAULT_STACK_MAX ? bounds.size : DEFAULT_STACK_MAX; td->stack = bounds.base; td->stack_size = bounds.size; @@ -170,7 +169,7 @@ void *__copy_tls(unsigned char *mem) td = (pthread_t)mem; mem += sizeof(struct pthread); - for (i = 1, p = libc.tls_head; p; i++, p = p->next) { + for (i=1, p=libc.tls_head; p; i++, p=p->next) { dtv[i] = (uintptr_t)(mem + p->offset) + DTP_OFFSET; memcpy(mem + p->offset, p->image, p->len); } @@ -181,7 +180,7 @@ void *__copy_tls(unsigned char *mem) mem -= (uintptr_t)mem & (libc.tls_align-1); td = (pthread_t)mem; - for (i = 1, p = libc.tls_head; p; i++, p = p->next) { + for (i=1, p=libc.tls_head; p; i++, p=p->next) { dtv[i] = (uintptr_t)(mem - p->offset) + DTP_OFFSET; memcpy(mem - p->offset, p->image, p->len); } @@ -222,8 +221,7 @@ static void static_init_tls(size_t *aux) size_t base = 0; void *mem; - for (p = (void *)aux[AT_PHDR], n = aux[AT_PHNUM]; n; n--, p += aux[AT_PHENT]) - { + for (p = (void *)aux[AT_PHDR], n = aux[AT_PHNUM]; n; n--, p += aux[AT_PHENT]) { phdr = (void *)p; if (phdr->p_type == PT_PHDR) base = aux[AT_PHDR] - phdr->p_vaddr; @@ -234,7 +232,7 @@ static void static_init_tls(size_t *aux) if (phdr->p_type == PT_GNU_STACK && phdr->p_memsz > __default_stacksize) __default_stacksize = - phdr->p_memsz < DEFAULT_STACK_MAX ? + phdr->p_memsz < DEFAULT_STACK_MAX ? phdr->p_memsz : DEFAULT_STACK_MAX; } @@ -247,39 +245,37 @@ static void static_init_tls(size_t *aux) libc.tls_head = &main_tls; } - main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image) & (main_tls.align - 1); + main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image) + & (main_tls.align - 1); #ifdef TLS_ABOVE_TP main_tls.offset = GAP_ABOVE_TP; - main_tls.offset += (-GAP_ABOVE_TP + (uintptr_t)main_tls.image) & (main_tls.align - 1); + main_tls.offset += (-GAP_ABOVE_TP + (uintptr_t)main_tls.image) + & (main_tls.align - 1); #else main_tls.offset = main_tls.size; #endif - if (main_tls.align < MIN_TLS_ALIGN) - main_tls.align = MIN_TLS_ALIGN; + if (main_tls.align < MIN_TLS_ALIGN) main_tls.align = MIN_TLS_ALIGN; libc.tls_align = main_tls.align; - libc.tls_size = 2 * sizeof(void *) + sizeof(struct pthread) + libc.tls_size = 2*sizeof(void *) + sizeof(struct pthread) #ifdef TLS_ABOVE_TP - + main_tls.offset + + main_tls.offset #endif - + main_tls.size + main_tls.align + MIN_TLS_ALIGN - 1 & - -MIN_TLS_ALIGN; + + main_tls.size + main_tls.align + + MIN_TLS_ALIGN - 1 & -MIN_TLS_ALIGN; - if (libc.tls_size > sizeof builtin_tls) - { + if (libc.tls_size > sizeof builtin_tls) { #ifndef SYS_mmap2 #define SYS_mmap2 SYS_mmap #endif mem = (void *)__syscall( SYS_mmap2, - 0, libc.tls_size, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); + 0, libc.tls_size, PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); /* -4095...-1 cast to void * will crash on dereference anyway, * so don't bloat the init code checking for error codes and * explicitly calling a_crash(). */ - } - else - { + } else { mem = builtin_tls; } From f66008a8b2a769d33f29dda6e1b4659a47b5e90c Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Tue, 13 Jan 2026 17:04:14 +0000 Subject: [PATCH 19/41] Formatting --- libc-top-half/musl/src/env/__init_tls.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libc-top-half/musl/src/env/__init_tls.c b/libc-top-half/musl/src/env/__init_tls.c index b4cc97b6f..a17d8fc2a 100644 --- a/libc-top-half/musl/src/env/__init_tls.c +++ b/libc-top-half/musl/src/env/__init_tls.c @@ -95,7 +95,7 @@ void __wasi_init_tp() { } #endif -int __init_tp(void *p) +int __init_tp(void *p) { pthread_t td = p; td->self = td; @@ -221,7 +221,7 @@ static void static_init_tls(size_t *aux) size_t base = 0; void *mem; - for (p = (void *)aux[AT_PHDR], n = aux[AT_PHNUM]; n; n--, p += aux[AT_PHENT]) { + for (p=(void *)aux[AT_PHDR], n=aux[AT_PHNUM]; n; n--, p+=aux[AT_PHENT]) { phdr = (void *)p; if (phdr->p_type == PT_PHDR) base = aux[AT_PHDR] - phdr->p_vaddr; @@ -246,11 +246,11 @@ static void static_init_tls(size_t *aux) } main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image) - & (main_tls.align - 1); + & (main_tls.align-1); #ifdef TLS_ABOVE_TP main_tls.offset = GAP_ABOVE_TP; main_tls.offset += (-GAP_ABOVE_TP + (uintptr_t)main_tls.image) - & (main_tls.align - 1); + & (main_tls.align-1); #else main_tls.offset = main_tls.size; #endif @@ -262,7 +262,7 @@ static void static_init_tls(size_t *aux) + main_tls.offset #endif + main_tls.size + main_tls.align - + MIN_TLS_ALIGN - 1 & -MIN_TLS_ALIGN; + + MIN_TLS_ALIGN-1 & -MIN_TLS_ALIGN; if (libc.tls_size > sizeof builtin_tls) { #ifndef SYS_mmap2 From a8c5c347d8b2d92159d5e5764d403b9065e3abd8 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Tue, 13 Jan 2026 17:05:23 +0000 Subject: [PATCH 20/41] Formatting --- libc-top-half/musl/src/env/__init_tls.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libc-top-half/musl/src/env/__init_tls.c b/libc-top-half/musl/src/env/__init_tls.c index a17d8fc2a..46c0cfa47 100644 --- a/libc-top-half/musl/src/env/__init_tls.c +++ b/libc-top-half/musl/src/env/__init_tls.c @@ -221,7 +221,7 @@ static void static_init_tls(size_t *aux) size_t base = 0; void *mem; - for (p=(void *)aux[AT_PHDR], n=aux[AT_PHNUM]; n; n--, p+=aux[AT_PHENT]) { + for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) { phdr = (void *)p; if (phdr->p_type == PT_PHDR) base = aux[AT_PHDR] - phdr->p_vaddr; @@ -246,11 +246,11 @@ static void static_init_tls(size_t *aux) } main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image) - & (main_tls.align-1); + & (main_tls.align-1); #ifdef TLS_ABOVE_TP main_tls.offset = GAP_ABOVE_TP; main_tls.offset += (-GAP_ABOVE_TP + (uintptr_t)main_tls.image) - & (main_tls.align-1); + & (main_tls.align-1); #else main_tls.offset = main_tls.size; #endif From e2e89e77d20da5fd4f8e7006e50cf69d05932cfd Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Wed, 14 Jan 2026 16:51:54 +0000 Subject: [PATCH 21/41] Update bindings --- cmake/bindings.cmake | 67 +- libc-bottom-half/CMakeLists.txt | 2 +- libc-bottom-half/cloudlibc/src/common/time.h | 9 +- .../cloudlibc/src/libc/sys/stat/stat_impl.h | 3 + .../src/libc/sys/time/gettimeofday.c | 6 +- .../cloudlibc/src/libc/time/clock_gettime.c | 8 +- .../cloudlibc/src/libc/time/time.c | 8 +- libc-bottom-half/crt/crt1-command.c | 2 +- .../headers/public/wasi/__generated_wasip2.h | 1255 +---------------- .../headers/public/wasi/__generated_wasip3.h | 105 +- libc-bottom-half/sources/wasip2.c | 72 +- libc-bottom-half/sources/wasip3.c | 368 +++-- .../sources/wasip3_component_type.o | Bin 8092 -> 8099 bytes wasi/wasi-libc-wasip2.wit | 5 + wasi/wasi-libc-wasip3.wit | 10 + 15 files changed, 376 insertions(+), 1544 deletions(-) create mode 100644 wasi/wasi-libc-wasip2.wit create mode 100644 wasi/wasi-libc-wasip3.wit diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index 73aa0b419..71a641e4b 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -35,20 +35,48 @@ else() set(wit_bindgen ${WIT_BINDGEN_EXECUTABLE}) endif() -include(ExternalProject) +# If `wkg` is on the system and has the right version, favor that, +# otherwise download a known good version. +find_program(WKG_EXECUTABLE NAMES wkg) +if(WKG_EXECUTABLE) + message(STATUS "Found wkg: ${WKG_EXECUTABLE}") + + execute_process( + COMMAND ${WKG_EXECUTABLE} --version + OUTPUT_VARIABLE WKG_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (NOT (WKG_VERSION MATCHES "0\\.13\\.0")) + message(WARNING "wkg version 0.13.0 is required, found: ${WKG_VERSION}") + set(WKG_EXECUTABLE "") + endif() +endif() + +if (NOT WKG_EXECUTABLE) + include(ba-download) + ba_download( + wit-bindgen + "https://github.com/bytecodealliance/wasm-pkg-tools" + "0.13.0" + ) + ExternalProject_Get_Property(wkg SOURCE_DIR) + set(wkg "${SOURCE_DIR}/wkg") +else() + add_custom_target(wkg) + set(wkg ${WKG_EXECUTABLE}) +endif() + +set(bottom_half "${CMAKE_SOURCE_DIR}/libc-bottom-half") + +set(wasip2_wit_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi/p2/wit) set(p2 0.2.0) -ExternalProject_Add( +file(MAKE_DIRECTORY ${wasip2_wit_dir}) +configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip2.wit ${wasip2_wit_dir} COPYONLY) +add_custom_target( wasip2-wits - URL https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v${p2}.tar.gz - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - EXCLUDE_FROM_ALL TRUE + COMMAND ${wkg} wit fetch + WORKING_DIRECTORY ${wasip2_wit_dir}/.. ) -ExternalProject_Get_Property(wasip2-wits SOURCE_DIR) -set(wasip2_wit_dir ${SOURCE_DIR}/wit) -set(bottom_half "${CMAKE_SOURCE_DIR}/libc-bottom-half") - add_custom_target( bindings-p2 COMMAND @@ -91,18 +119,15 @@ add_custom_target( DEPENDS wit-bindgen wasip2-wits ) -set(p3 0.3.0-rc-2025-09-16) -ExternalProject_Add( +set(wasip3_wit_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi/p3/wit) +set(p3 0.3.0-rc-2026-01-06) +file(MAKE_DIRECTORY ${wasip3_wit_dir}) +configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip3.wit ${wasip3_wit_dir} COPYONLY) +add_custom_target( wasip3-wits - URL https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v${p3}.tar.gz - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - EXCLUDE_FROM_ALL TRUE + COMMAND ${wkg} wit fetch + WORKING_DIRECTORY ${wasip3_wit_dir}/.. ) -ExternalProject_Get_Property(wasip3-wits SOURCE_DIR) -set(wasip3_wit_dir ${SOURCE_DIR}/wit-0.3.0-draft) - add_custom_target( bindings-p3 COMMAND diff --git a/libc-bottom-half/CMakeLists.txt b/libc-bottom-half/CMakeLists.txt index 54986c0cb..8802409a2 100644 --- a/libc-bottom-half/CMakeLists.txt +++ b/libc-bottom-half/CMakeLists.txt @@ -249,7 +249,7 @@ elseif (WASI STREQUAL "p3") ${wasm_tools} component embed ${wasip3_wit_dir} $ - --world wasi:cli/command@0.3.0-rc-2025-09-16 + --world wasi:cli/command@0.3.0-rc-2026-01-06 -o ${SYSROOT_LIB}/crt1-command.o DEPENDS crt1-command wasip3-wits $ wasm-tools ) diff --git a/libc-bottom-half/cloudlibc/src/common/time.h b/libc-bottom-half/cloudlibc/src/common/time.h index ece306e5a..9c5ae4877 100644 --- a/libc-bottom-half/cloudlibc/src/common/time.h +++ b/libc-bottom-half/cloudlibc/src/common/time.h @@ -18,8 +18,11 @@ #if defined(__wasip1__) typedef __wasi_timestamp_t wasilibc_timestamp_t; -#elif defined(__wasip2__) || defined(__wasip3__) +#elif defined(__wasip2__) typedef wall_clock_datetime_t wasilibc_timestamp_t; +#elif defined(__wasip3__) +typedef filesystem_instant_t wasilibc_timestamp_t; +typedef monotonic_clock_mark_t monotonic_clock_instant_t; #else # error "Unknown WASI version" #endif @@ -95,7 +98,7 @@ static inline struct timeval timestamp_to_timeval( #elif defined(__wasip2__) || defined(__wasip3__) static inline struct timespec timestamp_to_timespec( - wall_clock_datetime_t *timestamp) { + wasilibc_timestamp_t *timestamp) { return (struct timespec){.tv_sec = timestamp->seconds, .tv_nsec = timestamp->nanoseconds}; } @@ -155,7 +158,7 @@ static inline bool timeval_to_duration( } static inline struct timeval timestamp_to_timeval( - wall_clock_datetime_t *timestamp) { + wasilibc_timestamp_t *timestamp) { return (struct timeval){.tv_sec = timestamp->seconds, .tv_usec = timestamp->nanoseconds / 1000}; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h b/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h index 504b6ba7e..807eab164 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h @@ -66,6 +66,9 @@ static inline void to_public_stat(const __wasi_filestat_t *in, } } #elif defined(__wasip2__) || defined(__wasip3__) +#ifdef __wasip3__ +typedef filesystem_instant_t filesystem_datetime_t; +#endif static inline void to_public_stat(const filesystem_metadata_hash_value_t *metadata, const filesystem_descriptor_stat_t *in, struct stat *out) { diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c b/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c index 08592fe92..3c27aa93a 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c @@ -12,10 +12,14 @@ int gettimeofday(struct timeval *restrict tp, void *tz) { __wasi_timestamp_t ts = 0; (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts); *tp = timestamp_to_timeval(ts); -#elif defined(__wasip2__) || defined(__wasip3__) +#elif defined(__wasip2__) wall_clock_datetime_t time_result; wall_clock_now(&time_result); *tp = timestamp_to_timeval(&time_result); +#elif defined(__wasip3__) + wasi_clocks_system_clock_instant_t time_result; + wasi_clocks_system_clock_now(&time_result); + *tp = timestamp_to_timeval(&time_result); #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c b/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c index 4619c169e..ae8eef0fe 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c @@ -25,12 +25,16 @@ int __clock_gettime(clockid_t clock_id, struct timespec *tp) { monotonic_clock_instant_t ns = monotonic_clock_now(); *tp = instant_to_timespec(ns); } else if (clock_id == CLOCK_REALTIME) { - wall_clock_datetime_t time_result; + wasilibc_timestamp_t time_result; + #ifdef __wasip2__ wall_clock_now(&time_result); + #else + wasi_clocks_system_clock_now(&time_result); + #endif *tp = timestamp_to_timespec(&time_result); } else { errno = EINVAL; - return -1; // wasip2 only supports wall and monotonic clocks + return -1; // wasip{2,3} only supports wall and monotonic clocks } #else # error "Unsupported WASI version" diff --git a/libc-bottom-half/cloudlibc/src/libc/time/time.c b/libc-bottom-half/cloudlibc/src/libc/time/time.c index 96c09b35a..d3fceb5c2 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/time.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/time.c @@ -10,10 +10,14 @@ time_t time(time_t *tloc) { #if defined(__wasip1__) __wasi_timestamp_t ts = 0; (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, NSEC_PER_SEC, &ts); -#elif defined(__wasip2__) || defined(__wasip3__) - wall_clock_datetime_t res; +#elif defined(__wasip2__) + wasilibc_timestamp_t res; wall_clock_now(&res); uint64_t ts = (res.seconds * NSEC_PER_SEC) + res.nanoseconds; +#elif defined(__wasip3__) + wasilibc_timestamp_t res; + wasi_clocks_system_clock_now(&res); + uint64_t ts = (res.seconds * NSEC_PER_SEC) + res.nanoseconds; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/crt/crt1-command.c b/libc-bottom-half/crt/crt1-command.c index 63e556779..6ef297592 100644 --- a/libc-bottom-half/crt/crt1-command.c +++ b/libc-bottom-half/crt/crt1-command.c @@ -18,7 +18,7 @@ __attribute__((export_name("_start"))) void _start(void) // that this shouldn't be too problematic (in theory). __attribute__((export_name("wasi:cli/run@0.2.0#run"))) int _start(void) #elif defined(__wasip3__) -__attribute__((export_name("wasi:cli/run@0.3.0-rc-2025-09-16#run"))) int +__attribute__((export_name("wasi:cli/run@0.3.0-rc-2026-01-06#run"))) int _start(void) #else #error "Unsupported WASI version" diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip2.h b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h index a533e789f..ffd7e86f7 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip2.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h @@ -66,7 +66,6 @@ typedef struct { typedef io_error_own_error_t streams_own_error_t; -// An error for input-stream and output-stream operations. typedef struct streams_stream_error_t { uint8_t tag; union { @@ -74,13 +73,7 @@ typedef struct streams_stream_error_t { } val; } streams_stream_error_t; -// The last operation (a write or flush) failed before completion. -// -// More information is available in the `error` payload. #define STREAMS_STREAM_ERROR_LAST_OPERATION_FAILED 0 -// The stream is closed: no more input will be accepted by the -// stream. A closed output-stream will return this error on all -// future operations. #define STREAMS_STREAM_ERROR_CLOSED 1 typedef struct streams_own_input_stream_t { @@ -172,17 +165,12 @@ typedef struct { terminal_stderr_own_terminal_output_t val; } terminal_stderr_option_own_terminal_output_t; -// An instant in time, in nanoseconds. An instant is relative to an -// unspecified initial value, and can only be compared to instances from -// the same monotonic-clock. typedef uint64_t monotonic_clock_instant_t; -// A duration of time, in nanoseconds. typedef uint64_t monotonic_clock_duration_t; typedef poll_own_pollable_t monotonic_clock_own_pollable_t; -// A time and date in seconds plus nanoseconds. typedef struct wall_clock_datetime_t { uint64_t seconds; uint32_t nanoseconds; @@ -190,95 +178,39 @@ typedef struct wall_clock_datetime_t { typedef wall_clock_datetime_t filesystem_datetime_t; -// File size or length of a region within a file. typedef uint64_t filesystem_filesize_t; -// The type of a filesystem object referenced by a descriptor. -// -// Note: This was called `filetype` in earlier versions of WASI. typedef uint8_t filesystem_descriptor_type_t; -// The type of the descriptor or file is unknown or is different from -// any of the other types specified. #define FILESYSTEM_DESCRIPTOR_TYPE_UNKNOWN 0 -// The descriptor refers to a block device inode. #define FILESYSTEM_DESCRIPTOR_TYPE_BLOCK_DEVICE 1 -// The descriptor refers to a character device inode. #define FILESYSTEM_DESCRIPTOR_TYPE_CHARACTER_DEVICE 2 -// The descriptor refers to a directory inode. #define FILESYSTEM_DESCRIPTOR_TYPE_DIRECTORY 3 -// The descriptor refers to a named pipe. #define FILESYSTEM_DESCRIPTOR_TYPE_FIFO 4 -// The file refers to a symbolic link inode. #define FILESYSTEM_DESCRIPTOR_TYPE_SYMBOLIC_LINK 5 -// The descriptor refers to a regular file inode. #define FILESYSTEM_DESCRIPTOR_TYPE_REGULAR_FILE 6 -// The descriptor refers to a socket. #define FILESYSTEM_DESCRIPTOR_TYPE_SOCKET 7 -// Descriptor flags. -// -// Note: This was called `fdflags` in earlier versions of WASI. typedef uint8_t filesystem_descriptor_flags_t; -// Read mode: Data can be read. #define FILESYSTEM_DESCRIPTOR_FLAGS_READ (1 << 0) -// Write mode: Data can be written to. #define FILESYSTEM_DESCRIPTOR_FLAGS_WRITE (1 << 1) -// Request that writes be performed according to synchronized I/O file -// integrity completion. The data stored in the file and the file's -// metadata are synchronized. This is similar to `O_SYNC` in POSIX. -// -// The precise semantics of this operation have not yet been defined for -// WASI. At this time, it should be interpreted as a request, and not a -// requirement. #define FILESYSTEM_DESCRIPTOR_FLAGS_FILE_INTEGRITY_SYNC (1 << 2) -// Request that writes be performed according to synchronized I/O data -// integrity completion. Only the data stored in the file is -// synchronized. This is similar to `O_DSYNC` in POSIX. -// -// The precise semantics of this operation have not yet been defined for -// WASI. At this time, it should be interpreted as a request, and not a -// requirement. #define FILESYSTEM_DESCRIPTOR_FLAGS_DATA_INTEGRITY_SYNC (1 << 3) -// Requests that reads be performed at the same level of integrety -// requested for writes. This is similar to `O_RSYNC` in POSIX. -// -// The precise semantics of this operation have not yet been defined for -// WASI. At this time, it should be interpreted as a request, and not a -// requirement. #define FILESYSTEM_DESCRIPTOR_FLAGS_REQUESTED_WRITE_SYNC (1 << 4) -// Mutating directories mode: Directory contents may be mutated. -// -// When this flag is unset on a descriptor, operations using the -// descriptor which would create, rename, delete, modify the data or -// metadata of filesystem objects, or obtain another handle which -// would permit any of those, shall fail with `error-code::read-only` if -// they would otherwise succeed. -// -// This may only be set on directories. #define FILESYSTEM_DESCRIPTOR_FLAGS_MUTATE_DIRECTORY (1 << 5) -// Flags determining the method of how paths are resolved. typedef uint8_t filesystem_path_flags_t; -// As long as the resolved path corresponds to a symbolic link, it is -// expanded. #define FILESYSTEM_PATH_FLAGS_SYMLINK_FOLLOW (1 << 0) -// Open flags used by `open-at`. typedef uint8_t filesystem_open_flags_t; -// Create file if it does not exist, similar to `O_CREAT` in POSIX. #define FILESYSTEM_OPEN_FLAGS_CREATE (1 << 0) -// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. #define FILESYSTEM_OPEN_FLAGS_DIRECTORY (1 << 1) -// Fail if file already exists, similar to `O_EXCL` in POSIX. #define FILESYSTEM_OPEN_FLAGS_EXCLUSIVE (1 << 2) -// Truncate file to size 0, similar to `O_TRUNC` in POSIX. #define FILESYSTEM_OPEN_FLAGS_TRUNCATE (1 << 3) -// Number of hard links to an inode. typedef uint64_t filesystem_link_count_t; typedef struct { @@ -286,35 +218,15 @@ typedef struct { filesystem_datetime_t val; } filesystem_option_datetime_t; -// File attributes. -// -// Note: This was called `filestat` in earlier versions of WASI. typedef struct filesystem_descriptor_stat_t { - // File type. filesystem_descriptor_type_t type; - // Number of hard links to the file. filesystem_link_count_t link_count; - // For regular files, the file size in bytes. For symbolic links, the - // length in bytes of the pathname contained in the symbolic link. filesystem_filesize_t size; - // Last data access timestamp. - // - // If the `option` is none, the platform doesn't maintain an access - // timestamp for this file. filesystem_option_datetime_t data_access_timestamp; - // Last data modification timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // modification timestamp for this file. filesystem_option_datetime_t data_modification_timestamp; - // Last file status-change timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // status-change timestamp for this file. filesystem_option_datetime_t status_change_timestamp; } filesystem_descriptor_stat_t; -// When setting a timestamp, this gives the value to set it to. typedef struct filesystem_new_timestamp_t { uint8_t tag; union { @@ -322,131 +234,66 @@ typedef struct filesystem_new_timestamp_t { } val; } filesystem_new_timestamp_t; -// Leave the timestamp set to its previous value. #define FILESYSTEM_NEW_TIMESTAMP_NO_CHANGE 0 -// Set the timestamp to the current time of the system clock associated -// with the filesystem. #define FILESYSTEM_NEW_TIMESTAMP_NOW 1 -// Set the timestamp to the given value. #define FILESYSTEM_NEW_TIMESTAMP_TIMESTAMP 2 -// A directory entry. typedef struct filesystem_directory_entry_t { - // The type of the file referred to by this directory entry. filesystem_descriptor_type_t type; - // The name of the object. wasip2_string_t name; } filesystem_directory_entry_t; -// Error codes returned by functions, similar to `errno` in POSIX. -// Not all of these error codes are returned by the functions provided by this -// API; some are used in higher-level library layers, and others are provided -// merely for alignment with POSIX. typedef uint8_t filesystem_error_code_t; -// Permission denied, similar to `EACCES` in POSIX. #define FILESYSTEM_ERROR_CODE_ACCESS 0 -// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. #define FILESYSTEM_ERROR_CODE_WOULD_BLOCK 1 -// Connection already in progress, similar to `EALREADY` in POSIX. #define FILESYSTEM_ERROR_CODE_ALREADY 2 -// Bad descriptor, similar to `EBADF` in POSIX. #define FILESYSTEM_ERROR_CODE_BAD_DESCRIPTOR 3 -// Device or resource busy, similar to `EBUSY` in POSIX. #define FILESYSTEM_ERROR_CODE_BUSY 4 -// Resource deadlock would occur, similar to `EDEADLK` in POSIX. #define FILESYSTEM_ERROR_CODE_DEADLOCK 5 -// Storage quota exceeded, similar to `EDQUOT` in POSIX. #define FILESYSTEM_ERROR_CODE_QUOTA 6 -// File exists, similar to `EEXIST` in POSIX. #define FILESYSTEM_ERROR_CODE_EXIST 7 -// File too large, similar to `EFBIG` in POSIX. #define FILESYSTEM_ERROR_CODE_FILE_TOO_LARGE 8 -// Illegal byte sequence, similar to `EILSEQ` in POSIX. #define FILESYSTEM_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE 9 -// Operation in progress, similar to `EINPROGRESS` in POSIX. #define FILESYSTEM_ERROR_CODE_IN_PROGRESS 10 -// Interrupted function, similar to `EINTR` in POSIX. #define FILESYSTEM_ERROR_CODE_INTERRUPTED 11 -// Invalid argument, similar to `EINVAL` in POSIX. #define FILESYSTEM_ERROR_CODE_INVALID 12 -// I/O error, similar to `EIO` in POSIX. #define FILESYSTEM_ERROR_CODE_IO 13 -// Is a directory, similar to `EISDIR` in POSIX. #define FILESYSTEM_ERROR_CODE_IS_DIRECTORY 14 -// Too many levels of symbolic links, similar to `ELOOP` in POSIX. #define FILESYSTEM_ERROR_CODE_LOOP 15 -// Too many links, similar to `EMLINK` in POSIX. #define FILESYSTEM_ERROR_CODE_TOO_MANY_LINKS 16 -// Message too large, similar to `EMSGSIZE` in POSIX. #define FILESYSTEM_ERROR_CODE_MESSAGE_SIZE 17 -// Filename too long, similar to `ENAMETOOLONG` in POSIX. #define FILESYSTEM_ERROR_CODE_NAME_TOO_LONG 18 -// No such device, similar to `ENODEV` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_DEVICE 19 -// No such file or directory, similar to `ENOENT` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_ENTRY 20 -// No locks available, similar to `ENOLCK` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_LOCK 21 -// Not enough space, similar to `ENOMEM` in POSIX. #define FILESYSTEM_ERROR_CODE_INSUFFICIENT_MEMORY 22 -// No space left on device, similar to `ENOSPC` in POSIX. #define FILESYSTEM_ERROR_CODE_INSUFFICIENT_SPACE 23 -// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_DIRECTORY 24 -// Directory not empty, similar to `ENOTEMPTY` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_EMPTY 25 -// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_RECOVERABLE 26 -// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. #define FILESYSTEM_ERROR_CODE_UNSUPPORTED 27 -// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_TTY 28 -// No such device or address, similar to `ENXIO` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_SUCH_DEVICE 29 -// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. #define FILESYSTEM_ERROR_CODE_OVERFLOW 30 -// Operation not permitted, similar to `EPERM` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_PERMITTED 31 -// Broken pipe, similar to `EPIPE` in POSIX. #define FILESYSTEM_ERROR_CODE_PIPE 32 -// Read-only file system, similar to `EROFS` in POSIX. #define FILESYSTEM_ERROR_CODE_READ_ONLY 33 -// Invalid seek, similar to `ESPIPE` in POSIX. #define FILESYSTEM_ERROR_CODE_INVALID_SEEK 34 -// Text file busy, similar to `ETXTBSY` in POSIX. #define FILESYSTEM_ERROR_CODE_TEXT_FILE_BUSY 35 -// Cross-device link, similar to `EXDEV` in POSIX. #define FILESYSTEM_ERROR_CODE_CROSS_DEVICE 36 -// File or memory access pattern advisory information. typedef uint8_t filesystem_advice_t; -// The application has no advice to give on its behavior with respect -// to the specified data. #define FILESYSTEM_ADVICE_NORMAL 0 -// The application expects to access the specified data sequentially -// from lower offsets to higher offsets. #define FILESYSTEM_ADVICE_SEQUENTIAL 1 -// The application expects to access the specified data in a random -// order. #define FILESYSTEM_ADVICE_RANDOM 2 -// The application expects to access the specified data in the near -// future. #define FILESYSTEM_ADVICE_WILL_NEED 3 -// The application expects that it will not access the specified data -// in the near future. #define FILESYSTEM_ADVICE_DONT_NEED 4 -// The application expects to access the specified data once and then -// not reuse it thereafter. #define FILESYSTEM_ADVICE_NO_REUSE 5 -// A 128-bit hash value, split into parts because wasm doesn't have a -// 128-bit integer type. typedef struct filesystem_metadata_hash_value_t { - // 64 bits of a 128-bit hash value. uint64_t lower; - // Another 64 bits of a 128-bit hash value. uint64_t upper; } filesystem_metadata_hash_value_t; @@ -610,85 +457,33 @@ typedef struct network_borrow_network_t { int32_t __handle; } network_borrow_network_t; -// Error codes. -// -// In theory, every API can return any error code. -// In practice, API's typically only return the errors documented per API -// combined with a couple of errors that are always possible: -// - `unknown` -// - `access-denied` -// - `not-supported` -// - `out-of-memory` -// - `concurrency-conflict` -// -// See each individual API for what the POSIX equivalents are. They sometimes differ per API. typedef uint8_t network_error_code_t; -// Unknown error #define NETWORK_ERROR_CODE_UNKNOWN 0 -// Access denied. -// -// POSIX equivalent: EACCES, EPERM #define NETWORK_ERROR_CODE_ACCESS_DENIED 1 -// The operation is not supported. -// -// POSIX equivalent: EOPNOTSUPP #define NETWORK_ERROR_CODE_NOT_SUPPORTED 2 -// One of the arguments is invalid. -// -// POSIX equivalent: EINVAL #define NETWORK_ERROR_CODE_INVALID_ARGUMENT 3 -// Not enough memory to complete the operation. -// -// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY #define NETWORK_ERROR_CODE_OUT_OF_MEMORY 4 -// The operation timed out before it could finish completely. #define NETWORK_ERROR_CODE_TIMEOUT 5 -// This operation is incompatible with another asynchronous operation that is already in progress. -// -// POSIX equivalent: EALREADY #define NETWORK_ERROR_CODE_CONCURRENCY_CONFLICT 6 -// Trying to finish an asynchronous operation that: -// - has not been started yet, or: -// - was already finished by a previous `finish-*` call. -// -// Note: this is scheduled to be removed when `future`s are natively supported. #define NETWORK_ERROR_CODE_NOT_IN_PROGRESS 7 -// The operation has been aborted because it could not be completed immediately. -// -// Note: this is scheduled to be removed when `future`s are natively supported. #define NETWORK_ERROR_CODE_WOULD_BLOCK 8 -// The operation is not valid in the socket's current state. #define NETWORK_ERROR_CODE_INVALID_STATE 9 -// A new socket resource could not be created because of a system limit. #define NETWORK_ERROR_CODE_NEW_SOCKET_LIMIT 10 -// A bind operation failed because the provided address is not an address that the `network` can bind to. #define NETWORK_ERROR_CODE_ADDRESS_NOT_BINDABLE 11 -// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. #define NETWORK_ERROR_CODE_ADDRESS_IN_USE 12 -// The remote address is not reachable #define NETWORK_ERROR_CODE_REMOTE_UNREACHABLE 13 -// The TCP connection was forcefully rejected #define NETWORK_ERROR_CODE_CONNECTION_REFUSED 14 -// The TCP connection was reset. #define NETWORK_ERROR_CODE_CONNECTION_RESET 15 -// A TCP connection was aborted. #define NETWORK_ERROR_CODE_CONNECTION_ABORTED 16 -// The size of a datagram sent to a UDP socket exceeded the maximum -// supported size. #define NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE 17 -// Name does not exist or has no suitable associated IP addresses. #define NETWORK_ERROR_CODE_NAME_UNRESOLVABLE 18 -// A temporary failure in name resolution occurred. #define NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE 19 -// A permanent failure in name resolution occurred. #define NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE 20 typedef uint8_t network_ip_address_family_t; -// Similar to `AF_INET` in POSIX. #define NETWORK_IP_ADDRESS_FAMILY_IPV4 0 -// Similar to `AF_INET6` in POSIX. #define NETWORK_IP_ADDRESS_FAMILY_IPV6 1 typedef struct network_ipv4_address_t { @@ -721,20 +516,14 @@ typedef struct network_ip_address_t { #define NETWORK_IP_ADDRESS_IPV6 1 typedef struct network_ipv4_socket_address_t { - // sin_port uint16_t port; - // sin_addr network_ipv4_address_t address; } network_ipv4_socket_address_t; typedef struct network_ipv6_socket_address_t { - // sin6_port uint16_t port; - // sin6_flowinfo uint32_t flow_info; - // sin6_addr network_ipv6_address_t address; - // sin6_scope_id uint32_t scope_id; } network_ipv6_socket_address_t; @@ -757,17 +546,8 @@ typedef network_ip_socket_address_t udp_ip_socket_address_t; typedef network_ip_address_family_t udp_ip_address_family_t; -// A received datagram. typedef struct udp_incoming_datagram_t { - // The payload. - // - // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. wasip2_list_u8_t data; - // The source address. - // - // This field is guaranteed to match the remote address the stream was initialized with, if any. - // - // Equivalent to the `src_addr` out parameter of `recvfrom`. udp_ip_socket_address_t remote_address; } udp_incoming_datagram_t; @@ -776,17 +556,8 @@ typedef struct { udp_ip_socket_address_t val; } udp_option_ip_socket_address_t; -// A datagram to be sent out. typedef struct udp_outgoing_datagram_t { - // The payload. wasip2_list_u8_t data; - // The destination address. - // - // The requirements on this field depend on how the stream was initialized: - // - with a remote address: this field must be None or match the stream's remote address exactly. - // - without a remote address: this field is required. - // - // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`. udp_option_ip_socket_address_t remote_address; } udp_outgoing_datagram_t; @@ -904,11 +675,8 @@ typedef network_ip_address_family_t tcp_ip_address_family_t; typedef uint8_t tcp_shutdown_type_t; -// Similar to `SHUT_RD` in POSIX. #define TCP_SHUTDOWN_TYPE_RECEIVE 0 -// Similar to `SHUT_WR` in POSIX. #define TCP_SHUTDOWN_TYPE_SEND 1 -// Similar to `SHUT_RDWR` in POSIX. #define TCP_SHUTDOWN_TYPE_BOTH 2 typedef struct tcp_own_tcp_socket_t { @@ -1035,16 +803,6 @@ typedef struct ip_name_lookup_borrow_resolve_address_stream_t { int32_t __handle; } ip_name_lookup_borrow_resolve_address_stream_t; -typedef network_borrow_network_t ip_name_lookup_borrow_network_t; - -typedef struct { - bool is_err; - union { - ip_name_lookup_own_resolve_address_stream_t ok; - ip_name_lookup_error_code_t err; - } val; -} ip_name_lookup_result_own_resolve_address_stream_error_code_t; - typedef struct { bool is_some; ip_name_lookup_ip_address_t val; @@ -1060,6 +818,16 @@ typedef struct { typedef poll_own_pollable_t ip_name_lookup_own_pollable_t; +typedef network_borrow_network_t ip_name_lookup_borrow_network_t; + +typedef struct { + bool is_err; + union { + ip_name_lookup_own_resolve_address_stream_t ok; + ip_name_lookup_error_code_t err; + } val; +} ip_name_lookup_result_own_resolve_address_stream_error_code_t; + typedef struct { uint64_t f0; uint64_t f1; @@ -1086,217 +854,28 @@ extern bool environment_initial_cwd(wasip2_string_t *ret); _Noreturn extern void exit_exit(exit_result_void_void_t *status); // Imported Functions from `wasi:io/error@0.2.0` -// Returns a string that is suitable to assist humans in debugging -// this error. -// -// WARNING: The returned string should not be consumed mechanically! -// It may change across platforms, hosts, or other implementation -// details. Parsing this string is a major platform-compatibility -// hazard. extern void io_error_method_error_to_debug_string(io_error_borrow_error_t self, wasip2_string_t *ret); // Imported Functions from `wasi:io/poll@0.2.0` -// Return the readiness of a pollable. This function never blocks. -// -// Returns `true` when the pollable is ready, and `false` otherwise. extern bool poll_method_pollable_ready(poll_borrow_pollable_t self); -// `block` returns immediately if the pollable is ready, and otherwise -// blocks until ready. -// -// This function is equivalent to calling `poll.poll` on a list -// containing only this pollable. extern void poll_method_pollable_block(poll_borrow_pollable_t self); -// Poll for completion on a set of pollables. -// -// This function takes a list of pollables, which identify I/O sources of -// interest, and waits until one or more of the events is ready for I/O. -// -// The result `list` contains one or more indices of handles in the -// argument list that is ready for I/O. -// -// If the list contains more elements than can be indexed with a `u32` -// value, this function traps. -// -// A timeout can be implemented by adding a pollable from the -// wasi-clocks API to the list. -// -// This function does not return a `result`; polling in itself does not -// do any I/O so it doesn't fail. If any of the I/O sources identified by -// the pollables has an error, it is indicated by marking the source as -// being reaedy for I/O. extern void poll_poll(poll_list_borrow_pollable_t *in, wasip2_list_u32_t *ret); // Imported Functions from `wasi:io/streams@0.2.0` -// Perform a non-blocking read from the stream. -// -// When the source of a `read` is binary data, the bytes from the source -// are returned verbatim. When the source of a `read` is known to the -// implementation to be text, bytes containing the UTF-8 encoding of the -// text are returned. -// -// This function returns a list of bytes containing the read data, -// when successful. The returned list will contain up to `len` bytes; -// it may return fewer than requested, but not more. The list is -// empty when no bytes are available for reading at this time. The -// pollable given by `subscribe` will be ready when more bytes are -// available. -// -// This function fails with a `stream-error` when the operation -// encounters an error, giving `last-operation-failed`, or when the -// stream is closed, giving `closed`. -// -// When the caller gives a `len` of 0, it represents a request to -// read 0 bytes. If the stream is still open, this call should -// succeed and return an empty list, or otherwise fail with `closed`. -// -// The `len` parameter is a `u64`, which could represent a list of u8 which -// is not possible to allocate in wasm32, or not desirable to allocate as -// as a return value by the callee. The callee may return a list of bytes -// less than `len` in size while more bytes are available for reading. extern bool streams_method_input_stream_read(streams_borrow_input_stream_t self, uint64_t len, wasip2_list_u8_t *ret, streams_stream_error_t *err); -// Read bytes from a stream, after blocking until at least one byte can -// be read. Except for blocking, behavior is identical to `read`. extern bool streams_method_input_stream_blocking_read(streams_borrow_input_stream_t self, uint64_t len, wasip2_list_u8_t *ret, streams_stream_error_t *err); -// Skip bytes from a stream. Returns number of bytes skipped. -// -// Behaves identical to `read`, except instead of returning a list -// of bytes, returns the number of bytes consumed from the stream. extern bool streams_method_input_stream_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err); -// Skip bytes from a stream, after blocking until at least one byte -// can be skipped. Except for blocking behavior, identical to `skip`. extern bool streams_method_input_stream_blocking_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err); -// Create a `pollable` which will resolve once either the specified stream -// has bytes available to read or the other end of the stream has been -// closed. -// The created `pollable` is a child resource of the `input-stream`. -// Implementations may trap if the `input-stream` is dropped before -// all derived `pollable`s created with this function are dropped. extern streams_own_pollable_t streams_method_input_stream_subscribe(streams_borrow_input_stream_t self); -// Check readiness for writing. This function never blocks. -// -// Returns the number of bytes permitted for the next call to `write`, -// or an error. Calling `write` with more bytes than this function has -// permitted will trap. -// -// When this function returns 0 bytes, the `subscribe` pollable will -// become ready when this function will report at least 1 byte, or an -// error. extern bool streams_method_output_stream_check_write(streams_borrow_output_stream_t self, uint64_t *ret, streams_stream_error_t *err); -// Perform a write. This function never blocks. -// -// When the destination of a `write` is binary data, the bytes from -// `contents` are written verbatim. When the destination of a `write` is -// known to the implementation to be text, the bytes of `contents` are -// transcoded from UTF-8 into the encoding of the destination and then -// written. -// -// Precondition: check-write gave permit of Ok(n) and contents has a -// length of less than or equal to n. Otherwise, this function will trap. -// -// returns Err(closed) without writing if the stream has closed since -// the last call to check-write provided a permit. extern bool streams_method_output_stream_write(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err); -// Perform a write of up to 4096 bytes, and then flush the stream. Block -// until all of these operations are complete, or an error occurs. -// -// This is a convenience wrapper around the use of `check-write`, -// `subscribe`, `write`, and `flush`, and is implemented with the -// following pseudo-code: -// -// ```text -// let pollable = this.subscribe(); -// while !contents.is_empty() { -// // Wait for the stream to become writable -// pollable.block(); -// let Ok(n) = this.check-write(); // eliding error handling -// let len = min(n, contents.len()); -// let (chunk, rest) = contents.split_at(len); -// this.write(chunk ); // eliding error handling -// contents = rest; -// } -// this.flush(); -// // Wait for completion of `flush` -// pollable.block(); -// // Check for any errors that arose during `flush` -// let _ = this.check-write(); // eliding error handling -// ``` extern bool streams_method_output_stream_blocking_write_and_flush(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err); -// Request to flush buffered output. This function never blocks. -// -// This tells the output-stream that the caller intends any buffered -// output to be flushed. the output which is expected to be flushed -// is all that has been passed to `write` prior to this call. -// -// Upon calling this function, the `output-stream` will not accept any -// writes (`check-write` will return `ok(0)`) until the flush has -// completed. The `subscribe` pollable will become ready when the -// flush has completed and the stream can accept more writes. extern bool streams_method_output_stream_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err); -// Request to flush buffered output, and block until flush completes -// and stream is ready for writing again. extern bool streams_method_output_stream_blocking_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err); -// Create a `pollable` which will resolve once the output-stream -// is ready for more writing, or an error has occured. When this -// pollable is ready, `check-write` will return `ok(n)` with n>0, or an -// error. -// -// If the stream is closed, this pollable is always ready immediately. -// -// The created `pollable` is a child resource of the `output-stream`. -// Implementations may trap if the `output-stream` is dropped before -// all derived `pollable`s created with this function are dropped. extern streams_own_pollable_t streams_method_output_stream_subscribe(streams_borrow_output_stream_t self); -// Write zeroes to a stream. -// -// This should be used precisely like `write` with the exact same -// preconditions (must use check-write first), but instead of -// passing a list of bytes, you simply pass the number of zero-bytes -// that should be written. extern bool streams_method_output_stream_write_zeroes(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err); -// Perform a write of up to 4096 zeroes, and then flush the stream. -// Block until all of these operations are complete, or an error -// occurs. -// -// This is a convenience wrapper around the use of `check-write`, -// `subscribe`, `write-zeroes`, and `flush`, and is implemented with -// the following pseudo-code: -// -// ```text -// let pollable = this.subscribe(); -// while num_zeroes != 0 { -// // Wait for the stream to become writable -// pollable.block(); -// let Ok(n) = this.check-write(); // eliding error handling -// let len = min(n, num_zeroes); -// this.write-zeroes(len); // eliding error handling -// num_zeroes -= len; -// } -// this.flush(); -// // Wait for completion of `flush` -// pollable.block(); -// // Check for any errors that arose during `flush` -// let _ = this.check-write(); // eliding error handling -// ``` extern bool streams_method_output_stream_blocking_write_zeroes_and_flush(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err); -// Read from one stream and write to another. -// -// The behavior of splice is equivelant to: -// 1. calling `check-write` on the `output-stream` -// 2. calling `read` on the `input-stream` with the smaller of the -// `check-write` permitted length and the `len` provided to `splice` -// 3. calling `write` on the `output-stream` with that read data. -// -// Any error reported by the call to `check-write`, `read`, or -// `write` ends the splice and reports that error. -// -// This function returns the number of bytes transferred; it may be less -// than `len`. extern bool streams_method_output_stream_splice(streams_borrow_output_stream_t self, streams_borrow_input_stream_t src, uint64_t len, uint64_t *ret, streams_stream_error_t *err); -// Read from one stream and write to another, with blocking. -// -// This is similar to `splice`, except that it blocks until the -// `output-stream` is ready for writing, and the `input-stream` -// is ready for reading, before performing the `splice`. extern bool streams_method_output_stream_blocking_splice(streams_borrow_output_stream_t self, streams_borrow_input_stream_t src, uint64_t len, uint64_t *ret, streams_stream_error_t *err); // Imported Functions from `wasi:cli/stdin@0.2.0` @@ -1324,930 +903,122 @@ extern bool terminal_stdout_get_terminal_stdout(terminal_stdout_own_terminal_out extern bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t *ret); // Imported Functions from `wasi:clocks/monotonic-clock@0.2.0` -// Read the current value of the clock. -// -// The clock is monotonic, therefore calling this function repeatedly will -// produce a sequence of non-decreasing values. extern monotonic_clock_instant_t monotonic_clock_now(void); -// Query the resolution of the clock. Returns the duration of time -// corresponding to a clock tick. extern monotonic_clock_duration_t monotonic_clock_resolution(void); -// Create a `pollable` which will resolve once the specified instant -// occured. extern monotonic_clock_own_pollable_t monotonic_clock_subscribe_instant(monotonic_clock_instant_t when); -// Create a `pollable` which will resolve once the given duration has -// elapsed, starting at the time at which this function was called. -// occured. extern monotonic_clock_own_pollable_t monotonic_clock_subscribe_duration(monotonic_clock_duration_t when); // Imported Functions from `wasi:clocks/wall-clock@0.2.0` -// Read the current value of the clock. -// -// This clock is not monotonic, therefore calling this function repeatedly -// will not necessarily produce a sequence of non-decreasing values. -// -// The returned timestamps represent the number of seconds since -// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], -// also known as [Unix Time]. -// -// The nanoseconds field of the output is always less than 1000000000. -// -// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 -// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time extern void wall_clock_now(wall_clock_datetime_t *ret); -// Query the resolution of the clock. -// -// The nanoseconds field of the output is always less than 1000000000. extern void wall_clock_resolution(wall_clock_datetime_t *ret); // Imported Functions from `wasi:filesystem/types@0.2.0` -// Return a stream for reading from a file, if available. -// -// May fail with an error-code describing why the file cannot be read. -// -// Multiple read, write, and append streams may be active on the same open -// file and they do not interfere with each other. -// -// Note: This allows using `read-stream`, which is similar to `read` in POSIX. extern bool filesystem_method_descriptor_read_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_own_input_stream_t *ret, filesystem_error_code_t *err); -// Return a stream for writing to a file, if available. -// -// May fail with an error-code describing why the file cannot be written. -// -// Note: This allows using `write-stream`, which is similar to `write` in -// POSIX. extern bool filesystem_method_descriptor_write_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_own_output_stream_t *ret, filesystem_error_code_t *err); -// Return a stream for appending to a file, if available. -// -// May fail with an error-code describing why the file cannot be appended. -// -// Note: This allows using `write-stream`, which is similar to `write` with -// `O_APPEND` in in POSIX. extern bool filesystem_method_descriptor_append_via_stream(filesystem_borrow_descriptor_t self, filesystem_own_output_stream_t *ret, filesystem_error_code_t *err); -// Provide file advisory information on a descriptor. -// -// This is similar to `posix_fadvise` in POSIX. extern bool filesystem_method_descriptor_advise(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_filesize_t length, filesystem_advice_t advice, filesystem_error_code_t *err); -// Synchronize the data of a file to disk. -// -// This function succeeds with no effect if the file descriptor is not -// opened for writing. -// -// Note: This is similar to `fdatasync` in POSIX. extern bool filesystem_method_descriptor_sync_data(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err); -// Get flags associated with a descriptor. -// -// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. -// -// Note: This returns the value that was the `fs_flags` value returned -// from `fdstat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_get_flags(filesystem_borrow_descriptor_t self, filesystem_descriptor_flags_t *ret, filesystem_error_code_t *err); -// Get the dynamic type of a descriptor. -// -// Note: This returns the same value as the `type` field of the `fd-stat` -// returned by `stat`, `stat-at` and similar. -// -// Note: This returns similar flags to the `st_mode & S_IFMT` value provided -// by `fstat` in POSIX. -// -// Note: This returns the value that was the `fs_filetype` value returned -// from `fdstat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_get_type(filesystem_borrow_descriptor_t self, filesystem_descriptor_type_t *ret, filesystem_error_code_t *err); -// Adjust the size of an open file. If this increases the file's size, the -// extra bytes are filled with zeros. -// -// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. extern bool filesystem_method_descriptor_set_size(filesystem_borrow_descriptor_t self, filesystem_filesize_t size, filesystem_error_code_t *err); -// Adjust the timestamps of an open file or directory. -// -// Note: This is similar to `futimens` in POSIX. -// -// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. extern bool filesystem_method_descriptor_set_times(filesystem_borrow_descriptor_t self, filesystem_new_timestamp_t *data_access_timestamp, filesystem_new_timestamp_t *data_modification_timestamp, filesystem_error_code_t *err); -// Read from a descriptor, without using and updating the descriptor's offset. -// -// This function returns a list of bytes containing the data that was -// read, along with a bool which, when true, indicates that the end of the -// file was reached. The returned list will contain up to `length` bytes; it -// may return fewer than requested, if the end of the file is reached or -// if the I/O operation is interrupted. -// -// In the future, this may change to return a `stream`. -// -// Note: This is similar to `pread` in POSIX. extern bool filesystem_method_descriptor_read(filesystem_borrow_descriptor_t self, filesystem_filesize_t length, filesystem_filesize_t offset, wasip2_tuple2_list_u8_bool_t *ret, filesystem_error_code_t *err); -// Write to a descriptor, without using and updating the descriptor's offset. -// -// It is valid to write past the end of a file; the file is extended to the -// extent of the write, with bytes between the previous end and the start of -// the write set to zero. -// -// In the future, this may change to take a `stream`. -// -// Note: This is similar to `pwrite` in POSIX. extern bool filesystem_method_descriptor_write(filesystem_borrow_descriptor_t self, wasip2_list_u8_t *buffer, filesystem_filesize_t offset, filesystem_filesize_t *ret, filesystem_error_code_t *err); -// Read directory entries from a directory. -// -// On filesystems where directories contain entries referring to themselves -// and their parents, often named `.` and `..` respectively, these entries -// are omitted. -// -// This always returns a new stream which starts at the beginning of the -// directory. Multiple streams may be active on the same directory, and they -// do not interfere with each other. extern bool filesystem_method_descriptor_read_directory(filesystem_borrow_descriptor_t self, filesystem_own_directory_entry_stream_t *ret, filesystem_error_code_t *err); -// Synchronize the data and metadata of a file to disk. -// -// This function succeeds with no effect if the file descriptor is not -// opened for writing. -// -// Note: This is similar to `fsync` in POSIX. extern bool filesystem_method_descriptor_sync(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err); -// Create a directory. -// -// Note: This is similar to `mkdirat` in POSIX. extern bool filesystem_method_descriptor_create_directory_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); -// Return the attributes of an open file or directory. -// -// Note: This is similar to `fstat` in POSIX, except that it does not return -// device and inode information. For testing whether two descriptors refer to -// the same underlying filesystem object, use `is-same-object`. To obtain -// additional data that can be used do determine whether a file has been -// modified, use `metadata-hash`. -// -// Note: This was called `fd_filestat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_stat(filesystem_borrow_descriptor_t self, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err); -// Return the attributes of a file or directory. -// -// Note: This is similar to `fstatat` in POSIX, except that it does not -// return device and inode information. See the `stat` description for a -// discussion of alternatives. -// -// Note: This was called `path_filestat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_stat_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err); -// Adjust the timestamps of a file or directory. -// -// Note: This is similar to `utimensat` in POSIX. -// -// Note: This was called `path_filestat_set_times` in earlier versions of -// WASI. extern bool filesystem_method_descriptor_set_times_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_new_timestamp_t *data_access_timestamp, filesystem_new_timestamp_t *data_modification_timestamp, filesystem_error_code_t *err); -// Create a hard link. -// -// Note: This is similar to `linkat` in POSIX. extern bool filesystem_method_descriptor_link_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t old_path_flags, wasip2_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, wasip2_string_t *new_path, filesystem_error_code_t *err); -// Open a file or directory. -// -// The returned descriptor is not guaranteed to be the lowest-numbered -// 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 descriptor is -// guaranteed to be less than 2**31. -// -// If `flags` contains `descriptor-flags::mutate-directory`, and the base -// descriptor doesn't have `descriptor-flags::mutate-directory` set, -// `open-at` fails with `error-code::read-only`. -// -// If `flags` contains `write` or `mutate-directory`, or `open-flags` -// contains `truncate` or `create`, and the base descriptor doesn't have -// `descriptor-flags::mutate-directory` set, `open-at` fails with -// `error-code::read-only`. -// -// Note: This is similar to `openat` in POSIX. extern bool filesystem_method_descriptor_open_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_open_flags_t open_flags, filesystem_descriptor_flags_t flags, filesystem_own_descriptor_t *ret, filesystem_error_code_t *err); -// Read the contents of a symbolic link. -// -// If the contents contain an absolute or rooted path in the underlying -// filesystem, this function fails with `error-code::not-permitted`. -// -// Note: This is similar to `readlinkat` in POSIX. extern bool filesystem_method_descriptor_readlink_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, wasip2_string_t *ret, filesystem_error_code_t *err); -// Remove a directory. -// -// Return `error-code::not-empty` if the directory is not empty. -// -// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. extern bool filesystem_method_descriptor_remove_directory_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); -// Rename a filesystem object. -// -// Note: This is similar to `renameat` in POSIX. extern bool filesystem_method_descriptor_rename_at(filesystem_borrow_descriptor_t self, wasip2_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, wasip2_string_t *new_path, filesystem_error_code_t *err); -// Create a symbolic link (also known as a "symlink"). -// -// If `old-path` starts with `/`, the function fails with -// `error-code::not-permitted`. -// -// Note: This is similar to `symlinkat` in POSIX. extern bool filesystem_method_descriptor_symlink_at(filesystem_borrow_descriptor_t self, wasip2_string_t *old_path, wasip2_string_t *new_path, filesystem_error_code_t *err); -// Unlink a filesystem object that is not a directory. -// -// Return `error-code::is-directory` if the path refers to a directory. -// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. extern bool filesystem_method_descriptor_unlink_file_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); -// Test whether two descriptors refer to the same filesystem object. -// -// In POSIX, this corresponds to testing whether the two descriptors have the -// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. -// wasi-filesystem does not expose device and inode numbers, so this function -// may be used instead. extern bool filesystem_method_descriptor_is_same_object(filesystem_borrow_descriptor_t self, filesystem_borrow_descriptor_t other); -// Return a hash of the metadata associated with a filesystem object referred -// to by a descriptor. -// -// This returns a hash of the last-modification timestamp and file size, and -// may also include the inode number, device number, birth timestamp, and -// other metadata fields that may change when the file is modified or -// replaced. It may also include a secret value chosen by the -// implementation and not otherwise exposed. -// -// Implementations are encourated to provide the following properties: -// -// - If the file is not modified or replaced, the computed hash value should -// usually not change. -// - If the object is modified or replaced, the computed hash value should -// usually change. -// - The inputs to the hash should not be easily computable from the -// computed hash. -// -// However, none of these is required. extern bool filesystem_method_descriptor_metadata_hash(filesystem_borrow_descriptor_t self, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err); -// Return a hash of the metadata associated with a filesystem object referred -// to by a directory descriptor and a relative path. -// -// This performs the same hash computation as `metadata-hash`. extern bool filesystem_method_descriptor_metadata_hash_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err); -// Read a single directory entry from a `directory-entry-stream`. extern bool filesystem_method_directory_entry_stream_read_directory_entry(filesystem_borrow_directory_entry_stream_t self, filesystem_option_directory_entry_t *ret, filesystem_error_code_t *err); -// Attempts to extract a filesystem-related `error-code` from the stream -// `error` provided. -// -// Stream operations which return `stream-error::last-operation-failed` -// have a payload with more information about the operation that failed. -// This payload can be passed through to this function to see if there's -// filesystem-related information about the error to return. -// -// Note that this function is fallible because not all stream-related -// errors are filesystem-related errors. extern bool filesystem_filesystem_error_code(filesystem_borrow_error_t err_, filesystem_error_code_t *ret); // Imported Functions from `wasi:filesystem/preopens@0.2.0` -// Return the set of preopened directories, and their path. extern void filesystem_preopens_get_directories(filesystem_preopens_list_tuple2_own_descriptor_string_t *ret); // Imported Functions from `wasi:sockets/instance-network@0.2.0` -// Get a handle to the default network. extern instance_network_own_network_t instance_network_instance_network(void); // Imported Functions from `wasi:sockets/udp@0.2.0` -// Bind the socket to a specific network on the provided IP address and port. -// -// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which -// network interface(s) to bind to. -// If the port is zero, the socket will be bound to a random free port. -// -// # Typical errors -// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) -// - `invalid-state`: The socket is already bound. (EINVAL) -// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) -// - `address-in-use`: Address is already in use. (EADDRINUSE) -// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) -// - `not-in-progress`: A `bind` operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// Unlike in POSIX, in WASI the bind operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `bind` as part of either `start-bind` or `finish-bind`. -// -// # References -// - -// - -// - -// - extern bool udp_method_udp_socket_start_bind(udp_borrow_udp_socket_t self, udp_borrow_network_t network, udp_ip_socket_address_t *local_address, udp_error_code_t *err); extern bool udp_method_udp_socket_finish_bind(udp_borrow_udp_socket_t self, udp_error_code_t *err); -// Set up inbound & outbound communication channels, optionally to a specific peer. -// -// This function only changes the local socket configuration and does not generate any network traffic. -// On success, the `remote-address` of the socket is updated. The `local-address` may be updated as well, -// based on the best network path to `remote-address`. -// -// When a `remote-address` is provided, the returned streams are limited to communicating with that specific peer: -// - `send` can only be used to send to this destination. -// - `receive` will only return datagrams sent from the provided `remote-address`. -// -// This method may be called multiple times on the same socket to change its association, but -// only the most recently returned pair of streams will be operational. Implementations may trap if -// the streams returned by a previous invocation haven't been dropped yet before calling `stream` again. -// -// The POSIX equivalent in pseudo-code is: -// ```text -// if (was previously connected) { -// connect(s, AF_UNSPEC) -// } -// if (remote_address is Some) { -// connect(s, remote_address) -// } -// ``` -// -// Unlike in POSIX, the socket must already be explicitly bound. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-state`: The socket is not bound. -// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// -// # References -// - -// - -// - -// - extern bool udp_method_udp_socket_stream(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *maybe_remote_address, udp_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_t *ret, udp_error_code_t *err); -// Get the current bound address. -// -// POSIX mentions: -// > If the socket has not been bound to a local name, the value -// > stored in the object pointed to by `address` is unspecified. -// -// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. -// -// # References -// - -// - -// - -// - extern bool udp_method_udp_socket_local_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err); -// Get the address the socket is currently streaming to. -// -// # Typical errors -// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) -// -// # References -// - -// - -// - -// - extern bool udp_method_udp_socket_remote_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err); -// Whether this is a IPv4 or IPv6 socket. -// -// Equivalent to the SO_DOMAIN socket option. extern udp_ip_address_family_t udp_method_udp_socket_address_family(udp_borrow_udp_socket_t self); -// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// -// # Typical errors -// - `invalid-argument`: (set) The TTL value must be 1 or higher. extern bool udp_method_udp_socket_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t *ret, udp_error_code_t *err); extern bool udp_method_udp_socket_set_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t value, udp_error_code_t *err); -// The kernel buffer space reserved for sends/receives on this socket. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. extern bool udp_method_udp_socket_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err); extern bool udp_method_udp_socket_set_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err); extern bool udp_method_udp_socket_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err); extern bool udp_method_udp_socket_set_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err); -// Create a `pollable` which will resolve once the socket is ready for I/O. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. extern udp_own_pollable_t udp_method_udp_socket_subscribe(udp_borrow_udp_socket_t self); -// Receive messages on the socket. -// -// This function attempts to receive up to `max-results` datagrams on the socket without blocking. -// The returned list may contain fewer elements than requested, but never more. -// -// This function returns successfully with an empty list when either: -// - `max-results` is 0, or: -// - `max-results` is greater than 0, but no results are immediately available. -// This function never returns `error(would-block)`. -// -// # Typical errors -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - extern bool udp_method_incoming_datagram_stream_receive(udp_borrow_incoming_datagram_stream_t self, uint64_t max_results, udp_list_incoming_datagram_t *ret, udp_error_code_t *err); -// Create a `pollable` which will resolve once the stream is ready to receive again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. extern udp_own_pollable_t udp_method_incoming_datagram_stream_subscribe(udp_borrow_incoming_datagram_stream_t self); -// Check readiness for sending. This function never blocks. -// -// Returns the number of datagrams permitted for the next call to `send`, -// or an error. Calling `send` with more datagrams than this function has -// permitted will trap. -// -// When this function returns ok(0), the `subscribe` pollable will -// become ready when this function will report at least ok(1), or an -// error. -// -// Never returns `would-block`. extern bool udp_method_outgoing_datagram_stream_check_send(udp_borrow_outgoing_datagram_stream_t self, uint64_t *ret, udp_error_code_t *err); -// Send messages on the socket. -// -// This function attempts to send all provided `datagrams` on the socket without blocking and -// returns how many messages were actually sent (or queued for sending). This function never -// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned. -// -// This function semantically behaves the same as iterating the `datagrams` list and sequentially -// sending each individual datagram until either the end of the list has been reached or the first error occurred. -// If at least one datagram has been sent successfully, this function never returns an error. -// -// If the input list is empty, the function returns `ok(0)`. -// -// Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if -// either `check-send` was not called or `datagrams` contains more items than `check-send` permitted. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN) -// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ) -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - extern bool udp_method_outgoing_datagram_stream_send(udp_borrow_outgoing_datagram_stream_t self, udp_list_outgoing_datagram_t *datagrams, uint64_t *ret, udp_error_code_t *err); -// Create a `pollable` which will resolve once the stream is ready to send again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. extern udp_own_pollable_t udp_method_outgoing_datagram_stream_subscribe(udp_borrow_outgoing_datagram_stream_t self); // Imported Functions from `wasi:sockets/udp-create-socket@0.2.0` -// Create a new UDP socket. -// -// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX. -// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. -// -// This function does not require a network capability handle. This is considered to be safe because -// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind` is called, -// the socket is effectively an in-memory configuration object, unable to communicate with the outside world. -// -// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. -// -// # Typical errors -// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) -// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) -// -// # References: -// - -// - -// - -// - extern bool udp_create_socket_create_udp_socket(udp_create_socket_ip_address_family_t address_family, udp_create_socket_own_udp_socket_t *ret, udp_create_socket_error_code_t *err); // Imported Functions from `wasi:sockets/tcp@0.2.0` -// Bind the socket to a specific network on the provided IP address and port. -// -// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which -// network interface(s) to bind to. -// If the TCP/UDP port is zero, the socket will be bound to a random free port. -// -// Bind can be attempted multiple times on the same socket, even with -// different arguments on each iteration. But never concurrently and -// only as long as the previous bind failed. Once a bind succeeds, the -// binding can't be changed anymore. -// -// # Typical errors -// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) -// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) -// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL) -// - `invalid-state`: The socket is already bound. (EINVAL) -// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) -// - `address-in-use`: Address is already in use. (EADDRINUSE) -// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) -// - `not-in-progress`: A `bind` operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT -// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR -// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior -// and SO_REUSEADDR performs something different entirely. -// -// Unlike in POSIX, in WASI the bind operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `bind` as part of either `start-bind` or `finish-bind`. -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_start_bind(tcp_borrow_tcp_socket_t self, tcp_borrow_network_t network, tcp_ip_socket_address_t *local_address, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_finish_bind(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); -// Connect to a remote endpoint. -// -// On success: -// - the socket is transitioned into the `connection` state. -// - a pair of streams is returned that can be used to read & write to the connection -// -// After a failed connection attempt, the socket will be in the `closed` -// state and the only valid action left is to `drop` the socket. A single -// socket can not be used to connect more than once. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) -// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) -// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows) -// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. -// - `invalid-state`: The socket is already in the `connected` state. (EISCONN) -// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows) -// - `timeout`: Connection timed out. (ETIMEDOUT) -// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) -// - `connection-reset`: The connection was reset. (ECONNRESET) -// - `connection-aborted`: The connection was aborted. (ECONNABORTED) -// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) -// - `not-in-progress`: A connect operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// The POSIX equivalent of `start-connect` is the regular `connect` syscall. -// Because all WASI sockets are non-blocking this is expected to return -// EINPROGRESS, which should be translated to `ok()` in WASI. -// -// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` -// with a timeout of 0 on the socket descriptor. Followed by a check for -// the `SO_ERROR` socket option, in case the poll signaled readiness. -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_start_connect(tcp_borrow_tcp_socket_t self, tcp_borrow_network_t network, tcp_ip_socket_address_t *remote_address, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_finish_connect(tcp_borrow_tcp_socket_t self, tcp_tuple2_own_input_stream_own_output_stream_t *ret, tcp_error_code_t *err); -// Start listening for new connections. -// -// Transitions the socket into the `listening` state. -// -// Unlike POSIX, the socket must already be explicitly bound. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) -// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD) -// - `invalid-state`: The socket is already in the `listening` state. -// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE) -// - `not-in-progress`: A listen operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// Unlike in POSIX, in WASI the listen operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `listen` as part of either `start-listen` or `finish-listen`. -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_start_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_finish_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); -// Accept a new client socket. -// -// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket: -// - `address-family` -// - `keep-alive-enabled` -// - `keep-alive-idle-time` -// - `keep-alive-interval` -// - `keep-alive-count` -// - `hop-limit` -// - `receive-buffer-size` -// - `send-buffer-size` -// -// On success, this function returns the newly accepted client socket along with -// a pair of streams that can be used to read & write to the connection. -// -// # Typical errors -// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) -// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) -// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED) -// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_accept(tcp_borrow_tcp_socket_t self, tcp_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ret, tcp_error_code_t *err); -// Get the bound local address. -// -// POSIX mentions: -// > If the socket has not been bound to a local name, the value -// > stored in the object pointed to by `address` is unspecified. -// -// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_local_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err); -// Get the remote address. -// -// # Typical errors -// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_remote_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err); -// Whether the socket is in the `listening` state. -// -// Equivalent to the SO_ACCEPTCONN socket option. extern bool tcp_method_tcp_socket_is_listening(tcp_borrow_tcp_socket_t self); -// Whether this is a IPv4 or IPv6 socket. -// -// Equivalent to the SO_DOMAIN socket option. extern tcp_ip_address_family_t tcp_method_tcp_socket_address_family(tcp_borrow_tcp_socket_t self); -// Hints the desired listen queue size. Implementations are free to ignore this. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// -// # Typical errors -// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. -// - `invalid-argument`: (set) The provided value was 0. -// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state. extern bool tcp_method_tcp_socket_set_listen_backlog_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); -// Enables or disables keepalive. -// -// The keepalive behavior can be adjusted using: -// - `keep-alive-idle-time` -// - `keep-alive-interval` -// - `keep-alive-count` -// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. -// -// Equivalent to the SO_KEEPALIVE socket option. extern bool tcp_method_tcp_socket_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool value, tcp_error_code_t *err); -// Amount of time the connection has to be idle before TCP starts sending keepalive packets. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err); -// The time between keepalive packets. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the TCP_KEEPINTVL socket option. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err); -// The maximum amount of keepalive packets TCP should send before aborting the connection. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the TCP_KEEPCNT socket option. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t value, tcp_error_code_t *err); -// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// -// # Typical errors -// - `invalid-argument`: (set) The TTL value must be 1 or higher. extern bool tcp_method_tcp_socket_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t value, tcp_error_code_t *err); -// The kernel buffer space reserved for sends/receives on this socket. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); -// Create a `pollable` which can be used to poll for, or block on, -// completion of any of the asynchronous operations of this socket. -// -// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` -// return `error(would-block)`, this pollable can be used to wait for -// their success or failure, after which the method can be retried. -// -// The pollable is not limited to the async operation that happens to be -// in progress at the time of calling `subscribe` (if any). Theoretically, -// `subscribe` only has to be called once per socket and can then be -// (re)used for the remainder of the socket's lifetime. -// -// See -// for a more information. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. extern tcp_own_pollable_t tcp_method_tcp_socket_subscribe(tcp_borrow_tcp_socket_t self); -// Initiate a graceful shutdown. -// -// - `receive`: The socket is not expecting to receive any data from -// the peer. The `input-stream` associated with this socket will be -// closed. Any data still in the receive queue at time of calling -// this method will be discarded. -// - `send`: The socket has no more data to send to the peer. The `output-stream` -// associated with this socket will be closed and a FIN packet will be sent. -// - `both`: Same effect as `receive` & `send` combined. -// -// This function is idempotent. Shutting a down a direction more than once -// has no effect and returns `ok`. -// -// The shutdown function does not close (drop) the socket. -// -// # Typical errors -// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_shutdown(tcp_borrow_tcp_socket_t self, tcp_shutdown_type_t shutdown_type, tcp_error_code_t *err); // Imported Functions from `wasi:sockets/tcp-create-socket@0.2.0` -// Create a new TCP socket. -// -// Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. -// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. -// -// This function does not require a network capability handle. This is considered to be safe because -// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`connect` -// is called, the socket is effectively an in-memory configuration object, unable to communicate with the outside world. -// -// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. -// -// # Typical errors -// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) -// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) -// -// # References -// - -// - -// - -// - extern bool tcp_create_socket_create_tcp_socket(tcp_create_socket_ip_address_family_t address_family, tcp_create_socket_own_tcp_socket_t *ret, tcp_create_socket_error_code_t *err); // Imported Functions from `wasi:sockets/ip-name-lookup@0.2.0` -// Resolve an internet host name to a list of IP addresses. -// -// Unicode domain names are automatically converted to ASCII using IDNA encoding. -// If the input is an IP address string, the address is parsed and returned -// as-is without making any external requests. -// -// See the wasi-socket proposal README.md for a comparison with getaddrinfo. -// -// This function never blocks. It either immediately fails or immediately -// returns successfully with a `resolve-address-stream` that can be used -// to (asynchronously) fetch the results. -// -// # Typical errors -// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. -// -// # References: -// - -// - -// - -// - -extern bool ip_name_lookup_resolve_addresses(ip_name_lookup_borrow_network_t network, wasip2_string_t *name, ip_name_lookup_own_resolve_address_stream_t *ret, ip_name_lookup_error_code_t *err); -// Returns the next address from the resolver. -// -// This function should be called multiple times. On each call, it will -// return the next address in connection order preference. If all -// addresses have been exhausted, this function returns `none`. -// -// This function never returns IPv4-mapped IPv6 addresses. -// -// # Typical errors -// - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) -// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN) -// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL) -// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) extern bool ip_name_lookup_method_resolve_address_stream_resolve_next_address(ip_name_lookup_borrow_resolve_address_stream_t self, ip_name_lookup_option_ip_address_t *ret, ip_name_lookup_error_code_t *err); -// Create a `pollable` which will resolve once the stream is ready for I/O. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. extern ip_name_lookup_own_pollable_t ip_name_lookup_method_resolve_address_stream_subscribe(ip_name_lookup_borrow_resolve_address_stream_t self); +extern bool ip_name_lookup_resolve_addresses(ip_name_lookup_borrow_network_t network, wasip2_string_t *name, ip_name_lookup_own_resolve_address_stream_t *ret, ip_name_lookup_error_code_t *err); // Imported Functions from `wasi:random/random@0.2.0` -// Return `len` cryptographically-secure random or pseudo-random bytes. -// -// This function must produce data at least as cryptographically secure and -// fast as an adequately seeded cryptographically-secure pseudo-random -// number generator (CSPRNG). It must not block, from the perspective of -// the calling program, under any circumstances, including on the first -// request and on requests for numbers of bytes. The returned data must -// always be unpredictable. -// -// This function must always return fresh data. Deterministic environments -// must omit this function, rather than implementing it with deterministic -// data. extern void random_get_random_bytes(uint64_t len, wasip2_list_u8_t *ret); -// Return a cryptographically-secure random or pseudo-random `u64` value. -// -// This function returns the same type of data as `get-random-bytes`, -// represented as a `u64`. extern uint64_t random_get_random_u64(void); // Imported Functions from `wasi:random/insecure@0.2.0` -// Return `len` insecure pseudo-random bytes. -// -// This function is not cryptographically secure. Do not use it for -// anything related to security. -// -// There are no requirements on the values of the returned bytes, however -// implementations are encouraged to return evenly distributed values with -// a long period. extern void random_insecure_get_insecure_random_bytes(uint64_t len, wasip2_list_u8_t *ret); -// Return an insecure pseudo-random `u64` value. -// -// This function returns the same type of pseudo-random data as -// `get-insecure-random-bytes`, represented as a `u64`. extern uint64_t random_insecure_get_insecure_random_u64(void); // Imported Functions from `wasi:random/insecure-seed@0.2.0` -// Return a 128-bit value that may contain a pseudo-random value. -// -// The returned value is not required to be computed from a CSPRNG, and may -// even be entirely deterministic. Host implementations are encouraged to -// provide pseudo-random values to any program exposed to -// attacker-controlled content, to enable DoS protection built into many -// languages' hash-map implementations. -// -// This function is intended to only be called once, by a source language -// to initialize Denial Of Service (DoS) protection in its hash-map -// implementation. -// -// # Expected future evolution -// -// This will likely be changed to a value import, to prevent it from being -// called multiple times and potentially used for purposes other than DoS -// protection. extern void random_insecure_seed_insecure_seed(wasip2_tuple2_u64_u64_t *ret); // Helper Functions @@ -2434,12 +1205,12 @@ extern void ip_name_lookup_resolve_address_stream_drop_own(ip_name_lookup_own_re extern ip_name_lookup_borrow_resolve_address_stream_t ip_name_lookup_borrow_resolve_address_stream(ip_name_lookup_own_resolve_address_stream_t handle); -void ip_name_lookup_result_own_resolve_address_stream_error_code_free(ip_name_lookup_result_own_resolve_address_stream_error_code_t *ptr); - void ip_name_lookup_option_ip_address_free(ip_name_lookup_option_ip_address_t *ptr); void ip_name_lookup_result_option_ip_address_error_code_free(ip_name_lookup_result_option_ip_address_error_code_t *ptr); +void ip_name_lookup_result_own_resolve_address_stream_error_code_free(ip_name_lookup_result_own_resolve_address_stream_error_code_t *ptr); + // Sets the string `ret` to reference the input string `s` without copying it void wasip2_string_set(wasip2_string_t *ret, const char*s); diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h index 76d736d68..f08d6e0c6 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h @@ -206,18 +206,35 @@ typedef uint64_t wasi_clocks_types_duration_t; typedef wasi_clocks_types_duration_t monotonic_clock_duration_t; -// An instant in time, in nanoseconds. An instant is relative to an +// A mark on a monotonic clock is a number of nanoseconds since an // unspecified initial value, and can only be compared to instances from // the same monotonic-clock. -typedef uint64_t monotonic_clock_instant_t; +typedef uint64_t monotonic_clock_mark_t; -// A time and date in seconds plus nanoseconds. -typedef struct wall_clock_datetime_t { - uint64_t seconds; +typedef wasi_clocks_types_duration_t wasi_clocks_system_clock_duration_t; + +// An "instant", or "exact time", is a point in time without regard to any +// time zone: just the time since a particular external reference point, +// often called an "epoch". +// +// Here, the epoch is 1970-01-01T00:00:00Z, also known as +// [POSIX's Seconds Since the Epoch], also known as [Unix Time]. +// +// Note that even if the seconds field is negative, incrementing +// nanoseconds always represents moving forwards in time. +// For example, `{ -1 seconds, 999999999 nanoseconds }` represents the +// instant one nanosecond before the epoch. +// For more on various different ways to represent time, see +// https://tc39.es/proposal-temporal/docs/timezone.html +// +// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 +// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time +typedef struct wasi_clocks_system_clock_instant_t { + int64_t seconds; uint32_t nanoseconds; -} wall_clock_datetime_t; +} wasi_clocks_system_clock_instant_t; -typedef wall_clock_datetime_t filesystem_datetime_t; +typedef wasi_clocks_system_clock_instant_t filesystem_instant_t; // File size or length of a region within a file. typedef uint64_t filesystem_filesize_t; @@ -312,8 +329,8 @@ typedef uint64_t filesystem_link_count_t; typedef struct { bool is_some; - filesystem_datetime_t val; -} filesystem_option_datetime_t; + filesystem_instant_t val; +} filesystem_option_instant_t; // File attributes. // @@ -330,24 +347,24 @@ typedef struct filesystem_descriptor_stat_t { // // If the `option` is none, the platform doesn't maintain an access // timestamp for this file. - filesystem_option_datetime_t data_access_timestamp; + filesystem_option_instant_t data_access_timestamp; // Last data modification timestamp. // // If the `option` is none, the platform doesn't maintain a // modification timestamp for this file. - filesystem_option_datetime_t data_modification_timestamp; + filesystem_option_instant_t data_modification_timestamp; // Last file status-change timestamp. // // If the `option` is none, the platform doesn't maintain a // status-change timestamp for this file. - filesystem_option_datetime_t status_change_timestamp; + filesystem_option_instant_t status_change_timestamp; } filesystem_descriptor_stat_t; // When setting a timestamp, this gives the value to set it to. typedef struct filesystem_new_timestamp_t { uint8_t tag; union { - filesystem_datetime_t timestamp; + filesystem_instant_t timestamp; } val; } filesystem_new_timestamp_t; @@ -605,7 +622,7 @@ typedef struct { size_t len; } filesystem_preopens_list_tuple2_own_descriptor_string_t; -typedef monotonic_clock_duration_t sockets_duration_t; +typedef wasi_clocks_types_duration_t sockets_duration_t; // Error codes. // @@ -907,7 +924,7 @@ typedef struct { uint64_t f1; } wasip3_tuple2_u64_u64_t; -// Imported Functions from `wasi:cli/environment@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/environment@0.3.0-rc-2026-01-06` // Get the POSIX-style environment variables. // // Each environment variable is provided as a pair of string variable names @@ -923,11 +940,11 @@ extern void environment_get_arguments(wasip3_list_string_t *ret); // directory, interpreting `.` as shorthand for this. extern bool environment_get_initial_cwd(wasip3_string_t *ret); -// Imported Functions from `wasi:cli/exit@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/exit@0.3.0-rc-2026-01-06` // Exit the current instance and any linked instances. _Noreturn extern void exit_exit(exit_result_void_void_t *status); -// Imported Functions from `wasi:cli/stdin@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/stdin@0.3.0-rc-2026-01-06` // Return a stream for reading from stdin. // // This function returns a stream which provides data read from stdin, @@ -943,7 +960,7 @@ _Noreturn extern void exit_exit(exit_result_void_void_t *status); // reads is implementation-specific. extern void stdin_read_via_stream(stdin_tuple2_stream_u8_future_result_void_error_code_t *ret); -// Imported Functions from `wasi:cli/stdout@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/stdout@0.3.0-rc-2026-01-06` // Write the given stream to stdout. // // If the stream's writable end is dropped this function will either return @@ -954,7 +971,7 @@ extern void stdin_read_via_stream(stdin_tuple2_stream_u8_future_result_void_erro // dropped and this function will return an error-code. extern wasip3_subtask_status_t stdout_write_via_stream(stdin_stream_u8_t data, stdout_result_void_error_code_t *result); -// Imported Functions from `wasi:cli/stderr@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/stderr@0.3.0-rc-2026-01-06` // Write the given stream to stderr. // // If the stream's writable end is dropped this function will either return @@ -965,61 +982,53 @@ extern wasip3_subtask_status_t stdout_write_via_stream(stdin_stream_u8_t data, s // dropped and this function will return an error-code. extern wasip3_subtask_status_t stderr_write_via_stream(stdin_stream_u8_t data, stderr_result_void_error_code_t *result); -// Imported Functions from `wasi:cli/terminal-stdin@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/terminal-stdin@0.3.0-rc-2026-01-06` // If stdin is connected to a terminal, return a `terminal-input` handle // allowing further interaction with it. extern bool terminal_stdin_get_terminal_stdin(terminal_stdin_own_terminal_input_t *ret); -// Imported Functions from `wasi:cli/terminal-stdout@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/terminal-stdout@0.3.0-rc-2026-01-06` // If stdout is connected to a terminal, return a `terminal-output` handle // allowing further interaction with it. extern bool terminal_stdout_get_terminal_stdout(terminal_stdout_own_terminal_output_t *ret); -// Imported Functions from `wasi:cli/terminal-stderr@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/terminal-stderr@0.3.0-rc-2026-01-06` // If stderr is connected to a terminal, return a `terminal-output` handle // allowing further interaction with it. extern bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t *ret); -// Imported Functions from `wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06` // Read the current value of the clock. // // The clock is monotonic, therefore calling this function repeatedly will // produce a sequence of non-decreasing values. // // For completeness, this function traps if it's not possible to represent -// the value of the clock in an `instant`. Consequently, implementations +// the value of the clock in a `mark`. Consequently, implementations // should ensure that the starting time is low enough to avoid the // possibility of overflow in practice. -extern monotonic_clock_instant_t monotonic_clock_now(void); +extern monotonic_clock_mark_t monotonic_clock_now(void); // Query the resolution of the clock. Returns the duration of time // corresponding to a clock tick. extern monotonic_clock_duration_t monotonic_clock_get_resolution(void); -// Wait until the specified instant has occurred. -extern wasip3_subtask_status_t monotonic_clock_wait_until(monotonic_clock_instant_t when); +// Wait until the specified mark has occurred. +extern wasip3_subtask_status_t monotonic_clock_wait_until(monotonic_clock_mark_t when); // Wait for the specified duration to elapse. extern wasip3_subtask_status_t monotonic_clock_wait_for(monotonic_clock_duration_t how_long); -// Imported Functions from `wasi:clocks/wall-clock@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:clocks/system-clock@0.3.0-rc-2026-01-06` // Read the current value of the clock. // // This clock is not monotonic, therefore calling this function repeatedly // will not necessarily produce a sequence of non-decreasing values. // -// The returned timestamps represent the number of seconds since -// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], -// also known as [Unix Time]. -// -// The nanoseconds field of the output is always less than 1000000000. -// -// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 -// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time -extern void wall_clock_now(wall_clock_datetime_t *ret); -// Query the resolution of the clock. -// // The nanoseconds field of the output is always less than 1000000000. -extern void wall_clock_get_resolution(wall_clock_datetime_t *ret); +extern void wasi_clocks_system_clock_now(wasi_clocks_system_clock_instant_t *ret); +// Query the resolution of the clock. Returns the smallest duration of time +// that the implementation permits distinguishing. +extern wasi_clocks_system_clock_duration_t wasi_clocks_system_clock_get_resolution(void); -// Imported Functions from `wasi:filesystem/types@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:filesystem/types@0.3.0-rc-2026-01-06` // Return a stream for reading from a file. // // Multiple read, write, and append streams may be active on the same open @@ -1231,11 +1240,11 @@ extern wasip3_subtask_status_t filesystem_method_descriptor_metadata_hash(filesy // This performs the same hash computation as `metadata-hash`. extern wasip3_subtask_status_t filesystem_method_descriptor_metadata_hash_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip3_string_t path, filesystem_result_metadata_hash_value_error_code_t *result); -// Imported Functions from `wasi:filesystem/preopens@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:filesystem/preopens@0.3.0-rc-2026-01-06` // Return the set of preopened directories, and their paths. extern void filesystem_preopens_get_directories(filesystem_preopens_list_tuple2_own_descriptor_string_t *ret); -// Imported Functions from `wasi:sockets/types@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:sockets/types@0.3.0-rc-2026-01-06` // Create a new TCP socket. // // Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. @@ -1748,7 +1757,7 @@ extern bool sockets_method_udp_socket_set_receive_buffer_size(sockets_borrow_udp extern bool sockets_method_udp_socket_get_send_buffer_size(sockets_borrow_udp_socket_t self, uint64_t *ret, sockets_error_code_t *err); extern bool sockets_method_udp_socket_set_send_buffer_size(sockets_borrow_udp_socket_t self, uint64_t value, sockets_error_code_t *err); -// Imported Functions from `wasi:sockets/ip-name-lookup@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:sockets/ip-name-lookup@0.3.0-rc-2026-01-06` // Resolve an internet host name to a list of IP addresses. // // Unicode domain names are automatically converted to ASCII using IDNA encoding. @@ -1773,7 +1782,7 @@ extern bool sockets_method_udp_socket_set_send_buffer_size(sockets_borrow_udp_so // - extern wasip3_subtask_status_t ip_name_lookup_resolve_addresses(wasip3_string_t name, ip_name_lookup_result_list_ip_address_error_code_t *result); -// Imported Functions from `wasi:random/random@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:random/random@0.3.0-rc-2026-01-06` // Return `len` cryptographically-secure random or pseudo-random bytes. // // This function must produce data at least as cryptographically secure and @@ -1793,7 +1802,7 @@ extern void random_get_random_bytes(uint64_t len, wasip3_list_u8_t *ret); // represented as a `u64`. extern uint64_t random_get_random_u64(void); -// Imported Functions from `wasi:random/insecure@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:random/insecure@0.3.0-rc-2026-01-06` // Return `len` insecure pseudo-random bytes. // // This function is not cryptographically secure. Do not use it for @@ -1809,7 +1818,7 @@ extern void random_insecure_get_insecure_random_bytes(uint64_t len, wasip3_list_ // `get-insecure-random-bytes`, represented as a `u64`. extern uint64_t random_insecure_get_insecure_random_u64(void); -// Imported Functions from `wasi:random/insecure-seed@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:random/insecure-seed@0.3.0-rc-2026-01-06` // Return a 128-bit value that may contain a pseudo-random value. // // The returned value is not required to be computed from a CSPRNG, and may @@ -1883,7 +1892,7 @@ void terminal_stdout_option_own_terminal_output_free(terminal_stdout_option_own_ void terminal_stderr_option_own_terminal_output_free(terminal_stderr_option_own_terminal_output_t *ptr); -void filesystem_option_datetime_free(filesystem_option_datetime_t *ptr); +void filesystem_option_instant_free(filesystem_option_instant_t *ptr); void filesystem_descriptor_stat_free(filesystem_descriptor_stat_t *ptr); diff --git a/libc-bottom-half/sources/wasip2.c b/libc-bottom-half/sources/wasip2.c index 06c555ae5..ef3f67ba2 100644 --- a/libc-bottom-half/sources/wasip2.c +++ b/libc-bottom-half/sources/wasip2.c @@ -387,15 +387,15 @@ extern void __wasm_import_tcp_create_socket_create_tcp_socket(int32_t, uint8_t * // Imported Functions from `wasi:sockets/ip-name-lookup@0.2.0` -__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0"), __import_name__("resolve-addresses"))) -extern void __wasm_import_ip_name_lookup_resolve_addresses(int32_t, uint8_t *, size_t, uint8_t *); - __attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0"), __import_name__("[method]resolve-address-stream.resolve-next-address"))) extern void __wasm_import_ip_name_lookup_method_resolve_address_stream_resolve_next_address(int32_t, uint8_t *); __attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0"), __import_name__("[method]resolve-address-stream.subscribe"))) extern int32_t __wasm_import_ip_name_lookup_method_resolve_address_stream_subscribe(int32_t); +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0"), __import_name__("resolve-addresses"))) +extern void __wasm_import_ip_name_lookup_resolve_addresses(int32_t, uint8_t *, size_t, uint8_t *); + // Imported Functions from `wasi:random/random@0.2.0` __attribute__((__import_module__("wasi:random/random@0.2.0"), __import_name__("get-random-bytes"))) @@ -1002,12 +1002,6 @@ ip_name_lookup_borrow_resolve_address_stream_t ip_name_lookup_borrow_resolve_add return (ip_name_lookup_borrow_resolve_address_stream_t) { arg.__handle }; } -void ip_name_lookup_result_own_resolve_address_stream_error_code_free(ip_name_lookup_result_own_resolve_address_stream_error_code_t *ptr) { - if (!ptr->is_err) { - } else { - } -} - void ip_name_lookup_option_ip_address_free(ip_name_lookup_option_ip_address_t *ptr) { if (ptr->is_some) { ip_name_lookup_ip_address_free(&ptr->val); @@ -1021,6 +1015,12 @@ void ip_name_lookup_result_option_ip_address_error_code_free(ip_name_lookup_resu } } +void ip_name_lookup_result_own_resolve_address_stream_error_code_free(ip_name_lookup_result_own_resolve_address_stream_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + void wasip2_string_set(wasip2_string_t *ret, const char*s) { ret->ptr = (uint8_t*) s; ret->len = strlen(s); @@ -4201,33 +4201,6 @@ bool tcp_create_socket_create_tcp_socket(tcp_create_socket_ip_address_family_t a } } -bool ip_name_lookup_resolve_addresses(ip_name_lookup_borrow_network_t network, wasip2_string_t *name, ip_name_lookup_own_resolve_address_stream_t *ret, ip_name_lookup_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - uint8_t *ptr = (uint8_t *) &ret_area; - __wasm_import_ip_name_lookup_resolve_addresses((network).__handle, (uint8_t *) (*name).ptr, (*name).len, ptr); - ip_name_lookup_result_own_resolve_address_stream_error_code_t result; - switch ((int32_t) *((uint8_t*) (ptr + 0))) { - case 0: { - result.is_err = false; - result.val.ok = (ip_name_lookup_own_resolve_address_stream_t) { *((int32_t*) (ptr + 4)) }; - break; - } - case 1: { - result.is_err = true; - result.val.err = (int32_t) *((uint8_t*) (ptr + 4)); - break; - } - } - if (!result.is_err) { - *ret = result.val.ok; - return 1; - } else { - *err = result.val.err; - return 0; - } -} - bool ip_name_lookup_method_resolve_address_stream_resolve_next_address(ip_name_lookup_borrow_resolve_address_stream_t self, ip_name_lookup_option_ip_address_t *ret, ip_name_lookup_error_code_t *err) { __attribute__((__aligned__(2))) uint8_t ret_area[22]; @@ -4300,6 +4273,33 @@ ip_name_lookup_own_pollable_t ip_name_lookup_method_resolve_address_stream_subsc return (ip_name_lookup_own_pollable_t) { ret }; } +bool ip_name_lookup_resolve_addresses(ip_name_lookup_borrow_network_t network, wasip2_string_t *name, ip_name_lookup_own_resolve_address_stream_t *ret, ip_name_lookup_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_ip_name_lookup_resolve_addresses((network).__handle, (uint8_t *) (*name).ptr, (*name).len, ptr); + ip_name_lookup_result_own_resolve_address_stream_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (ip_name_lookup_own_resolve_address_stream_t) { *((int32_t*) (ptr + 4)) }; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 4)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + void random_get_random_bytes(uint64_t len, wasip2_list_u8_t *ret) { __attribute__((__aligned__(sizeof(void*)))) uint8_t ret_area[(2*sizeof(void*))]; diff --git a/libc-bottom-half/sources/wasip3.c b/libc-bottom-half/sources/wasip3.c index 5c8978312..f8de0c2ec 100644 --- a/libc-bottom-half/sources/wasip3.c +++ b/libc-bottom-half/sources/wasip3.c @@ -3,302 +3,302 @@ #include #include -// Imported Functions from `wasi:cli/environment@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/environment@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2025-09-16"), __import_name__("get-environment"))) +__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2026-01-06"), __import_name__("get-environment"))) extern void __wasm_import_environment_get_environment(uint8_t *); -__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2025-09-16"), __import_name__("get-arguments"))) +__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2026-01-06"), __import_name__("get-arguments"))) extern void __wasm_import_environment_get_arguments(uint8_t *); -__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2025-09-16"), __import_name__("get-initial-cwd"))) +__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2026-01-06"), __import_name__("get-initial-cwd"))) extern void __wasm_import_environment_get_initial_cwd(uint8_t *); -// Imported Functions from `wasi:cli/exit@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/exit@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/exit@0.3.0-rc-2025-09-16"), __import_name__("exit"))) +__attribute__((__import_module__("wasi:cli/exit@0.3.0-rc-2026-01-06"), __import_name__("exit"))) _Noreturn extern void __wasm_import_exit_exit(int32_t); -// Imported Functions from `wasi:cli/stdin@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/stdin@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("read-via-stream"))) extern void __wasm_import_stdin_read_via_stream(uint8_t *); -// Imported Functions from `wasi:cli/stdout@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/stdout@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/stdout@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]write-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdout@0.3.0-rc-2026-01-06"), __import_name__("[async-lower]write-via-stream"))) extern int32_t __wasm_import_stdout_write_via_stream(int32_t, uint8_t *); -// Imported Functions from `wasi:cli/stderr@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/stderr@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/stderr@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]write-via-stream"))) +__attribute__((__import_module__("wasi:cli/stderr@0.3.0-rc-2026-01-06"), __import_name__("[async-lower]write-via-stream"))) extern int32_t __wasm_import_stderr_write_via_stream(int32_t, uint8_t *); -// Imported Functions from `wasi:cli/terminal-stdin@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/terminal-stdin@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/terminal-stdin@0.3.0-rc-2025-09-16"), __import_name__("get-terminal-stdin"))) +__attribute__((__import_module__("wasi:cli/terminal-stdin@0.3.0-rc-2026-01-06"), __import_name__("get-terminal-stdin"))) extern void __wasm_import_terminal_stdin_get_terminal_stdin(uint8_t *); -// Imported Functions from `wasi:cli/terminal-stdout@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/terminal-stdout@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/terminal-stdout@0.3.0-rc-2025-09-16"), __import_name__("get-terminal-stdout"))) +__attribute__((__import_module__("wasi:cli/terminal-stdout@0.3.0-rc-2026-01-06"), __import_name__("get-terminal-stdout"))) extern void __wasm_import_terminal_stdout_get_terminal_stdout(uint8_t *); -// Imported Functions from `wasi:cli/terminal-stderr@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/terminal-stderr@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/terminal-stderr@0.3.0-rc-2025-09-16"), __import_name__("get-terminal-stderr"))) +__attribute__((__import_module__("wasi:cli/terminal-stderr@0.3.0-rc-2026-01-06"), __import_name__("get-terminal-stderr"))) extern void __wasm_import_terminal_stderr_get_terminal_stderr(uint8_t *); -// Imported Functions from `wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16"), __import_name__("now"))) +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06"), __import_name__("now"))) extern int64_t __wasm_import_monotonic_clock_now(void); -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16"), __import_name__("get-resolution"))) +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06"), __import_name__("get-resolution"))) extern int64_t __wasm_import_monotonic_clock_get_resolution(void); -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]wait-until"))) +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06"), __import_name__("[async-lower]wait-until"))) extern int32_t __wasm_import_monotonic_clock_wait_until(int64_t); -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]wait-for"))) +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06"), __import_name__("[async-lower]wait-for"))) extern int32_t __wasm_import_monotonic_clock_wait_for(int64_t); -// Imported Functions from `wasi:clocks/wall-clock@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:clocks/system-clock@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:clocks/wall-clock@0.3.0-rc-2025-09-16"), __import_name__("now"))) -extern void __wasm_import_wall_clock_now(uint8_t *); +__attribute__((__import_module__("wasi:clocks/system-clock@0.3.0-rc-2026-01-06"), __import_name__("now"))) +extern void __wasm_import_wasi_clocks_system_clock_now(uint8_t *); -__attribute__((__import_module__("wasi:clocks/wall-clock@0.3.0-rc-2025-09-16"), __import_name__("get-resolution"))) -extern void __wasm_import_wall_clock_get_resolution(uint8_t *); +__attribute__((__import_module__("wasi:clocks/system-clock@0.3.0-rc-2026-01-06"), __import_name__("get-resolution"))) +extern int64_t __wasm_import_wasi_clocks_system_clock_get_resolution(void); -// Imported Functions from `wasi:filesystem/types@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:filesystem/types@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[method]descriptor.read-via-stream"))) extern void __wasm_import_filesystem_method_descriptor_read_via_stream(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.write-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.write-via-stream"))) extern int32_t __wasm_import_filesystem_method_descriptor_write_via_stream(int32_t, int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.append-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.append-via-stream"))) extern int32_t __wasm_import_filesystem_method_descriptor_append_via_stream(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.advise"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.advise"))) extern int32_t __wasm_import_filesystem_method_descriptor_advise(int32_t, int64_t, int64_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.sync-data"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.sync-data"))) extern int32_t __wasm_import_filesystem_method_descriptor_sync_data(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.get-flags"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.get-flags"))) extern int32_t __wasm_import_filesystem_method_descriptor_get_flags(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.get-type"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.get-type"))) extern int32_t __wasm_import_filesystem_method_descriptor_get_type(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.set-size"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.set-size"))) extern int32_t __wasm_import_filesystem_method_descriptor_set_size(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.set-times"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.set-times"))) extern int32_t __wasm_import_filesystem_method_descriptor_set_times(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.read-directory"))) extern int32_t __wasm_import_filesystem_method_descriptor_read_directory(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.sync"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.sync"))) extern int32_t __wasm_import_filesystem_method_descriptor_sync(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.create-directory-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.create-directory-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_create_directory_at(int32_t, uint8_t *, size_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.stat"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.stat"))) extern int32_t __wasm_import_filesystem_method_descriptor_stat(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.stat-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.stat-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_stat_at(int32_t, int32_t, uint8_t *, size_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.set-times-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.set-times-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_set_times_at(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.link-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.link-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_link_at(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.open-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.open-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_open_at(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.readlink-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.readlink-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_readlink_at(int32_t, uint8_t *, size_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.remove-directory-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.remove-directory-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_remove_directory_at(int32_t, uint8_t *, size_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.rename-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.rename-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_rename_at(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.symlink-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.symlink-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_symlink_at(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.unlink-file-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.unlink-file-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_unlink_file_at(int32_t, uint8_t *, size_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.is-same-object"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.is-same-object"))) extern int32_t __wasm_import_filesystem_method_descriptor_is_same_object(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.metadata-hash"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.metadata-hash"))) extern int32_t __wasm_import_filesystem_method_descriptor_metadata_hash(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.metadata-hash-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.metadata-hash-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_metadata_hash_at(int32_t, int32_t, uint8_t *, size_t, uint8_t *); -// Imported Functions from `wasi:filesystem/preopens@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:filesystem/preopens@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:filesystem/preopens@0.3.0-rc-2025-09-16"), __import_name__("get-directories"))) +__attribute__((__import_module__("wasi:filesystem/preopens@0.3.0-rc-2026-01-06"), __import_name__("get-directories"))) extern void __wasm_import_filesystem_preopens_get_directories(uint8_t *); -// Imported Functions from `wasi:sockets/types@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:sockets/types@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[static]tcp-socket.create"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[static]tcp-socket.create"))) extern void __wasm_import_sockets_static_tcp_socket_create(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.bind"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.bind"))) extern void __wasm_import_sockets_method_tcp_socket_bind(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]tcp-socket.connect"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]tcp-socket.connect"))) extern int32_t __wasm_import_sockets_method_tcp_socket_connect(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.listen"))) extern void __wasm_import_sockets_method_tcp_socket_listen(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]tcp-socket.send"))) extern int32_t __wasm_import_sockets_method_tcp_socket_send(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.receive"))) extern void __wasm_import_sockets_method_tcp_socket_receive(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-local-address"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-local-address"))) extern void __wasm_import_sockets_method_tcp_socket_get_local_address(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-remote-address"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-remote-address"))) extern void __wasm_import_sockets_method_tcp_socket_get_remote_address(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-is-listening"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-is-listening"))) extern int32_t __wasm_import_sockets_method_tcp_socket_get_is_listening(int32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-address-family"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-address-family"))) extern int32_t __wasm_import_sockets_method_tcp_socket_get_address_family(int32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-listen-backlog-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-listen-backlog-size"))) extern void __wasm_import_sockets_method_tcp_socket_set_listen_backlog_size(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-keep-alive-enabled"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-keep-alive-enabled"))) extern void __wasm_import_sockets_method_tcp_socket_get_keep_alive_enabled(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-keep-alive-enabled"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-keep-alive-enabled"))) extern void __wasm_import_sockets_method_tcp_socket_set_keep_alive_enabled(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-keep-alive-idle-time"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-keep-alive-idle-time"))) extern void __wasm_import_sockets_method_tcp_socket_get_keep_alive_idle_time(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-keep-alive-idle-time"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-keep-alive-idle-time"))) extern void __wasm_import_sockets_method_tcp_socket_set_keep_alive_idle_time(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-keep-alive-interval"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-keep-alive-interval"))) extern void __wasm_import_sockets_method_tcp_socket_get_keep_alive_interval(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-keep-alive-interval"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-keep-alive-interval"))) extern void __wasm_import_sockets_method_tcp_socket_set_keep_alive_interval(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-keep-alive-count"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-keep-alive-count"))) extern void __wasm_import_sockets_method_tcp_socket_get_keep_alive_count(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-keep-alive-count"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-keep-alive-count"))) extern void __wasm_import_sockets_method_tcp_socket_set_keep_alive_count(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-hop-limit"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-hop-limit"))) extern void __wasm_import_sockets_method_tcp_socket_get_hop_limit(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-hop-limit"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-hop-limit"))) extern void __wasm_import_sockets_method_tcp_socket_set_hop_limit(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-receive-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-receive-buffer-size"))) extern void __wasm_import_sockets_method_tcp_socket_get_receive_buffer_size(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-receive-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-receive-buffer-size"))) extern void __wasm_import_sockets_method_tcp_socket_set_receive_buffer_size(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-send-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-send-buffer-size"))) extern void __wasm_import_sockets_method_tcp_socket_get_send_buffer_size(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-send-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-send-buffer-size"))) extern void __wasm_import_sockets_method_tcp_socket_set_send_buffer_size(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[static]udp-socket.create"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[static]udp-socket.create"))) extern void __wasm_import_sockets_static_udp_socket_create(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.bind"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.bind"))) extern void __wasm_import_sockets_method_udp_socket_bind(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.connect"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.connect"))) extern void __wasm_import_sockets_method_udp_socket_connect(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.disconnect"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.disconnect"))) extern void __wasm_import_sockets_method_udp_socket_disconnect(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]udp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]udp-socket.send"))) extern int32_t __wasm_import_sockets_method_udp_socket_send(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]udp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]udp-socket.receive"))) extern int32_t __wasm_import_sockets_method_udp_socket_receive(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-local-address"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.get-local-address"))) extern void __wasm_import_sockets_method_udp_socket_get_local_address(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-remote-address"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.get-remote-address"))) extern void __wasm_import_sockets_method_udp_socket_get_remote_address(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-address-family"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.get-address-family"))) extern int32_t __wasm_import_sockets_method_udp_socket_get_address_family(int32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-unicast-hop-limit"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.get-unicast-hop-limit"))) extern void __wasm_import_sockets_method_udp_socket_get_unicast_hop_limit(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.set-unicast-hop-limit"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.set-unicast-hop-limit"))) extern void __wasm_import_sockets_method_udp_socket_set_unicast_hop_limit(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-receive-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.get-receive-buffer-size"))) extern void __wasm_import_sockets_method_udp_socket_get_receive_buffer_size(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.set-receive-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.set-receive-buffer-size"))) extern void __wasm_import_sockets_method_udp_socket_set_receive_buffer_size(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-send-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.get-send-buffer-size"))) extern void __wasm_import_sockets_method_udp_socket_get_send_buffer_size(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.set-send-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.set-send-buffer-size"))) extern void __wasm_import_sockets_method_udp_socket_set_send_buffer_size(int32_t, int64_t, uint8_t *); -// Imported Functions from `wasi:sockets/ip-name-lookup@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:sockets/ip-name-lookup@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]resolve-addresses"))) +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.3.0-rc-2026-01-06"), __import_name__("[async-lower]resolve-addresses"))) extern int32_t __wasm_import_ip_name_lookup_resolve_addresses(uint8_t *, size_t, uint8_t *); -// Imported Functions from `wasi:random/random@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:random/random@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:random/random@0.3.0-rc-2025-09-16"), __import_name__("get-random-bytes"))) +__attribute__((__import_module__("wasi:random/random@0.3.0-rc-2026-01-06"), __import_name__("get-random-bytes"))) extern void __wasm_import_random_get_random_bytes(int64_t, uint8_t *); -__attribute__((__import_module__("wasi:random/random@0.3.0-rc-2025-09-16"), __import_name__("get-random-u64"))) +__attribute__((__import_module__("wasi:random/random@0.3.0-rc-2026-01-06"), __import_name__("get-random-u64"))) extern int64_t __wasm_import_random_get_random_u64(void); -// Imported Functions from `wasi:random/insecure@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:random/insecure@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:random/insecure@0.3.0-rc-2025-09-16"), __import_name__("get-insecure-random-bytes"))) +__attribute__((__import_module__("wasi:random/insecure@0.3.0-rc-2026-01-06"), __import_name__("get-insecure-random-bytes"))) extern void __wasm_import_random_insecure_get_insecure_random_bytes(int64_t, uint8_t *); -__attribute__((__import_module__("wasi:random/insecure@0.3.0-rc-2025-09-16"), __import_name__("get-insecure-random-u64"))) +__attribute__((__import_module__("wasi:random/insecure@0.3.0-rc-2026-01-06"), __import_name__("get-insecure-random-u64"))) extern int64_t __wasm_import_random_insecure_get_insecure_random_u64(void); -// Imported Functions from `wasi:random/insecure-seed@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:random/insecure-seed@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:random/insecure-seed@0.3.0-rc-2025-09-16"), __import_name__("get-insecure-seed"))) +__attribute__((__import_module__("wasi:random/insecure-seed@0.3.0-rc-2026-01-06"), __import_name__("get-insecure-seed"))) extern void __wasm_import_random_insecure_seed_get_insecure_seed(uint8_t *); // Canonical ABI intrinsics @@ -358,19 +358,19 @@ void stdin_result_void_error_code_free(stdin_result_void_error_code_t *ptr) { } } -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[stream-new-0]read-via-stream"))) extern uint64_t stdin_stream_u8__new(void); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-read-0]read-via-stream"))) extern uint32_t stdin_stream_u8__read(uint32_t, uint8_t*, size_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-write-0]read-via-stream"))) extern uint32_t stdin_stream_u8__write(uint32_t, const uint8_t*, size_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-read-0]read-via-stream"))) extern uint32_t stdin_stream_u8__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-write-0]read-via-stream"))) extern uint32_t stdin_stream_u8__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-readable-0]read-via-stream"))) extern void stdin_stream_u8__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-writable-0]read-via-stream"))) extern void stdin_stream_u8__drop_writable(uint32_t); stdin_stream_u8_t stdin_stream_u8_new(stdin_stream_u8_writer_t *writer) { @@ -404,19 +404,19 @@ void stdin_stream_u8_drop_writable(stdin_stream_u8_writer_t writer) { } -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-new-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[future-new-1]read-via-stream"))) extern uint64_t stdin_future_result_void_error_code__new(void); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-read-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][future-read-1]read-via-stream"))) extern uint32_t stdin_future_result_void_error_code__read(uint32_t, uint8_t*); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-write-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][future-write-1]read-via-stream"))) extern uint32_t stdin_future_result_void_error_code__write(uint32_t, const uint8_t*); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-read-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[future-cancel-read-1]read-via-stream"))) extern uint32_t stdin_future_result_void_error_code__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-write-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[future-cancel-write-1]read-via-stream"))) extern uint32_t stdin_future_result_void_error_code__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-readable-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[future-drop-readable-1]read-via-stream"))) extern void stdin_future_result_void_error_code__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-writable-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[future-drop-writable-1]read-via-stream"))) extern void stdin_future_result_void_error_code__drop_writable(uint32_t); stdin_future_result_void_error_code_t stdin_future_result_void_error_code_new(stdin_future_result_void_error_code_writer_t *writer) { @@ -462,7 +462,7 @@ void stderr_result_void_error_code_free(stderr_result_void_error_code_t *ptr) { } } -__attribute__((__import_module__("wasi:cli/terminal-input@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]terminal-input"))) +__attribute__((__import_module__("wasi:cli/terminal-input@0.3.0-rc-2026-01-06"), __import_name__("[resource-drop]terminal-input"))) extern void __wasm_import_terminal_input_terminal_input_drop(int32_t handle); void terminal_input_terminal_input_drop_own(terminal_input_own_terminal_input_t handle) { @@ -473,7 +473,7 @@ terminal_input_borrow_terminal_input_t terminal_input_borrow_terminal_input(term return (terminal_input_borrow_terminal_input_t) { arg.__handle }; } -__attribute__((__import_module__("wasi:cli/terminal-output@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]terminal-output"))) +__attribute__((__import_module__("wasi:cli/terminal-output@0.3.0-rc-2026-01-06"), __import_name__("[resource-drop]terminal-output"))) extern void __wasm_import_terminal_output_terminal_output_drop(int32_t handle); void terminal_output_terminal_output_drop_own(terminal_output_own_terminal_output_t handle) { @@ -499,15 +499,15 @@ void terminal_stderr_option_own_terminal_output_free(terminal_stderr_option_own_ } } -void filesystem_option_datetime_free(filesystem_option_datetime_t *ptr) { +void filesystem_option_instant_free(filesystem_option_instant_t *ptr) { if (ptr->is_some) { } } void filesystem_descriptor_stat_free(filesystem_descriptor_stat_t *ptr) { - filesystem_option_datetime_free(&ptr->data_access_timestamp); - filesystem_option_datetime_free(&ptr->data_modification_timestamp); - filesystem_option_datetime_free(&ptr->status_change_timestamp); + filesystem_option_instant_free(&ptr->data_access_timestamp); + filesystem_option_instant_free(&ptr->data_modification_timestamp); + filesystem_option_instant_free(&ptr->status_change_timestamp); } void filesystem_new_timestamp_free(filesystem_new_timestamp_t *ptr) { @@ -522,7 +522,7 @@ void filesystem_directory_entry_free(filesystem_directory_entry_t *ptr) { wasip3_string_free(&ptr->name); } -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]descriptor"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[resource-drop]descriptor"))) extern void __wasm_import_filesystem_descriptor_drop(int32_t handle); void filesystem_descriptor_drop_own(filesystem_own_descriptor_t handle) { @@ -577,19 +577,19 @@ void filesystem_result_metadata_hash_value_error_code_free(filesystem_result_met } } -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-new-0][method]descriptor.read-via-stream"))) extern uint64_t filesystem_stream_u8__new(void); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-read-0][method]descriptor.read-via-stream"))) extern uint32_t filesystem_stream_u8__read(uint32_t, uint8_t*, size_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-write-0][method]descriptor.read-via-stream"))) extern uint32_t filesystem_stream_u8__write(uint32_t, const uint8_t*, size_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-read-0][method]descriptor.read-via-stream"))) extern uint32_t filesystem_stream_u8__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-write-0][method]descriptor.read-via-stream"))) extern uint32_t filesystem_stream_u8__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-readable-0][method]descriptor.read-via-stream"))) extern void filesystem_stream_u8__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-writable-0][method]descriptor.read-via-stream"))) extern void filesystem_stream_u8__drop_writable(uint32_t); filesystem_stream_u8_t filesystem_stream_u8_new(filesystem_stream_u8_writer_t *writer) { @@ -623,19 +623,19 @@ void filesystem_stream_u8_drop_writable(filesystem_stream_u8_writer_t writer) { } -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-new-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[future-new-1][method]descriptor.read-via-stream"))) extern uint64_t filesystem_future_result_void_error_code__new(void); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-read-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][future-read-1][method]descriptor.read-via-stream"))) extern uint32_t filesystem_future_result_void_error_code__read(uint32_t, uint8_t*); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-write-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][future-write-1][method]descriptor.read-via-stream"))) extern uint32_t filesystem_future_result_void_error_code__write(uint32_t, const uint8_t*); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-read-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[future-cancel-read-1][method]descriptor.read-via-stream"))) extern uint32_t filesystem_future_result_void_error_code__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-write-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[future-cancel-write-1][method]descriptor.read-via-stream"))) extern uint32_t filesystem_future_result_void_error_code__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-readable-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[future-drop-readable-1][method]descriptor.read-via-stream"))) extern void filesystem_future_result_void_error_code__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-writable-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[future-drop-writable-1][method]descriptor.read-via-stream"))) extern void filesystem_future_result_void_error_code__drop_writable(uint32_t); filesystem_future_result_void_error_code_t filesystem_future_result_void_error_code_new(filesystem_future_result_void_error_code_writer_t *writer) { @@ -669,19 +669,19 @@ void filesystem_future_result_void_error_code_drop_writable(filesystem_future_re } -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-new-0][method]descriptor.read-directory"))) extern uint64_t filesystem_stream_directory_entry__new(void); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-read-0][method]descriptor.read-directory"))) extern uint32_t filesystem_stream_directory_entry__read(uint32_t, uint8_t*, size_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-write-0][method]descriptor.read-directory"))) extern uint32_t filesystem_stream_directory_entry__write(uint32_t, const uint8_t*, size_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-read-0][method]descriptor.read-directory"))) extern uint32_t filesystem_stream_directory_entry__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-write-0][method]descriptor.read-directory"))) extern uint32_t filesystem_stream_directory_entry__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-readable-0][method]descriptor.read-directory"))) extern void filesystem_stream_directory_entry__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-writable-0][method]descriptor.read-directory"))) extern void filesystem_stream_directory_entry__drop_writable(uint32_t); filesystem_stream_directory_entry_t filesystem_stream_directory_entry_new(filesystem_stream_directory_entry_writer_t *writer) { @@ -752,7 +752,7 @@ void sockets_ip_socket_address_free(sockets_ip_socket_address_t *ptr) { } } -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]tcp-socket"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[resource-drop]tcp-socket"))) extern void __wasm_import_sockets_tcp_socket_drop(int32_t handle); void sockets_tcp_socket_drop_own(sockets_own_tcp_socket_t handle) { @@ -763,7 +763,7 @@ sockets_borrow_tcp_socket_t sockets_borrow_tcp_socket(sockets_own_tcp_socket_t a return (sockets_borrow_tcp_socket_t) { arg.__handle }; } -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]udp-socket"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[resource-drop]udp-socket"))) extern void __wasm_import_sockets_udp_socket_drop(int32_t handle); void sockets_udp_socket_drop_own(sockets_own_udp_socket_t handle) { @@ -863,19 +863,19 @@ void sockets_result_tuple2_list_u8_ip_socket_address_error_code_free(sockets_res } } -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-new-0][method]tcp-socket.listen"))) extern uint64_t sockets_stream_own_tcp_socket__new(void); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-read-0][method]tcp-socket.listen"))) extern uint32_t sockets_stream_own_tcp_socket__read(uint32_t, uint8_t*, size_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-write-0][method]tcp-socket.listen"))) extern uint32_t sockets_stream_own_tcp_socket__write(uint32_t, const uint8_t*, size_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-read-0][method]tcp-socket.listen"))) extern uint32_t sockets_stream_own_tcp_socket__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-write-0][method]tcp-socket.listen"))) extern uint32_t sockets_stream_own_tcp_socket__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-readable-0][method]tcp-socket.listen"))) extern void sockets_stream_own_tcp_socket__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-writable-0][method]tcp-socket.listen"))) extern void sockets_stream_own_tcp_socket__drop_writable(uint32_t); sockets_stream_own_tcp_socket_t sockets_stream_own_tcp_socket_new(sockets_stream_own_tcp_socket_writer_t *writer) { @@ -909,19 +909,19 @@ void sockets_stream_own_tcp_socket_drop_writable(sockets_stream_own_tcp_socket_w } -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-new-0][method]tcp-socket.send"))) extern uint64_t sockets_stream_u8__new(void); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-read-0][method]tcp-socket.send"))) extern uint32_t sockets_stream_u8__read(uint32_t, uint8_t*, size_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-write-0][method]tcp-socket.send"))) extern uint32_t sockets_stream_u8__write(uint32_t, const uint8_t*, size_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-read-0][method]tcp-socket.send"))) extern uint32_t sockets_stream_u8__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-write-0][method]tcp-socket.send"))) extern uint32_t sockets_stream_u8__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-readable-0][method]tcp-socket.send"))) extern void sockets_stream_u8__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-writable-0][method]tcp-socket.send"))) extern void sockets_stream_u8__drop_writable(uint32_t); sockets_stream_u8_t sockets_stream_u8_new(sockets_stream_u8_writer_t *writer) { @@ -955,19 +955,19 @@ void sockets_stream_u8_drop_writable(sockets_stream_u8_writer_t writer) { } -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-new-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[future-new-1][method]tcp-socket.receive"))) extern uint64_t sockets_future_result_void_error_code__new(void); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-read-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][future-read-1][method]tcp-socket.receive"))) extern uint32_t sockets_future_result_void_error_code__read(uint32_t, uint8_t*); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-write-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][future-write-1][method]tcp-socket.receive"))) extern uint32_t sockets_future_result_void_error_code__write(uint32_t, const uint8_t*); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-read-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[future-cancel-read-1][method]tcp-socket.receive"))) extern uint32_t sockets_future_result_void_error_code__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-write-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[future-cancel-write-1][method]tcp-socket.receive"))) extern uint32_t sockets_future_result_void_error_code__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-readable-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[future-drop-readable-1][method]tcp-socket.receive"))) extern void sockets_future_result_void_error_code__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-writable-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[future-drop-writable-1][method]tcp-socket.receive"))) extern void sockets_future_result_void_error_code__drop_writable(uint32_t); sockets_future_result_void_error_code_t sockets_future_result_void_error_code_new(sockets_future_result_void_error_code_writer_t *writer) { @@ -1359,7 +1359,7 @@ bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t * return option.is_some; } -monotonic_clock_instant_t monotonic_clock_now(void) { +monotonic_clock_mark_t monotonic_clock_now(void) { int64_t ret = __wasm_import_monotonic_clock_now(); return (uint64_t) (ret); } @@ -1369,7 +1369,7 @@ monotonic_clock_duration_t monotonic_clock_get_resolution(void) { return (uint64_t) (ret); } -wasip3_subtask_status_t monotonic_clock_wait_until(monotonic_clock_instant_t when) { +wasip3_subtask_status_t monotonic_clock_wait_until(monotonic_clock_mark_t when) { return __wasm_import_monotonic_clock_wait_until((int64_t) (when)); } @@ -1377,26 +1377,20 @@ wasip3_subtask_status_t monotonic_clock_wait_for(monotonic_clock_duration_t how_ return __wasm_import_monotonic_clock_wait_for((int64_t) (how_long)); } -void wall_clock_now(wall_clock_datetime_t *ret) { +void wasi_clocks_system_clock_now(wasi_clocks_system_clock_instant_t *ret) { __attribute__((__aligned__(8))) uint8_t ret_area[16]; uint8_t *ptr = (uint8_t *) &ret_area; - __wasm_import_wall_clock_now(ptr); - *ret = (wall_clock_datetime_t) { - (uint64_t) (uint64_t) (*((int64_t*) (ptr + 0))), + __wasm_import_wasi_clocks_system_clock_now(ptr); + *ret = (wasi_clocks_system_clock_instant_t) { + (int64_t) *((int64_t*) (ptr + 0)), (uint32_t) (uint32_t) (*((int32_t*) (ptr + 8))), }; } -void wall_clock_get_resolution(wall_clock_datetime_t *ret) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - uint8_t *ptr = (uint8_t *) &ret_area; - __wasm_import_wall_clock_get_resolution(ptr); - *ret = (wall_clock_datetime_t) { - (uint64_t) (uint64_t) (*((int64_t*) (ptr + 0))), - (uint32_t) (uint32_t) (*((int32_t*) (ptr + 8))), - }; +wasi_clocks_system_clock_duration_t wasi_clocks_system_clock_get_resolution(void) { + int64_t ret = __wasm_import_wasi_clocks_system_clock_get_resolution(); + return (uint64_t) (ret); } void filesystem_method_descriptor_read_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_tuple2_stream_u8_future_result_void_error_code_t *ret) { diff --git a/libc-bottom-half/sources/wasip3_component_type.o b/libc-bottom-half/sources/wasip3_component_type.o index 1bbc77162df643e996ee21d74433728d8365bc09..68f4f3604b601e2b750b65bc5532d01a799cf67a 100644 GIT binary patch delta 482 zcmbPZzu10)B;(nMQf?d@Z5bVz7#$5KX4J8n=^7a78ccj+3uR5#XAFfgyBLc(A@XLd zER*w@0w#ws3BV+Cn37@4t4t0srZlq?jG4?_4P!oGu7@!*S+ZfwTP)@D@$%- zQTAj{)=mqUodS$b98AnijQlJN94Vzmi6xo&dCUw9j73cB#i_~pc`3ye+zNZ)LdOK&%r>?SkFMWC|TFYzzAlEAQLkKFMDQQ zaYiH&^Q6E%mUrS zl$4^>;$o;5#3%2Pc@7UuiOH*EuvC+DLNGftX?K?UlaO#RHKa(;8cuv;3uR5#XAFfgyBLc(A@XLd zER*w@0w#ws3BV+Cn37@4t4t0srZlq?jG4?_4P!oGu7@!*S+ZfwTP)@CF4iwk%*oLOvmFfdjP(q3 zi;{JX42&QaE1R(j0yXf$&1ZCqWMXDw6hg9ca|hc}E|}Ym1{JNSDYki+;Bzhom>O}Q8Ue1%0^P)v6rdxE8J##lsw5^Klz9#hZpq0TW#i#IsmYRZ Yh^UaBJXOvIE+;ejm7D_1EduhB0q}@;&j0`b diff --git a/wasi/wasi-libc-wasip2.wit b/wasi/wasi-libc-wasip2.wit new file mode 100644 index 000000000..a3b1657e2 --- /dev/null +++ b/wasi/wasi-libc-wasip2.wit @@ -0,0 +1,5 @@ +package wasi-libc:wasip2; + +world wasip3 { + include wasi:cli/command@0.2.0; +} \ No newline at end of file diff --git a/wasi/wasi-libc-wasip3.wit b/wasi/wasi-libc-wasip3.wit new file mode 100644 index 000000000..68726e260 --- /dev/null +++ b/wasi/wasi-libc-wasip3.wit @@ -0,0 +1,10 @@ +package wasi-libc:wasip3; + +world wasip3 { + include wasi:cli/command@0.3.0-rc-2026-01-06; + include wasi:clocks/imports@0.3.0-rc-2026-01-06; + include wasi:filesystem/imports@0.3.0-rc-2026-01-06; + include wasi:http/middleware@0.3.0-rc-2026-01-06; + include wasi:random/imports@0.3.0-rc-2026-01-06; + include wasi:sockets/imports@0.3.0-rc-2026-01-06; +} \ No newline at end of file From a2fd15ba38f89aaf0aeccce608db0134c5e33f2e Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Wed, 14 Jan 2026 16:55:20 +0000 Subject: [PATCH 22/41] Update bindings generation and WASIP3 --- cmake/bindings.cmake | 79 +- libc-bottom-half/CMakeLists.txt | 2 +- libc-bottom-half/cloudlibc/src/common/time.h | 9 +- .../cloudlibc/src/libc/sys/stat/stat_impl.h | 3 + .../src/libc/sys/time/gettimeofday.c | 6 +- .../cloudlibc/src/libc/time/clock_gettime.c | 8 +- .../cloudlibc/src/libc/time/time.c | 8 +- libc-bottom-half/crt/crt1-command.c | 2 +- .../headers/public/wasi/__generated_wasip2.h | 1262 +---------------- .../headers/public/wasi/__generated_wasip3.h | 121 +- libc-bottom-half/sources/wasip2.c | 80 +- .../sources/wasip2_component_type.o | Bin 10846 -> 10846 bytes libc-bottom-half/sources/wasip3.c | 405 +++--- .../sources/wasip3_component_type.o | Bin 8092 -> 8099 bytes wasi/wasi-libc-wasip2.wit | 5 + wasi/wasi-libc-wasip3.wit | 10 + 16 files changed, 419 insertions(+), 1581 deletions(-) create mode 100644 wasi/wasi-libc-wasip2.wit create mode 100644 wasi/wasi-libc-wasip3.wit diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index 016cf398d..8d81d6f1b 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -15,8 +15,8 @@ if(WIT_BINDGEN_EXECUTABLE) OUTPUT_VARIABLE WIT_BINDGEN_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) - if (NOT (WIT_BINDGEN_VERSION MATCHES "0\\.48\\.0")) - message(WARNING "wit-bindgen version 0.48.0 is required, found: ${WIT_BINDGEN_VERSION}") + if (NOT (WIT_BINDGEN_VERSION MATCHES "0\\.51\\.0")) + message(WARNING "wit-bindgen version 0.51.0 is required, found: ${WIT_BINDGEN_VERSION}") set(WIT_BINDGEN_EXECUTABLE "") endif() endif() @@ -26,7 +26,7 @@ if (NOT WIT_BINDGEN_EXECUTABLE) ba_download( wit-bindgen "https://github.com/bytecodealliance/wit-bindgen" - "0.48.0" + "0.51.0" ) ExternalProject_Get_Property(wit-bindgen SOURCE_DIR) set(wit_bindgen "${SOURCE_DIR}/wit-bindgen") @@ -35,20 +35,48 @@ else() set(wit_bindgen ${WIT_BINDGEN_EXECUTABLE}) endif() -include(ExternalProject) +# If `wkg` is on the system and has the right version, favor that, +# otherwise download a known good version. +find_program(WKG_EXECUTABLE NAMES wkg) +if(WKG_EXECUTABLE) + message(STATUS "Found wkg: ${WKG_EXECUTABLE}") + + execute_process( + COMMAND ${WKG_EXECUTABLE} --version + OUTPUT_VARIABLE WKG_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE) + + if (NOT (WKG_VERSION MATCHES "0\\.13\\.0")) + message(WARNING "wkg version 0.13.0 is required, found: ${WKG_VERSION}") + set(WKG_EXECUTABLE "") + endif() +endif() + +if (NOT WKG_EXECUTABLE) + include(ba-download) + ba_download( + wit-bindgen + "https://github.com/bytecodealliance/wasm-pkg-tools" + "0.13.0" + ) + ExternalProject_Get_Property(wkg SOURCE_DIR) + set(wkg "${SOURCE_DIR}/wkg") +else() + add_custom_target(wkg) + set(wkg ${WKG_EXECUTABLE}) +endif() + +set(bottom_half "${CMAKE_SOURCE_DIR}/libc-bottom-half") + +set(wasip2_wit_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi/p2/wit) set(p2 0.2.0) -ExternalProject_Add( +file(MAKE_DIRECTORY ${wasip2_wit_dir}) +configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip2.wit ${wasip2_wit_dir} COPYONLY) +add_custom_target( wasip2-wits - URL https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v${p2}.tar.gz - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - EXCLUDE_FROM_ALL TRUE + COMMAND ${wkg} wit fetch + WORKING_DIRECTORY ${wasip2_wit_dir}/.. ) -ExternalProject_Get_Property(wasip2-wits SOURCE_DIR) -set(wasip2_wit_dir ${SOURCE_DIR}/wit) -set(bottom_half "${CMAKE_SOURCE_DIR}/libc-bottom-half") - add_custom_target( bindings-p2 COMMAND @@ -91,18 +119,15 @@ add_custom_target( DEPENDS wit-bindgen wasip2-wits ) -set(p3 0.3.0-rc-2025-09-16) -ExternalProject_Add( +set(wasip3_wit_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi/p3/wit) +set(p3 0.3.0-rc-2026-01-06) +file(MAKE_DIRECTORY ${wasip3_wit_dir}) +configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip3.wit ${wasip3_wit_dir} COPYONLY) +add_custom_target( wasip3-wits - URL https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v${p3}.tar.gz - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - EXCLUDE_FROM_ALL TRUE + COMMAND ${wkg} wit fetch + WORKING_DIRECTORY ${wasip3_wit_dir}/.. ) -ExternalProject_Get_Property(wasip3-wits SOURCE_DIR) -set(wasip3_wit_dir ${SOURCE_DIR}/wit-0.3.0-draft) - add_custom_target( bindings-p3 COMMAND @@ -142,9 +167,9 @@ add_custom_target(bindings DEPENDS bindings-p2 bindings-p3) function(wit_bindgen_edit p) add_custom_target( bindings-${p}-edit - COMMAND sed -i "" "'s_#include .wasi${p}\.h._#include \"wasi/wasi${p}.h\"_'" ${bottom_half}/sources/wasi${p}.c - COMMAND sed -i "" "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/__generated_wasi${p}.h - COMMAND sed -i "" "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasi${p}.c + COMMAND sed -i '' "'s_#include .wasi${p}\.h._#include \"wasi/wasi${p}.h\"_'" ${bottom_half}/sources/wasi${p}.c + COMMAND sed -i '' "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/__generated_wasi${p}.h + COMMAND sed -i '' "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasi${p}.c DEPENDS bindings-${p} ) add_dependencies(bindings bindings-${p}-edit) diff --git a/libc-bottom-half/CMakeLists.txt b/libc-bottom-half/CMakeLists.txt index b6445f924..b4fae0e64 100644 --- a/libc-bottom-half/CMakeLists.txt +++ b/libc-bottom-half/CMakeLists.txt @@ -248,7 +248,7 @@ elseif (WASI STREQUAL "p3") ${wasm_tools} component embed ${wasip3_wit_dir} $ - --world wasi:cli/command@0.3.0-rc-2025-09-16 + --world wasi:cli/command@0.3.0-rc-2026-01-06 -o ${SYSROOT_LIB}/crt1-command.o DEPENDS crt1-command wasip3-wits $ wasm-tools ) diff --git a/libc-bottom-half/cloudlibc/src/common/time.h b/libc-bottom-half/cloudlibc/src/common/time.h index ece306e5a..9c5ae4877 100644 --- a/libc-bottom-half/cloudlibc/src/common/time.h +++ b/libc-bottom-half/cloudlibc/src/common/time.h @@ -18,8 +18,11 @@ #if defined(__wasip1__) typedef __wasi_timestamp_t wasilibc_timestamp_t; -#elif defined(__wasip2__) || defined(__wasip3__) +#elif defined(__wasip2__) typedef wall_clock_datetime_t wasilibc_timestamp_t; +#elif defined(__wasip3__) +typedef filesystem_instant_t wasilibc_timestamp_t; +typedef monotonic_clock_mark_t monotonic_clock_instant_t; #else # error "Unknown WASI version" #endif @@ -95,7 +98,7 @@ static inline struct timeval timestamp_to_timeval( #elif defined(__wasip2__) || defined(__wasip3__) static inline struct timespec timestamp_to_timespec( - wall_clock_datetime_t *timestamp) { + wasilibc_timestamp_t *timestamp) { return (struct timespec){.tv_sec = timestamp->seconds, .tv_nsec = timestamp->nanoseconds}; } @@ -155,7 +158,7 @@ static inline bool timeval_to_duration( } static inline struct timeval timestamp_to_timeval( - wall_clock_datetime_t *timestamp) { + wasilibc_timestamp_t *timestamp) { return (struct timeval){.tv_sec = timestamp->seconds, .tv_usec = timestamp->nanoseconds / 1000}; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h b/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h index 504b6ba7e..807eab164 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h @@ -66,6 +66,9 @@ static inline void to_public_stat(const __wasi_filestat_t *in, } } #elif defined(__wasip2__) || defined(__wasip3__) +#ifdef __wasip3__ +typedef filesystem_instant_t filesystem_datetime_t; +#endif static inline void to_public_stat(const filesystem_metadata_hash_value_t *metadata, const filesystem_descriptor_stat_t *in, struct stat *out) { diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c b/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c index 08592fe92..3c27aa93a 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c @@ -12,10 +12,14 @@ int gettimeofday(struct timeval *restrict tp, void *tz) { __wasi_timestamp_t ts = 0; (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts); *tp = timestamp_to_timeval(ts); -#elif defined(__wasip2__) || defined(__wasip3__) +#elif defined(__wasip2__) wall_clock_datetime_t time_result; wall_clock_now(&time_result); *tp = timestamp_to_timeval(&time_result); +#elif defined(__wasip3__) + wasi_clocks_system_clock_instant_t time_result; + wasi_clocks_system_clock_now(&time_result); + *tp = timestamp_to_timeval(&time_result); #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c b/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c index 4619c169e..ae8eef0fe 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c @@ -25,12 +25,16 @@ int __clock_gettime(clockid_t clock_id, struct timespec *tp) { monotonic_clock_instant_t ns = monotonic_clock_now(); *tp = instant_to_timespec(ns); } else if (clock_id == CLOCK_REALTIME) { - wall_clock_datetime_t time_result; + wasilibc_timestamp_t time_result; + #ifdef __wasip2__ wall_clock_now(&time_result); + #else + wasi_clocks_system_clock_now(&time_result); + #endif *tp = timestamp_to_timespec(&time_result); } else { errno = EINVAL; - return -1; // wasip2 only supports wall and monotonic clocks + return -1; // wasip{2,3} only supports wall and monotonic clocks } #else # error "Unsupported WASI version" diff --git a/libc-bottom-half/cloudlibc/src/libc/time/time.c b/libc-bottom-half/cloudlibc/src/libc/time/time.c index 96c09b35a..d3fceb5c2 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/time.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/time.c @@ -10,10 +10,14 @@ time_t time(time_t *tloc) { #if defined(__wasip1__) __wasi_timestamp_t ts = 0; (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, NSEC_PER_SEC, &ts); -#elif defined(__wasip2__) || defined(__wasip3__) - wall_clock_datetime_t res; +#elif defined(__wasip2__) + wasilibc_timestamp_t res; wall_clock_now(&res); uint64_t ts = (res.seconds * NSEC_PER_SEC) + res.nanoseconds; +#elif defined(__wasip3__) + wasilibc_timestamp_t res; + wasi_clocks_system_clock_now(&res); + uint64_t ts = (res.seconds * NSEC_PER_SEC) + res.nanoseconds; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/crt/crt1-command.c b/libc-bottom-half/crt/crt1-command.c index 63e556779..6ef297592 100644 --- a/libc-bottom-half/crt/crt1-command.c +++ b/libc-bottom-half/crt/crt1-command.c @@ -18,7 +18,7 @@ __attribute__((export_name("_start"))) void _start(void) // that this shouldn't be too problematic (in theory). __attribute__((export_name("wasi:cli/run@0.2.0#run"))) int _start(void) #elif defined(__wasip3__) -__attribute__((export_name("wasi:cli/run@0.3.0-rc-2025-09-16#run"))) int +__attribute__((export_name("wasi:cli/run@0.3.0-rc-2026-01-06#run"))) int _start(void) #else #error "Unsupported WASI version" diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip2.h b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h index 54ffac264..ffd7e86f7 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip2.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.48.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! #ifndef __BINDINGS_WASIP2_H #define __BINDINGS_WASIP2_H #ifdef __cplusplus @@ -66,7 +66,6 @@ typedef struct { typedef io_error_own_error_t streams_own_error_t; -// An error for input-stream and output-stream operations. typedef struct streams_stream_error_t { uint8_t tag; union { @@ -74,13 +73,7 @@ typedef struct streams_stream_error_t { } val; } streams_stream_error_t; -// The last operation (a write or flush) failed before completion. -// -// More information is available in the `error` payload. #define STREAMS_STREAM_ERROR_LAST_OPERATION_FAILED 0 -// The stream is closed: no more input will be accepted by the -// stream. A closed output-stream will return this error on all -// future operations. #define STREAMS_STREAM_ERROR_CLOSED 1 typedef struct streams_own_input_stream_t { @@ -172,17 +165,12 @@ typedef struct { terminal_stderr_own_terminal_output_t val; } terminal_stderr_option_own_terminal_output_t; -// An instant in time, in nanoseconds. An instant is relative to an -// unspecified initial value, and can only be compared to instances from -// the same monotonic-clock. typedef uint64_t monotonic_clock_instant_t; -// A duration of time, in nanoseconds. typedef uint64_t monotonic_clock_duration_t; typedef poll_own_pollable_t monotonic_clock_own_pollable_t; -// A time and date in seconds plus nanoseconds. typedef struct wall_clock_datetime_t { uint64_t seconds; uint32_t nanoseconds; @@ -190,95 +178,39 @@ typedef struct wall_clock_datetime_t { typedef wall_clock_datetime_t filesystem_datetime_t; -// File size or length of a region within a file. typedef uint64_t filesystem_filesize_t; -// The type of a filesystem object referenced by a descriptor. -// -// Note: This was called `filetype` in earlier versions of WASI. typedef uint8_t filesystem_descriptor_type_t; -// The type of the descriptor or file is unknown or is different from -// any of the other types specified. #define FILESYSTEM_DESCRIPTOR_TYPE_UNKNOWN 0 -// The descriptor refers to a block device inode. #define FILESYSTEM_DESCRIPTOR_TYPE_BLOCK_DEVICE 1 -// The descriptor refers to a character device inode. #define FILESYSTEM_DESCRIPTOR_TYPE_CHARACTER_DEVICE 2 -// The descriptor refers to a directory inode. #define FILESYSTEM_DESCRIPTOR_TYPE_DIRECTORY 3 -// The descriptor refers to a named pipe. #define FILESYSTEM_DESCRIPTOR_TYPE_FIFO 4 -// The file refers to a symbolic link inode. #define FILESYSTEM_DESCRIPTOR_TYPE_SYMBOLIC_LINK 5 -// The descriptor refers to a regular file inode. #define FILESYSTEM_DESCRIPTOR_TYPE_REGULAR_FILE 6 -// The descriptor refers to a socket. #define FILESYSTEM_DESCRIPTOR_TYPE_SOCKET 7 -// Descriptor flags. -// -// Note: This was called `fdflags` in earlier versions of WASI. typedef uint8_t filesystem_descriptor_flags_t; -// Read mode: Data can be read. #define FILESYSTEM_DESCRIPTOR_FLAGS_READ (1 << 0) -// Write mode: Data can be written to. #define FILESYSTEM_DESCRIPTOR_FLAGS_WRITE (1 << 1) -// Request that writes be performed according to synchronized I/O file -// integrity completion. The data stored in the file and the file's -// metadata are synchronized. This is similar to `O_SYNC` in POSIX. -// -// The precise semantics of this operation have not yet been defined for -// WASI. At this time, it should be interpreted as a request, and not a -// requirement. #define FILESYSTEM_DESCRIPTOR_FLAGS_FILE_INTEGRITY_SYNC (1 << 2) -// Request that writes be performed according to synchronized I/O data -// integrity completion. Only the data stored in the file is -// synchronized. This is similar to `O_DSYNC` in POSIX. -// -// The precise semantics of this operation have not yet been defined for -// WASI. At this time, it should be interpreted as a request, and not a -// requirement. #define FILESYSTEM_DESCRIPTOR_FLAGS_DATA_INTEGRITY_SYNC (1 << 3) -// Requests that reads be performed at the same level of integrety -// requested for writes. This is similar to `O_RSYNC` in POSIX. -// -// The precise semantics of this operation have not yet been defined for -// WASI. At this time, it should be interpreted as a request, and not a -// requirement. #define FILESYSTEM_DESCRIPTOR_FLAGS_REQUESTED_WRITE_SYNC (1 << 4) -// Mutating directories mode: Directory contents may be mutated. -// -// When this flag is unset on a descriptor, operations using the -// descriptor which would create, rename, delete, modify the data or -// metadata of filesystem objects, or obtain another handle which -// would permit any of those, shall fail with `error-code::read-only` if -// they would otherwise succeed. -// -// This may only be set on directories. #define FILESYSTEM_DESCRIPTOR_FLAGS_MUTATE_DIRECTORY (1 << 5) -// Flags determining the method of how paths are resolved. typedef uint8_t filesystem_path_flags_t; -// As long as the resolved path corresponds to a symbolic link, it is -// expanded. #define FILESYSTEM_PATH_FLAGS_SYMLINK_FOLLOW (1 << 0) -// Open flags used by `open-at`. typedef uint8_t filesystem_open_flags_t; -// Create file if it does not exist, similar to `O_CREAT` in POSIX. #define FILESYSTEM_OPEN_FLAGS_CREATE (1 << 0) -// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. #define FILESYSTEM_OPEN_FLAGS_DIRECTORY (1 << 1) -// Fail if file already exists, similar to `O_EXCL` in POSIX. #define FILESYSTEM_OPEN_FLAGS_EXCLUSIVE (1 << 2) -// Truncate file to size 0, similar to `O_TRUNC` in POSIX. #define FILESYSTEM_OPEN_FLAGS_TRUNCATE (1 << 3) -// Number of hard links to an inode. typedef uint64_t filesystem_link_count_t; typedef struct { @@ -286,35 +218,15 @@ typedef struct { filesystem_datetime_t val; } filesystem_option_datetime_t; -// File attributes. -// -// Note: This was called `filestat` in earlier versions of WASI. typedef struct filesystem_descriptor_stat_t { - // File type. filesystem_descriptor_type_t type; - // Number of hard links to the file. filesystem_link_count_t link_count; - // For regular files, the file size in bytes. For symbolic links, the - // length in bytes of the pathname contained in the symbolic link. filesystem_filesize_t size; - // Last data access timestamp. - // - // If the `option` is none, the platform doesn't maintain an access - // timestamp for this file. filesystem_option_datetime_t data_access_timestamp; - // Last data modification timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // modification timestamp for this file. filesystem_option_datetime_t data_modification_timestamp; - // Last file status-change timestamp. - // - // If the `option` is none, the platform doesn't maintain a - // status-change timestamp for this file. filesystem_option_datetime_t status_change_timestamp; } filesystem_descriptor_stat_t; -// When setting a timestamp, this gives the value to set it to. typedef struct filesystem_new_timestamp_t { uint8_t tag; union { @@ -322,131 +234,66 @@ typedef struct filesystem_new_timestamp_t { } val; } filesystem_new_timestamp_t; -// Leave the timestamp set to its previous value. #define FILESYSTEM_NEW_TIMESTAMP_NO_CHANGE 0 -// Set the timestamp to the current time of the system clock associated -// with the filesystem. #define FILESYSTEM_NEW_TIMESTAMP_NOW 1 -// Set the timestamp to the given value. #define FILESYSTEM_NEW_TIMESTAMP_TIMESTAMP 2 -// A directory entry. typedef struct filesystem_directory_entry_t { - // The type of the file referred to by this directory entry. filesystem_descriptor_type_t type; - // The name of the object. wasip2_string_t name; } filesystem_directory_entry_t; -// Error codes returned by functions, similar to `errno` in POSIX. -// Not all of these error codes are returned by the functions provided by this -// API; some are used in higher-level library layers, and others are provided -// merely for alignment with POSIX. typedef uint8_t filesystem_error_code_t; -// Permission denied, similar to `EACCES` in POSIX. #define FILESYSTEM_ERROR_CODE_ACCESS 0 -// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. #define FILESYSTEM_ERROR_CODE_WOULD_BLOCK 1 -// Connection already in progress, similar to `EALREADY` in POSIX. #define FILESYSTEM_ERROR_CODE_ALREADY 2 -// Bad descriptor, similar to `EBADF` in POSIX. #define FILESYSTEM_ERROR_CODE_BAD_DESCRIPTOR 3 -// Device or resource busy, similar to `EBUSY` in POSIX. #define FILESYSTEM_ERROR_CODE_BUSY 4 -// Resource deadlock would occur, similar to `EDEADLK` in POSIX. #define FILESYSTEM_ERROR_CODE_DEADLOCK 5 -// Storage quota exceeded, similar to `EDQUOT` in POSIX. #define FILESYSTEM_ERROR_CODE_QUOTA 6 -// File exists, similar to `EEXIST` in POSIX. #define FILESYSTEM_ERROR_CODE_EXIST 7 -// File too large, similar to `EFBIG` in POSIX. #define FILESYSTEM_ERROR_CODE_FILE_TOO_LARGE 8 -// Illegal byte sequence, similar to `EILSEQ` in POSIX. #define FILESYSTEM_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE 9 -// Operation in progress, similar to `EINPROGRESS` in POSIX. #define FILESYSTEM_ERROR_CODE_IN_PROGRESS 10 -// Interrupted function, similar to `EINTR` in POSIX. #define FILESYSTEM_ERROR_CODE_INTERRUPTED 11 -// Invalid argument, similar to `EINVAL` in POSIX. #define FILESYSTEM_ERROR_CODE_INVALID 12 -// I/O error, similar to `EIO` in POSIX. #define FILESYSTEM_ERROR_CODE_IO 13 -// Is a directory, similar to `EISDIR` in POSIX. #define FILESYSTEM_ERROR_CODE_IS_DIRECTORY 14 -// Too many levels of symbolic links, similar to `ELOOP` in POSIX. #define FILESYSTEM_ERROR_CODE_LOOP 15 -// Too many links, similar to `EMLINK` in POSIX. #define FILESYSTEM_ERROR_CODE_TOO_MANY_LINKS 16 -// Message too large, similar to `EMSGSIZE` in POSIX. #define FILESYSTEM_ERROR_CODE_MESSAGE_SIZE 17 -// Filename too long, similar to `ENAMETOOLONG` in POSIX. #define FILESYSTEM_ERROR_CODE_NAME_TOO_LONG 18 -// No such device, similar to `ENODEV` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_DEVICE 19 -// No such file or directory, similar to `ENOENT` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_ENTRY 20 -// No locks available, similar to `ENOLCK` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_LOCK 21 -// Not enough space, similar to `ENOMEM` in POSIX. #define FILESYSTEM_ERROR_CODE_INSUFFICIENT_MEMORY 22 -// No space left on device, similar to `ENOSPC` in POSIX. #define FILESYSTEM_ERROR_CODE_INSUFFICIENT_SPACE 23 -// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_DIRECTORY 24 -// Directory not empty, similar to `ENOTEMPTY` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_EMPTY 25 -// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_RECOVERABLE 26 -// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. #define FILESYSTEM_ERROR_CODE_UNSUPPORTED 27 -// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_TTY 28 -// No such device or address, similar to `ENXIO` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_SUCH_DEVICE 29 -// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. #define FILESYSTEM_ERROR_CODE_OVERFLOW 30 -// Operation not permitted, similar to `EPERM` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_PERMITTED 31 -// Broken pipe, similar to `EPIPE` in POSIX. #define FILESYSTEM_ERROR_CODE_PIPE 32 -// Read-only file system, similar to `EROFS` in POSIX. #define FILESYSTEM_ERROR_CODE_READ_ONLY 33 -// Invalid seek, similar to `ESPIPE` in POSIX. #define FILESYSTEM_ERROR_CODE_INVALID_SEEK 34 -// Text file busy, similar to `ETXTBSY` in POSIX. #define FILESYSTEM_ERROR_CODE_TEXT_FILE_BUSY 35 -// Cross-device link, similar to `EXDEV` in POSIX. #define FILESYSTEM_ERROR_CODE_CROSS_DEVICE 36 -// File or memory access pattern advisory information. typedef uint8_t filesystem_advice_t; -// The application has no advice to give on its behavior with respect -// to the specified data. #define FILESYSTEM_ADVICE_NORMAL 0 -// The application expects to access the specified data sequentially -// from lower offsets to higher offsets. #define FILESYSTEM_ADVICE_SEQUENTIAL 1 -// The application expects to access the specified data in a random -// order. #define FILESYSTEM_ADVICE_RANDOM 2 -// The application expects to access the specified data in the near -// future. #define FILESYSTEM_ADVICE_WILL_NEED 3 -// The application expects that it will not access the specified data -// in the near future. #define FILESYSTEM_ADVICE_DONT_NEED 4 -// The application expects to access the specified data once and then -// not reuse it thereafter. #define FILESYSTEM_ADVICE_NO_REUSE 5 -// A 128-bit hash value, split into parts because wasm doesn't have a -// 128-bit integer type. typedef struct filesystem_metadata_hash_value_t { - // 64 bits of a 128-bit hash value. uint64_t lower; - // Another 64 bits of a 128-bit hash value. uint64_t upper; } filesystem_metadata_hash_value_t; @@ -610,85 +457,33 @@ typedef struct network_borrow_network_t { int32_t __handle; } network_borrow_network_t; -// Error codes. -// -// In theory, every API can return any error code. -// In practice, API's typically only return the errors documented per API -// combined with a couple of errors that are always possible: -// - `unknown` -// - `access-denied` -// - `not-supported` -// - `out-of-memory` -// - `concurrency-conflict` -// -// See each individual API for what the POSIX equivalents are. They sometimes differ per API. typedef uint8_t network_error_code_t; -// Unknown error #define NETWORK_ERROR_CODE_UNKNOWN 0 -// Access denied. -// -// POSIX equivalent: EACCES, EPERM #define NETWORK_ERROR_CODE_ACCESS_DENIED 1 -// The operation is not supported. -// -// POSIX equivalent: EOPNOTSUPP #define NETWORK_ERROR_CODE_NOT_SUPPORTED 2 -// One of the arguments is invalid. -// -// POSIX equivalent: EINVAL #define NETWORK_ERROR_CODE_INVALID_ARGUMENT 3 -// Not enough memory to complete the operation. -// -// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY #define NETWORK_ERROR_CODE_OUT_OF_MEMORY 4 -// The operation timed out before it could finish completely. #define NETWORK_ERROR_CODE_TIMEOUT 5 -// This operation is incompatible with another asynchronous operation that is already in progress. -// -// POSIX equivalent: EALREADY #define NETWORK_ERROR_CODE_CONCURRENCY_CONFLICT 6 -// Trying to finish an asynchronous operation that: -// - has not been started yet, or: -// - was already finished by a previous `finish-*` call. -// -// Note: this is scheduled to be removed when `future`s are natively supported. #define NETWORK_ERROR_CODE_NOT_IN_PROGRESS 7 -// The operation has been aborted because it could not be completed immediately. -// -// Note: this is scheduled to be removed when `future`s are natively supported. #define NETWORK_ERROR_CODE_WOULD_BLOCK 8 -// The operation is not valid in the socket's current state. #define NETWORK_ERROR_CODE_INVALID_STATE 9 -// A new socket resource could not be created because of a system limit. #define NETWORK_ERROR_CODE_NEW_SOCKET_LIMIT 10 -// A bind operation failed because the provided address is not an address that the `network` can bind to. #define NETWORK_ERROR_CODE_ADDRESS_NOT_BINDABLE 11 -// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. #define NETWORK_ERROR_CODE_ADDRESS_IN_USE 12 -// The remote address is not reachable #define NETWORK_ERROR_CODE_REMOTE_UNREACHABLE 13 -// The TCP connection was forcefully rejected #define NETWORK_ERROR_CODE_CONNECTION_REFUSED 14 -// The TCP connection was reset. #define NETWORK_ERROR_CODE_CONNECTION_RESET 15 -// A TCP connection was aborted. #define NETWORK_ERROR_CODE_CONNECTION_ABORTED 16 -// The size of a datagram sent to a UDP socket exceeded the maximum -// supported size. #define NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE 17 -// Name does not exist or has no suitable associated IP addresses. #define NETWORK_ERROR_CODE_NAME_UNRESOLVABLE 18 -// A temporary failure in name resolution occurred. #define NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE 19 -// A permanent failure in name resolution occurred. #define NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE 20 typedef uint8_t network_ip_address_family_t; -// Similar to `AF_INET` in POSIX. #define NETWORK_IP_ADDRESS_FAMILY_IPV4 0 -// Similar to `AF_INET6` in POSIX. #define NETWORK_IP_ADDRESS_FAMILY_IPV6 1 typedef struct network_ipv4_address_t { @@ -721,20 +516,14 @@ typedef struct network_ip_address_t { #define NETWORK_IP_ADDRESS_IPV6 1 typedef struct network_ipv4_socket_address_t { - // sin_port uint16_t port; - // sin_addr network_ipv4_address_t address; } network_ipv4_socket_address_t; typedef struct network_ipv6_socket_address_t { - // sin6_port uint16_t port; - // sin6_flowinfo uint32_t flow_info; - // sin6_addr network_ipv6_address_t address; - // sin6_scope_id uint32_t scope_id; } network_ipv6_socket_address_t; @@ -757,17 +546,8 @@ typedef network_ip_socket_address_t udp_ip_socket_address_t; typedef network_ip_address_family_t udp_ip_address_family_t; -// A received datagram. typedef struct udp_incoming_datagram_t { - // The payload. - // - // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. wasip2_list_u8_t data; - // The source address. - // - // This field is guaranteed to match the remote address the stream was initialized with, if any. - // - // Equivalent to the `src_addr` out parameter of `recvfrom`. udp_ip_socket_address_t remote_address; } udp_incoming_datagram_t; @@ -776,17 +556,8 @@ typedef struct { udp_ip_socket_address_t val; } udp_option_ip_socket_address_t; -// A datagram to be sent out. typedef struct udp_outgoing_datagram_t { - // The payload. wasip2_list_u8_t data; - // The destination address. - // - // The requirements on this field depend on how the stream was initialized: - // - with a remote address: this field must be None or match the stream's remote address exactly. - // - without a remote address: this field is required. - // - // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`. udp_option_ip_socket_address_t remote_address; } udp_outgoing_datagram_t; @@ -904,11 +675,8 @@ typedef network_ip_address_family_t tcp_ip_address_family_t; typedef uint8_t tcp_shutdown_type_t; -// Similar to `SHUT_RD` in POSIX. #define TCP_SHUTDOWN_TYPE_RECEIVE 0 -// Similar to `SHUT_WR` in POSIX. #define TCP_SHUTDOWN_TYPE_SEND 1 -// Similar to `SHUT_RDWR` in POSIX. #define TCP_SHUTDOWN_TYPE_BOTH 2 typedef struct tcp_own_tcp_socket_t { @@ -1035,16 +803,6 @@ typedef struct ip_name_lookup_borrow_resolve_address_stream_t { int32_t __handle; } ip_name_lookup_borrow_resolve_address_stream_t; -typedef network_borrow_network_t ip_name_lookup_borrow_network_t; - -typedef struct { - bool is_err; - union { - ip_name_lookup_own_resolve_address_stream_t ok; - ip_name_lookup_error_code_t err; - } val; -} ip_name_lookup_result_own_resolve_address_stream_error_code_t; - typedef struct { bool is_some; ip_name_lookup_ip_address_t val; @@ -1060,6 +818,16 @@ typedef struct { typedef poll_own_pollable_t ip_name_lookup_own_pollable_t; +typedef network_borrow_network_t ip_name_lookup_borrow_network_t; + +typedef struct { + bool is_err; + union { + ip_name_lookup_own_resolve_address_stream_t ok; + ip_name_lookup_error_code_t err; + } val; +} ip_name_lookup_result_own_resolve_address_stream_error_code_t; + typedef struct { uint64_t f0; uint64_t f1; @@ -1086,217 +854,28 @@ extern bool environment_initial_cwd(wasip2_string_t *ret); _Noreturn extern void exit_exit(exit_result_void_void_t *status); // Imported Functions from `wasi:io/error@0.2.0` -// Returns a string that is suitable to assist humans in debugging -// this error. -// -// WARNING: The returned string should not be consumed mechanically! -// It may change across platforms, hosts, or other implementation -// details. Parsing this string is a major platform-compatibility -// hazard. extern void io_error_method_error_to_debug_string(io_error_borrow_error_t self, wasip2_string_t *ret); // Imported Functions from `wasi:io/poll@0.2.0` -// Return the readiness of a pollable. This function never blocks. -// -// Returns `true` when the pollable is ready, and `false` otherwise. extern bool poll_method_pollable_ready(poll_borrow_pollable_t self); -// `block` returns immediately if the pollable is ready, and otherwise -// blocks until ready. -// -// This function is equivalent to calling `poll.poll` on a list -// containing only this pollable. extern void poll_method_pollable_block(poll_borrow_pollable_t self); -// Poll for completion on a set of pollables. -// -// This function takes a list of pollables, which identify I/O sources of -// interest, and waits until one or more of the events is ready for I/O. -// -// The result `list` contains one or more indices of handles in the -// argument list that is ready for I/O. -// -// If the list contains more elements than can be indexed with a `u32` -// value, this function traps. -// -// A timeout can be implemented by adding a pollable from the -// wasi-clocks API to the list. -// -// This function does not return a `result`; polling in itself does not -// do any I/O so it doesn't fail. If any of the I/O sources identified by -// the pollables has an error, it is indicated by marking the source as -// being reaedy for I/O. extern void poll_poll(poll_list_borrow_pollable_t *in, wasip2_list_u32_t *ret); // Imported Functions from `wasi:io/streams@0.2.0` -// Perform a non-blocking read from the stream. -// -// When the source of a `read` is binary data, the bytes from the source -// are returned verbatim. When the source of a `read` is known to the -// implementation to be text, bytes containing the UTF-8 encoding of the -// text are returned. -// -// This function returns a list of bytes containing the read data, -// when successful. The returned list will contain up to `len` bytes; -// it may return fewer than requested, but not more. The list is -// empty when no bytes are available for reading at this time. The -// pollable given by `subscribe` will be ready when more bytes are -// available. -// -// This function fails with a `stream-error` when the operation -// encounters an error, giving `last-operation-failed`, or when the -// stream is closed, giving `closed`. -// -// When the caller gives a `len` of 0, it represents a request to -// read 0 bytes. If the stream is still open, this call should -// succeed and return an empty list, or otherwise fail with `closed`. -// -// The `len` parameter is a `u64`, which could represent a list of u8 which -// is not possible to allocate in wasm32, or not desirable to allocate as -// as a return value by the callee. The callee may return a list of bytes -// less than `len` in size while more bytes are available for reading. extern bool streams_method_input_stream_read(streams_borrow_input_stream_t self, uint64_t len, wasip2_list_u8_t *ret, streams_stream_error_t *err); -// Read bytes from a stream, after blocking until at least one byte can -// be read. Except for blocking, behavior is identical to `read`. extern bool streams_method_input_stream_blocking_read(streams_borrow_input_stream_t self, uint64_t len, wasip2_list_u8_t *ret, streams_stream_error_t *err); -// Skip bytes from a stream. Returns number of bytes skipped. -// -// Behaves identical to `read`, except instead of returning a list -// of bytes, returns the number of bytes consumed from the stream. extern bool streams_method_input_stream_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err); -// Skip bytes from a stream, after blocking until at least one byte -// can be skipped. Except for blocking behavior, identical to `skip`. extern bool streams_method_input_stream_blocking_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err); -// Create a `pollable` which will resolve once either the specified stream -// has bytes available to read or the other end of the stream has been -// closed. -// The created `pollable` is a child resource of the `input-stream`. -// Implementations may trap if the `input-stream` is dropped before -// all derived `pollable`s created with this function are dropped. extern streams_own_pollable_t streams_method_input_stream_subscribe(streams_borrow_input_stream_t self); -// Check readiness for writing. This function never blocks. -// -// Returns the number of bytes permitted for the next call to `write`, -// or an error. Calling `write` with more bytes than this function has -// permitted will trap. -// -// When this function returns 0 bytes, the `subscribe` pollable will -// become ready when this function will report at least 1 byte, or an -// error. extern bool streams_method_output_stream_check_write(streams_borrow_output_stream_t self, uint64_t *ret, streams_stream_error_t *err); -// Perform a write. This function never blocks. -// -// When the destination of a `write` is binary data, the bytes from -// `contents` are written verbatim. When the destination of a `write` is -// known to the implementation to be text, the bytes of `contents` are -// transcoded from UTF-8 into the encoding of the destination and then -// written. -// -// Precondition: check-write gave permit of Ok(n) and contents has a -// length of less than or equal to n. Otherwise, this function will trap. -// -// returns Err(closed) without writing if the stream has closed since -// the last call to check-write provided a permit. extern bool streams_method_output_stream_write(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err); -// Perform a write of up to 4096 bytes, and then flush the stream. Block -// until all of these operations are complete, or an error occurs. -// -// This is a convenience wrapper around the use of `check-write`, -// `subscribe`, `write`, and `flush`, and is implemented with the -// following pseudo-code: -// -// ```text -// let pollable = this.subscribe(); -// while !contents.is_empty() { -// // Wait for the stream to become writable -// pollable.block(); -// let Ok(n) = this.check-write(); // eliding error handling -// let len = min(n, contents.len()); -// let (chunk, rest) = contents.split_at(len); -// this.write(chunk ); // eliding error handling -// contents = rest; -// } -// this.flush(); -// // Wait for completion of `flush` -// pollable.block(); -// // Check for any errors that arose during `flush` -// let _ = this.check-write(); // eliding error handling -// ``` extern bool streams_method_output_stream_blocking_write_and_flush(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err); -// Request to flush buffered output. This function never blocks. -// -// This tells the output-stream that the caller intends any buffered -// output to be flushed. the output which is expected to be flushed -// is all that has been passed to `write` prior to this call. -// -// Upon calling this function, the `output-stream` will not accept any -// writes (`check-write` will return `ok(0)`) until the flush has -// completed. The `subscribe` pollable will become ready when the -// flush has completed and the stream can accept more writes. extern bool streams_method_output_stream_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err); -// Request to flush buffered output, and block until flush completes -// and stream is ready for writing again. extern bool streams_method_output_stream_blocking_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err); -// Create a `pollable` which will resolve once the output-stream -// is ready for more writing, or an error has occured. When this -// pollable is ready, `check-write` will return `ok(n)` with n>0, or an -// error. -// -// If the stream is closed, this pollable is always ready immediately. -// -// The created `pollable` is a child resource of the `output-stream`. -// Implementations may trap if the `output-stream` is dropped before -// all derived `pollable`s created with this function are dropped. extern streams_own_pollable_t streams_method_output_stream_subscribe(streams_borrow_output_stream_t self); -// Write zeroes to a stream. -// -// This should be used precisely like `write` with the exact same -// preconditions (must use check-write first), but instead of -// passing a list of bytes, you simply pass the number of zero-bytes -// that should be written. extern bool streams_method_output_stream_write_zeroes(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err); -// Perform a write of up to 4096 zeroes, and then flush the stream. -// Block until all of these operations are complete, or an error -// occurs. -// -// This is a convenience wrapper around the use of `check-write`, -// `subscribe`, `write-zeroes`, and `flush`, and is implemented with -// the following pseudo-code: -// -// ```text -// let pollable = this.subscribe(); -// while num_zeroes != 0 { -// // Wait for the stream to become writable -// pollable.block(); -// let Ok(n) = this.check-write(); // eliding error handling -// let len = min(n, num_zeroes); -// this.write-zeroes(len); // eliding error handling -// num_zeroes -= len; -// } -// this.flush(); -// // Wait for completion of `flush` -// pollable.block(); -// // Check for any errors that arose during `flush` -// let _ = this.check-write(); // eliding error handling -// ``` extern bool streams_method_output_stream_blocking_write_zeroes_and_flush(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err); -// Read from one stream and write to another. -// -// The behavior of splice is equivelant to: -// 1. calling `check-write` on the `output-stream` -// 2. calling `read` on the `input-stream` with the smaller of the -// `check-write` permitted length and the `len` provided to `splice` -// 3. calling `write` on the `output-stream` with that read data. -// -// Any error reported by the call to `check-write`, `read`, or -// `write` ends the splice and reports that error. -// -// This function returns the number of bytes transferred; it may be less -// than `len`. extern bool streams_method_output_stream_splice(streams_borrow_output_stream_t self, streams_borrow_input_stream_t src, uint64_t len, uint64_t *ret, streams_stream_error_t *err); -// Read from one stream and write to another, with blocking. -// -// This is similar to `splice`, except that it blocks until the -// `output-stream` is ready for writing, and the `input-stream` -// is ready for reading, before performing the `splice`. extern bool streams_method_output_stream_blocking_splice(streams_borrow_output_stream_t self, streams_borrow_input_stream_t src, uint64_t len, uint64_t *ret, streams_stream_error_t *err); // Imported Functions from `wasi:cli/stdin@0.2.0` @@ -1324,930 +903,122 @@ extern bool terminal_stdout_get_terminal_stdout(terminal_stdout_own_terminal_out extern bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t *ret); // Imported Functions from `wasi:clocks/monotonic-clock@0.2.0` -// Read the current value of the clock. -// -// The clock is monotonic, therefore calling this function repeatedly will -// produce a sequence of non-decreasing values. extern monotonic_clock_instant_t monotonic_clock_now(void); -// Query the resolution of the clock. Returns the duration of time -// corresponding to a clock tick. extern monotonic_clock_duration_t monotonic_clock_resolution(void); -// Create a `pollable` which will resolve once the specified instant -// occured. extern monotonic_clock_own_pollable_t monotonic_clock_subscribe_instant(monotonic_clock_instant_t when); -// Create a `pollable` which will resolve once the given duration has -// elapsed, starting at the time at which this function was called. -// occured. extern monotonic_clock_own_pollable_t monotonic_clock_subscribe_duration(monotonic_clock_duration_t when); // Imported Functions from `wasi:clocks/wall-clock@0.2.0` -// Read the current value of the clock. -// -// This clock is not monotonic, therefore calling this function repeatedly -// will not necessarily produce a sequence of non-decreasing values. -// -// The returned timestamps represent the number of seconds since -// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], -// also known as [Unix Time]. -// -// The nanoseconds field of the output is always less than 1000000000. -// -// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 -// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time extern void wall_clock_now(wall_clock_datetime_t *ret); -// Query the resolution of the clock. -// -// The nanoseconds field of the output is always less than 1000000000. extern void wall_clock_resolution(wall_clock_datetime_t *ret); // Imported Functions from `wasi:filesystem/types@0.2.0` -// Return a stream for reading from a file, if available. -// -// May fail with an error-code describing why the file cannot be read. -// -// Multiple read, write, and append streams may be active on the same open -// file and they do not interfere with each other. -// -// Note: This allows using `read-stream`, which is similar to `read` in POSIX. extern bool filesystem_method_descriptor_read_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_own_input_stream_t *ret, filesystem_error_code_t *err); -// Return a stream for writing to a file, if available. -// -// May fail with an error-code describing why the file cannot be written. -// -// Note: This allows using `write-stream`, which is similar to `write` in -// POSIX. extern bool filesystem_method_descriptor_write_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_own_output_stream_t *ret, filesystem_error_code_t *err); -// Return a stream for appending to a file, if available. -// -// May fail with an error-code describing why the file cannot be appended. -// -// Note: This allows using `write-stream`, which is similar to `write` with -// `O_APPEND` in in POSIX. extern bool filesystem_method_descriptor_append_via_stream(filesystem_borrow_descriptor_t self, filesystem_own_output_stream_t *ret, filesystem_error_code_t *err); -// Provide file advisory information on a descriptor. -// -// This is similar to `posix_fadvise` in POSIX. extern bool filesystem_method_descriptor_advise(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_filesize_t length, filesystem_advice_t advice, filesystem_error_code_t *err); -// Synchronize the data of a file to disk. -// -// This function succeeds with no effect if the file descriptor is not -// opened for writing. -// -// Note: This is similar to `fdatasync` in POSIX. extern bool filesystem_method_descriptor_sync_data(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err); -// Get flags associated with a descriptor. -// -// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. -// -// Note: This returns the value that was the `fs_flags` value returned -// from `fdstat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_get_flags(filesystem_borrow_descriptor_t self, filesystem_descriptor_flags_t *ret, filesystem_error_code_t *err); -// Get the dynamic type of a descriptor. -// -// Note: This returns the same value as the `type` field of the `fd-stat` -// returned by `stat`, `stat-at` and similar. -// -// Note: This returns similar flags to the `st_mode & S_IFMT` value provided -// by `fstat` in POSIX. -// -// Note: This returns the value that was the `fs_filetype` value returned -// from `fdstat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_get_type(filesystem_borrow_descriptor_t self, filesystem_descriptor_type_t *ret, filesystem_error_code_t *err); -// Adjust the size of an open file. If this increases the file's size, the -// extra bytes are filled with zeros. -// -// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. extern bool filesystem_method_descriptor_set_size(filesystem_borrow_descriptor_t self, filesystem_filesize_t size, filesystem_error_code_t *err); -// Adjust the timestamps of an open file or directory. -// -// Note: This is similar to `futimens` in POSIX. -// -// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. extern bool filesystem_method_descriptor_set_times(filesystem_borrow_descriptor_t self, filesystem_new_timestamp_t *data_access_timestamp, filesystem_new_timestamp_t *data_modification_timestamp, filesystem_error_code_t *err); -// Read from a descriptor, without using and updating the descriptor's offset. -// -// This function returns a list of bytes containing the data that was -// read, along with a bool which, when true, indicates that the end of the -// file was reached. The returned list will contain up to `length` bytes; it -// may return fewer than requested, if the end of the file is reached or -// if the I/O operation is interrupted. -// -// In the future, this may change to return a `stream`. -// -// Note: This is similar to `pread` in POSIX. extern bool filesystem_method_descriptor_read(filesystem_borrow_descriptor_t self, filesystem_filesize_t length, filesystem_filesize_t offset, wasip2_tuple2_list_u8_bool_t *ret, filesystem_error_code_t *err); -// Write to a descriptor, without using and updating the descriptor's offset. -// -// It is valid to write past the end of a file; the file is extended to the -// extent of the write, with bytes between the previous end and the start of -// the write set to zero. -// -// In the future, this may change to take a `stream`. -// -// Note: This is similar to `pwrite` in POSIX. extern bool filesystem_method_descriptor_write(filesystem_borrow_descriptor_t self, wasip2_list_u8_t *buffer, filesystem_filesize_t offset, filesystem_filesize_t *ret, filesystem_error_code_t *err); -// Read directory entries from a directory. -// -// On filesystems where directories contain entries referring to themselves -// and their parents, often named `.` and `..` respectively, these entries -// are omitted. -// -// This always returns a new stream which starts at the beginning of the -// directory. Multiple streams may be active on the same directory, and they -// do not interfere with each other. extern bool filesystem_method_descriptor_read_directory(filesystem_borrow_descriptor_t self, filesystem_own_directory_entry_stream_t *ret, filesystem_error_code_t *err); -// Synchronize the data and metadata of a file to disk. -// -// This function succeeds with no effect if the file descriptor is not -// opened for writing. -// -// Note: This is similar to `fsync` in POSIX. extern bool filesystem_method_descriptor_sync(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err); -// Create a directory. -// -// Note: This is similar to `mkdirat` in POSIX. extern bool filesystem_method_descriptor_create_directory_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); -// Return the attributes of an open file or directory. -// -// Note: This is similar to `fstat` in POSIX, except that it does not return -// device and inode information. For testing whether two descriptors refer to -// the same underlying filesystem object, use `is-same-object`. To obtain -// additional data that can be used do determine whether a file has been -// modified, use `metadata-hash`. -// -// Note: This was called `fd_filestat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_stat(filesystem_borrow_descriptor_t self, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err); -// Return the attributes of a file or directory. -// -// Note: This is similar to `fstatat` in POSIX, except that it does not -// return device and inode information. See the `stat` description for a -// discussion of alternatives. -// -// Note: This was called `path_filestat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_stat_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err); -// Adjust the timestamps of a file or directory. -// -// Note: This is similar to `utimensat` in POSIX. -// -// Note: This was called `path_filestat_set_times` in earlier versions of -// WASI. extern bool filesystem_method_descriptor_set_times_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_new_timestamp_t *data_access_timestamp, filesystem_new_timestamp_t *data_modification_timestamp, filesystem_error_code_t *err); -// Create a hard link. -// -// Note: This is similar to `linkat` in POSIX. extern bool filesystem_method_descriptor_link_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t old_path_flags, wasip2_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, wasip2_string_t *new_path, filesystem_error_code_t *err); -// Open a file or directory. -// -// The returned descriptor is not guaranteed to be the lowest-numbered -// 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 descriptor is -// guaranteed to be less than 2**31. -// -// If `flags` contains `descriptor-flags::mutate-directory`, and the base -// descriptor doesn't have `descriptor-flags::mutate-directory` set, -// `open-at` fails with `error-code::read-only`. -// -// If `flags` contains `write` or `mutate-directory`, or `open-flags` -// contains `truncate` or `create`, and the base descriptor doesn't have -// `descriptor-flags::mutate-directory` set, `open-at` fails with -// `error-code::read-only`. -// -// Note: This is similar to `openat` in POSIX. extern bool filesystem_method_descriptor_open_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_open_flags_t open_flags, filesystem_descriptor_flags_t flags, filesystem_own_descriptor_t *ret, filesystem_error_code_t *err); -// Read the contents of a symbolic link. -// -// If the contents contain an absolute or rooted path in the underlying -// filesystem, this function fails with `error-code::not-permitted`. -// -// Note: This is similar to `readlinkat` in POSIX. extern bool filesystem_method_descriptor_readlink_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, wasip2_string_t *ret, filesystem_error_code_t *err); -// Remove a directory. -// -// Return `error-code::not-empty` if the directory is not empty. -// -// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. extern bool filesystem_method_descriptor_remove_directory_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); -// Rename a filesystem object. -// -// Note: This is similar to `renameat` in POSIX. extern bool filesystem_method_descriptor_rename_at(filesystem_borrow_descriptor_t self, wasip2_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, wasip2_string_t *new_path, filesystem_error_code_t *err); -// Create a symbolic link (also known as a "symlink"). -// -// If `old-path` starts with `/`, the function fails with -// `error-code::not-permitted`. -// -// Note: This is similar to `symlinkat` in POSIX. extern bool filesystem_method_descriptor_symlink_at(filesystem_borrow_descriptor_t self, wasip2_string_t *old_path, wasip2_string_t *new_path, filesystem_error_code_t *err); -// Unlink a filesystem object that is not a directory. -// -// Return `error-code::is-directory` if the path refers to a directory. -// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. extern bool filesystem_method_descriptor_unlink_file_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); -// Test whether two descriptors refer to the same filesystem object. -// -// In POSIX, this corresponds to testing whether the two descriptors have the -// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. -// wasi-filesystem does not expose device and inode numbers, so this function -// may be used instead. extern bool filesystem_method_descriptor_is_same_object(filesystem_borrow_descriptor_t self, filesystem_borrow_descriptor_t other); -// Return a hash of the metadata associated with a filesystem object referred -// to by a descriptor. -// -// This returns a hash of the last-modification timestamp and file size, and -// may also include the inode number, device number, birth timestamp, and -// other metadata fields that may change when the file is modified or -// replaced. It may also include a secret value chosen by the -// implementation and not otherwise exposed. -// -// Implementations are encourated to provide the following properties: -// -// - If the file is not modified or replaced, the computed hash value should -// usually not change. -// - If the object is modified or replaced, the computed hash value should -// usually change. -// - The inputs to the hash should not be easily computable from the -// computed hash. -// -// However, none of these is required. extern bool filesystem_method_descriptor_metadata_hash(filesystem_borrow_descriptor_t self, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err); -// Return a hash of the metadata associated with a filesystem object referred -// to by a directory descriptor and a relative path. -// -// This performs the same hash computation as `metadata-hash`. extern bool filesystem_method_descriptor_metadata_hash_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err); -// Read a single directory entry from a `directory-entry-stream`. extern bool filesystem_method_directory_entry_stream_read_directory_entry(filesystem_borrow_directory_entry_stream_t self, filesystem_option_directory_entry_t *ret, filesystem_error_code_t *err); -// Attempts to extract a filesystem-related `error-code` from the stream -// `error` provided. -// -// Stream operations which return `stream-error::last-operation-failed` -// have a payload with more information about the operation that failed. -// This payload can be passed through to this function to see if there's -// filesystem-related information about the error to return. -// -// Note that this function is fallible because not all stream-related -// errors are filesystem-related errors. extern bool filesystem_filesystem_error_code(filesystem_borrow_error_t err_, filesystem_error_code_t *ret); // Imported Functions from `wasi:filesystem/preopens@0.2.0` -// Return the set of preopened directories, and their path. extern void filesystem_preopens_get_directories(filesystem_preopens_list_tuple2_own_descriptor_string_t *ret); // Imported Functions from `wasi:sockets/instance-network@0.2.0` -// Get a handle to the default network. extern instance_network_own_network_t instance_network_instance_network(void); // Imported Functions from `wasi:sockets/udp@0.2.0` -// Bind the socket to a specific network on the provided IP address and port. -// -// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which -// network interface(s) to bind to. -// If the port is zero, the socket will be bound to a random free port. -// -// # Typical errors -// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) -// - `invalid-state`: The socket is already bound. (EINVAL) -// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) -// - `address-in-use`: Address is already in use. (EADDRINUSE) -// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) -// - `not-in-progress`: A `bind` operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// Unlike in POSIX, in WASI the bind operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `bind` as part of either `start-bind` or `finish-bind`. -// -// # References -// - -// - -// - -// - extern bool udp_method_udp_socket_start_bind(udp_borrow_udp_socket_t self, udp_borrow_network_t network, udp_ip_socket_address_t *local_address, udp_error_code_t *err); extern bool udp_method_udp_socket_finish_bind(udp_borrow_udp_socket_t self, udp_error_code_t *err); -// Set up inbound & outbound communication channels, optionally to a specific peer. -// -// This function only changes the local socket configuration and does not generate any network traffic. -// On success, the `remote-address` of the socket is updated. The `local-address` may be updated as well, -// based on the best network path to `remote-address`. -// -// When a `remote-address` is provided, the returned streams are limited to communicating with that specific peer: -// - `send` can only be used to send to this destination. -// - `receive` will only return datagrams sent from the provided `remote-address`. -// -// This method may be called multiple times on the same socket to change its association, but -// only the most recently returned pair of streams will be operational. Implementations may trap if -// the streams returned by a previous invocation haven't been dropped yet before calling `stream` again. -// -// The POSIX equivalent in pseudo-code is: -// ```text -// if (was previously connected) { -// connect(s, AF_UNSPEC) -// } -// if (remote_address is Some) { -// connect(s, remote_address) -// } -// ``` -// -// Unlike in POSIX, the socket must already be explicitly bound. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-state`: The socket is not bound. -// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// -// # References -// - -// - -// - -// - extern bool udp_method_udp_socket_stream(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *maybe_remote_address, udp_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_t *ret, udp_error_code_t *err); -// Get the current bound address. -// -// POSIX mentions: -// > If the socket has not been bound to a local name, the value -// > stored in the object pointed to by `address` is unspecified. -// -// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. -// -// # References -// - -// - -// - -// - extern bool udp_method_udp_socket_local_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err); -// Get the address the socket is currently streaming to. -// -// # Typical errors -// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) -// -// # References -// - -// - -// - -// - extern bool udp_method_udp_socket_remote_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err); -// Whether this is a IPv4 or IPv6 socket. -// -// Equivalent to the SO_DOMAIN socket option. extern udp_ip_address_family_t udp_method_udp_socket_address_family(udp_borrow_udp_socket_t self); -// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// -// # Typical errors -// - `invalid-argument`: (set) The TTL value must be 1 or higher. extern bool udp_method_udp_socket_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t *ret, udp_error_code_t *err); extern bool udp_method_udp_socket_set_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t value, udp_error_code_t *err); -// The kernel buffer space reserved for sends/receives on this socket. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. extern bool udp_method_udp_socket_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err); extern bool udp_method_udp_socket_set_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err); extern bool udp_method_udp_socket_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err); extern bool udp_method_udp_socket_set_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err); -// Create a `pollable` which will resolve once the socket is ready for I/O. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. extern udp_own_pollable_t udp_method_udp_socket_subscribe(udp_borrow_udp_socket_t self); -// Receive messages on the socket. -// -// This function attempts to receive up to `max-results` datagrams on the socket without blocking. -// The returned list may contain fewer elements than requested, but never more. -// -// This function returns successfully with an empty list when either: -// - `max-results` is 0, or: -// - `max-results` is greater than 0, but no results are immediately available. -// This function never returns `error(would-block)`. -// -// # Typical errors -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - extern bool udp_method_incoming_datagram_stream_receive(udp_borrow_incoming_datagram_stream_t self, uint64_t max_results, udp_list_incoming_datagram_t *ret, udp_error_code_t *err); -// Create a `pollable` which will resolve once the stream is ready to receive again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. extern udp_own_pollable_t udp_method_incoming_datagram_stream_subscribe(udp_borrow_incoming_datagram_stream_t self); -// Check readiness for sending. This function never blocks. -// -// Returns the number of datagrams permitted for the next call to `send`, -// or an error. Calling `send` with more datagrams than this function has -// permitted will trap. -// -// When this function returns ok(0), the `subscribe` pollable will -// become ready when this function will report at least ok(1), or an -// error. -// -// Never returns `would-block`. extern bool udp_method_outgoing_datagram_stream_check_send(udp_borrow_outgoing_datagram_stream_t self, uint64_t *ret, udp_error_code_t *err); -// Send messages on the socket. -// -// This function attempts to send all provided `datagrams` on the socket without blocking and -// returns how many messages were actually sent (or queued for sending). This function never -// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned. -// -// This function semantically behaves the same as iterating the `datagrams` list and sequentially -// sending each individual datagram until either the end of the list has been reached or the first error occurred. -// If at least one datagram has been sent successfully, this function never returns an error. -// -// If the input list is empty, the function returns `ok(0)`. -// -// Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if -// either `check-send` was not called or `datagrams` contains more items than `check-send` permitted. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) -// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN) -// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ) -// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `connection-refused`: The connection was refused. (ECONNREFUSED) -// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) -// -// # References -// - -// - -// - -// - -// - -// - -// - -// - extern bool udp_method_outgoing_datagram_stream_send(udp_borrow_outgoing_datagram_stream_t self, udp_list_outgoing_datagram_t *datagrams, uint64_t *ret, udp_error_code_t *err); -// Create a `pollable` which will resolve once the stream is ready to send again. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. extern udp_own_pollable_t udp_method_outgoing_datagram_stream_subscribe(udp_borrow_outgoing_datagram_stream_t self); // Imported Functions from `wasi:sockets/udp-create-socket@0.2.0` -// Create a new UDP socket. -// -// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX. -// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. -// -// This function does not require a network capability handle. This is considered to be safe because -// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind` is called, -// the socket is effectively an in-memory configuration object, unable to communicate with the outside world. -// -// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. -// -// # Typical errors -// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) -// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) -// -// # References: -// - -// - -// - -// - extern bool udp_create_socket_create_udp_socket(udp_create_socket_ip_address_family_t address_family, udp_create_socket_own_udp_socket_t *ret, udp_create_socket_error_code_t *err); // Imported Functions from `wasi:sockets/tcp@0.2.0` -// Bind the socket to a specific network on the provided IP address and port. -// -// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which -// network interface(s) to bind to. -// If the TCP/UDP port is zero, the socket will be bound to a random free port. -// -// Bind can be attempted multiple times on the same socket, even with -// different arguments on each iteration. But never concurrently and -// only as long as the previous bind failed. Once a bind succeeds, the -// binding can't be changed anymore. -// -// # Typical errors -// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) -// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) -// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL) -// - `invalid-state`: The socket is already bound. (EINVAL) -// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) -// - `address-in-use`: Address is already in use. (EADDRINUSE) -// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) -// - `not-in-progress`: A `bind` operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT -// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR -// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior -// and SO_REUSEADDR performs something different entirely. -// -// Unlike in POSIX, in WASI the bind operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `bind` as part of either `start-bind` or `finish-bind`. -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_start_bind(tcp_borrow_tcp_socket_t self, tcp_borrow_network_t network, tcp_ip_socket_address_t *local_address, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_finish_bind(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); -// Connect to a remote endpoint. -// -// On success: -// - the socket is transitioned into the `connection` state. -// - a pair of streams is returned that can be used to read & write to the connection -// -// After a failed connection attempt, the socket will be in the `closed` -// state and the only valid action left is to `drop` the socket. A single -// socket can not be used to connect more than once. -// -// # Typical errors -// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) -// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) -// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos) -// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) -// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows) -// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. -// - `invalid-state`: The socket is already in the `connected` state. (EISCONN) -// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows) -// - `timeout`: Connection timed out. (ETIMEDOUT) -// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) -// - `connection-reset`: The connection was reset. (ECONNRESET) -// - `connection-aborted`: The connection was aborted. (ECONNABORTED) -// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) -// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) -// - `not-in-progress`: A connect operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// The POSIX equivalent of `start-connect` is the regular `connect` syscall. -// Because all WASI sockets are non-blocking this is expected to return -// EINPROGRESS, which should be translated to `ok()` in WASI. -// -// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` -// with a timeout of 0 on the socket descriptor. Followed by a check for -// the `SO_ERROR` socket option, in case the poll signaled readiness. -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_start_connect(tcp_borrow_tcp_socket_t self, tcp_borrow_network_t network, tcp_ip_socket_address_t *remote_address, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_finish_connect(tcp_borrow_tcp_socket_t self, tcp_tuple2_own_input_stream_own_output_stream_t *ret, tcp_error_code_t *err); -// Start listening for new connections. -// -// Transitions the socket into the `listening` state. -// -// Unlike POSIX, the socket must already be explicitly bound. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) -// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD) -// - `invalid-state`: The socket is already in the `listening` state. -// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE) -// - `not-in-progress`: A listen operation is not in progress. -// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) -// -// # Implementors note -// Unlike in POSIX, in WASI the listen operation is async. This enables -// interactive WASI hosts to inject permission prompts. Runtimes that -// don't want to make use of this ability can simply call the native -// `listen` as part of either `start-listen` or `finish-listen`. -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_start_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_finish_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); -// Accept a new client socket. -// -// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket: -// - `address-family` -// - `keep-alive-enabled` -// - `keep-alive-idle-time` -// - `keep-alive-interval` -// - `keep-alive-count` -// - `hop-limit` -// - `receive-buffer-size` -// - `send-buffer-size` -// -// On success, this function returns the newly accepted client socket along with -// a pair of streams that can be used to read & write to the connection. -// -// # Typical errors -// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) -// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) -// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED) -// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_accept(tcp_borrow_tcp_socket_t self, tcp_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ret, tcp_error_code_t *err); -// Get the bound local address. -// -// POSIX mentions: -// > If the socket has not been bound to a local name, the value -// > stored in the object pointed to by `address` is unspecified. -// -// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. -// -// # Typical errors -// - `invalid-state`: The socket is not bound to any local address. -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_local_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err); -// Get the remote address. -// -// # Typical errors -// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_remote_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err); -// Whether the socket is in the `listening` state. -// -// Equivalent to the SO_ACCEPTCONN socket option. extern bool tcp_method_tcp_socket_is_listening(tcp_borrow_tcp_socket_t self); -// Whether this is a IPv4 or IPv6 socket. -// -// Equivalent to the SO_DOMAIN socket option. extern tcp_ip_address_family_t tcp_method_tcp_socket_address_family(tcp_borrow_tcp_socket_t self); -// Hints the desired listen queue size. Implementations are free to ignore this. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// -// # Typical errors -// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. -// - `invalid-argument`: (set) The provided value was 0. -// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state. extern bool tcp_method_tcp_socket_set_listen_backlog_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); -// Enables or disables keepalive. -// -// The keepalive behavior can be adjusted using: -// - `keep-alive-idle-time` -// - `keep-alive-interval` -// - `keep-alive-count` -// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. -// -// Equivalent to the SO_KEEPALIVE socket option. extern bool tcp_method_tcp_socket_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool value, tcp_error_code_t *err); -// Amount of time the connection has to be idle before TCP starts sending keepalive packets. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err); -// The time between keepalive packets. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the TCP_KEEPINTVL socket option. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err); -// The maximum amount of keepalive packets TCP should send before aborting the connection. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the TCP_KEEPCNT socket option. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t value, tcp_error_code_t *err); -// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// -// # Typical errors -// - `invalid-argument`: (set) The TTL value must be 1 or higher. extern bool tcp_method_tcp_socket_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t value, tcp_error_code_t *err); -// The kernel buffer space reserved for sends/receives on this socket. -// -// If the provided value is 0, an `invalid-argument` error is returned. -// Any other value will never cause an error, but it might be silently clamped and/or rounded. -// I.e. after setting a value, reading the same setting back may return a different value. -// -// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. -// -// # Typical errors -// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); -// Create a `pollable` which can be used to poll for, or block on, -// completion of any of the asynchronous operations of this socket. -// -// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` -// return `error(would-block)`, this pollable can be used to wait for -// their success or failure, after which the method can be retried. -// -// The pollable is not limited to the async operation that happens to be -// in progress at the time of calling `subscribe` (if any). Theoretically, -// `subscribe` only has to be called once per socket and can then be -// (re)used for the remainder of the socket's lifetime. -// -// See -// for a more information. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. extern tcp_own_pollable_t tcp_method_tcp_socket_subscribe(tcp_borrow_tcp_socket_t self); -// Initiate a graceful shutdown. -// -// - `receive`: The socket is not expecting to receive any data from -// the peer. The `input-stream` associated with this socket will be -// closed. Any data still in the receive queue at time of calling -// this method will be discarded. -// - `send`: The socket has no more data to send to the peer. The `output-stream` -// associated with this socket will be closed and a FIN packet will be sent. -// - `both`: Same effect as `receive` & `send` combined. -// -// This function is idempotent. Shutting a down a direction more than once -// has no effect and returns `ok`. -// -// The shutdown function does not close (drop) the socket. -// -// # Typical errors -// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) -// -// # References -// - -// - -// - -// - extern bool tcp_method_tcp_socket_shutdown(tcp_borrow_tcp_socket_t self, tcp_shutdown_type_t shutdown_type, tcp_error_code_t *err); // Imported Functions from `wasi:sockets/tcp-create-socket@0.2.0` -// Create a new TCP socket. -// -// Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. -// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. -// -// This function does not require a network capability handle. This is considered to be safe because -// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`connect` -// is called, the socket is effectively an in-memory configuration object, unable to communicate with the outside world. -// -// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. -// -// # Typical errors -// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) -// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) -// -// # References -// - -// - -// - -// - extern bool tcp_create_socket_create_tcp_socket(tcp_create_socket_ip_address_family_t address_family, tcp_create_socket_own_tcp_socket_t *ret, tcp_create_socket_error_code_t *err); // Imported Functions from `wasi:sockets/ip-name-lookup@0.2.0` -// Resolve an internet host name to a list of IP addresses. -// -// Unicode domain names are automatically converted to ASCII using IDNA encoding. -// If the input is an IP address string, the address is parsed and returned -// as-is without making any external requests. -// -// See the wasi-socket proposal README.md for a comparison with getaddrinfo. -// -// This function never blocks. It either immediately fails or immediately -// returns successfully with a `resolve-address-stream` that can be used -// to (asynchronously) fetch the results. -// -// # Typical errors -// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. -// -// # References: -// - -// - -// - -// - -extern bool ip_name_lookup_resolve_addresses(ip_name_lookup_borrow_network_t network, wasip2_string_t *name, ip_name_lookup_own_resolve_address_stream_t *ret, ip_name_lookup_error_code_t *err); -// Returns the next address from the resolver. -// -// This function should be called multiple times. On each call, it will -// return the next address in connection order preference. If all -// addresses have been exhausted, this function returns `none`. -// -// This function never returns IPv4-mapped IPv6 addresses. -// -// # Typical errors -// - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) -// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN) -// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL) -// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) extern bool ip_name_lookup_method_resolve_address_stream_resolve_next_address(ip_name_lookup_borrow_resolve_address_stream_t self, ip_name_lookup_option_ip_address_t *ret, ip_name_lookup_error_code_t *err); -// Create a `pollable` which will resolve once the stream is ready for I/O. -// -// Note: this function is here for WASI Preview2 only. -// It's planned to be removed when `future` is natively supported in Preview3. extern ip_name_lookup_own_pollable_t ip_name_lookup_method_resolve_address_stream_subscribe(ip_name_lookup_borrow_resolve_address_stream_t self); +extern bool ip_name_lookup_resolve_addresses(ip_name_lookup_borrow_network_t network, wasip2_string_t *name, ip_name_lookup_own_resolve_address_stream_t *ret, ip_name_lookup_error_code_t *err); // Imported Functions from `wasi:random/random@0.2.0` -// Return `len` cryptographically-secure random or pseudo-random bytes. -// -// This function must produce data at least as cryptographically secure and -// fast as an adequately seeded cryptographically-secure pseudo-random -// number generator (CSPRNG). It must not block, from the perspective of -// the calling program, under any circumstances, including on the first -// request and on requests for numbers of bytes. The returned data must -// always be unpredictable. -// -// This function must always return fresh data. Deterministic environments -// must omit this function, rather than implementing it with deterministic -// data. extern void random_get_random_bytes(uint64_t len, wasip2_list_u8_t *ret); -// Return a cryptographically-secure random or pseudo-random `u64` value. -// -// This function returns the same type of data as `get-random-bytes`, -// represented as a `u64`. extern uint64_t random_get_random_u64(void); // Imported Functions from `wasi:random/insecure@0.2.0` -// Return `len` insecure pseudo-random bytes. -// -// This function is not cryptographically secure. Do not use it for -// anything related to security. -// -// There are no requirements on the values of the returned bytes, however -// implementations are encouraged to return evenly distributed values with -// a long period. extern void random_insecure_get_insecure_random_bytes(uint64_t len, wasip2_list_u8_t *ret); -// Return an insecure pseudo-random `u64` value. -// -// This function returns the same type of pseudo-random data as -// `get-insecure-random-bytes`, represented as a `u64`. extern uint64_t random_insecure_get_insecure_random_u64(void); // Imported Functions from `wasi:random/insecure-seed@0.2.0` -// Return a 128-bit value that may contain a pseudo-random value. -// -// The returned value is not required to be computed from a CSPRNG, and may -// even be entirely deterministic. Host implementations are encouraged to -// provide pseudo-random values to any program exposed to -// attacker-controlled content, to enable DoS protection built into many -// languages' hash-map implementations. -// -// This function is intended to only be called once, by a source language -// to initialize Denial Of Service (DoS) protection in its hash-map -// implementation. -// -// # Expected future evolution -// -// This will likely be changed to a value import, to prevent it from being -// called multiple times and potentially used for purposes other than DoS -// protection. extern void random_insecure_seed_insecure_seed(wasip2_tuple2_u64_u64_t *ret); // Helper Functions @@ -2434,12 +1205,12 @@ extern void ip_name_lookup_resolve_address_stream_drop_own(ip_name_lookup_own_re extern ip_name_lookup_borrow_resolve_address_stream_t ip_name_lookup_borrow_resolve_address_stream(ip_name_lookup_own_resolve_address_stream_t handle); -void ip_name_lookup_result_own_resolve_address_stream_error_code_free(ip_name_lookup_result_own_resolve_address_stream_error_code_t *ptr); - void ip_name_lookup_option_ip_address_free(ip_name_lookup_option_ip_address_t *ptr); void ip_name_lookup_result_option_ip_address_error_code_free(ip_name_lookup_result_option_ip_address_error_code_t *ptr); +void ip_name_lookup_result_own_resolve_address_stream_error_code_free(ip_name_lookup_result_own_resolve_address_stream_error_code_t *ptr); + // Sets the string `ret` to reference the input string `s` without copying it void wasip2_string_set(wasip2_string_t *ret, const char*s); @@ -2447,6 +1218,11 @@ void wasip2_string_set(wasip2_string_t *ret, const char*s); // stores it into the component model string `ret`. void wasip2_string_dup(wasip2_string_t *ret, const char*s); +// Creates a copy of the input string `s` with length `len` and +// stores it into the component model string `ret`. +// The length is specified in code units (bytes for UTF-8, 16-bit values for UTF-16). +void wasip2_string_dup_n(wasip2_string_t *ret, const char*s, size_t len); + // Deallocates the string pointed to by `ret`, deallocating // the memory behind the string. void wasip2_string_free(wasip2_string_t *ret); diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h index 8618192ab..232b69b8c 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.48.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! #ifndef __BINDINGS_WASIP3_H #define __BINDINGS_WASIP3_H #ifdef __cplusplus @@ -36,7 +36,6 @@ typedef uint32_t wasip3_callback_code_t; #define WASIP3_CALLBACK_CODE_EXIT 0 #define WASIP3_CALLBACK_CODE_YIELD 1 #define WASIP3_CALLBACK_CODE_WAIT(set) (2 | (set << 4)) -#define WASIP3_CALLBACK_CODE_POLL(set) (3 | (set << 4)) typedef enum wasip3_event_code { WASIP3_EVENT_NONE, @@ -74,13 +73,11 @@ typedef enum wasip3_waitable_state { WASIP3_WAITABLE_CANCELLED, } wasip3_waitable_state_t; -void wasip3_backpressure_set(bool enable); void wasip3_backpressure_inc(void); void wasip3_backpressure_dec(void); -void* wasip3_context_get(void); -void wasip3_context_set(void*); -void wasip3_yield(void); -uint32_t wasip3_yield_cancellable(void); +void* wasip3_context_get_0(void); +void wasip3_context_set_0(void* value); +void wasip3_thread_yield(void); @@ -195,18 +192,35 @@ typedef uint64_t wasi_clocks_types_duration_t; typedef wasi_clocks_types_duration_t monotonic_clock_duration_t; -// An instant in time, in nanoseconds. An instant is relative to an +// A mark on a monotonic clock is a number of nanoseconds since an // unspecified initial value, and can only be compared to instances from // the same monotonic-clock. -typedef uint64_t monotonic_clock_instant_t; +typedef uint64_t monotonic_clock_mark_t; -// A time and date in seconds plus nanoseconds. -typedef struct wall_clock_datetime_t { - uint64_t seconds; +typedef wasi_clocks_types_duration_t wasi_clocks_system_clock_duration_t; + +// An "instant", or "exact time", is a point in time without regard to any +// time zone: just the time since a particular external reference point, +// often called an "epoch". +// +// Here, the epoch is 1970-01-01T00:00:00Z, also known as +// [POSIX's Seconds Since the Epoch], also known as [Unix Time]. +// +// Note that even if the seconds field is negative, incrementing +// nanoseconds always represents moving forwards in time. +// For example, `{ -1 seconds, 999999999 nanoseconds }` represents the +// instant one nanosecond before the epoch. +// For more on various different ways to represent time, see +// https://tc39.es/proposal-temporal/docs/timezone.html +// +// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 +// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time +typedef struct wasi_clocks_system_clock_instant_t { + int64_t seconds; uint32_t nanoseconds; -} wall_clock_datetime_t; +} wasi_clocks_system_clock_instant_t; -typedef wall_clock_datetime_t filesystem_datetime_t; +typedef wasi_clocks_system_clock_instant_t filesystem_instant_t; // File size or length of a region within a file. typedef uint64_t filesystem_filesize_t; @@ -301,8 +315,8 @@ typedef uint64_t filesystem_link_count_t; typedef struct { bool is_some; - filesystem_datetime_t val; -} filesystem_option_datetime_t; + filesystem_instant_t val; +} filesystem_option_instant_t; // File attributes. // @@ -319,24 +333,24 @@ typedef struct filesystem_descriptor_stat_t { // // If the `option` is none, the platform doesn't maintain an access // timestamp for this file. - filesystem_option_datetime_t data_access_timestamp; + filesystem_option_instant_t data_access_timestamp; // Last data modification timestamp. // // If the `option` is none, the platform doesn't maintain a // modification timestamp for this file. - filesystem_option_datetime_t data_modification_timestamp; + filesystem_option_instant_t data_modification_timestamp; // Last file status-change timestamp. // // If the `option` is none, the platform doesn't maintain a // status-change timestamp for this file. - filesystem_option_datetime_t status_change_timestamp; + filesystem_option_instant_t status_change_timestamp; } filesystem_descriptor_stat_t; // When setting a timestamp, this gives the value to set it to. typedef struct filesystem_new_timestamp_t { uint8_t tag; union { - filesystem_datetime_t timestamp; + filesystem_instant_t timestamp; } val; } filesystem_new_timestamp_t; @@ -594,7 +608,7 @@ typedef struct { size_t len; } filesystem_preopens_list_tuple2_own_descriptor_string_t; -typedef monotonic_clock_duration_t sockets_duration_t; +typedef wasi_clocks_types_duration_t sockets_duration_t; // Error codes. // @@ -896,7 +910,7 @@ typedef struct { uint64_t f1; } wasip3_tuple2_u64_u64_t; -// Imported Functions from `wasi:cli/environment@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/environment@0.3.0-rc-2026-01-06` // Get the POSIX-style environment variables. // // Each environment variable is provided as a pair of string variable names @@ -912,11 +926,11 @@ extern void environment_get_arguments(wasip3_list_string_t *ret); // directory, interpreting `.` as shorthand for this. extern bool environment_get_initial_cwd(wasip3_string_t *ret); -// Imported Functions from `wasi:cli/exit@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/exit@0.3.0-rc-2026-01-06` // Exit the current instance and any linked instances. _Noreturn extern void exit_exit(exit_result_void_void_t *status); -// Imported Functions from `wasi:cli/stdin@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/stdin@0.3.0-rc-2026-01-06` // Return a stream for reading from stdin. // // This function returns a stream which provides data read from stdin, @@ -932,7 +946,7 @@ _Noreturn extern void exit_exit(exit_result_void_void_t *status); // reads is implementation-specific. extern void stdin_read_via_stream(stdin_tuple2_stream_u8_future_result_void_error_code_t *ret); -// Imported Functions from `wasi:cli/stdout@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/stdout@0.3.0-rc-2026-01-06` // Write the given stream to stdout. // // If the stream's writable end is dropped this function will either return @@ -943,7 +957,7 @@ extern void stdin_read_via_stream(stdin_tuple2_stream_u8_future_result_void_erro // dropped and this function will return an error-code. extern wasip3_subtask_status_t stdout_write_via_stream(stdin_stream_u8_t data, stdout_result_void_error_code_t *result); -// Imported Functions from `wasi:cli/stderr@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/stderr@0.3.0-rc-2026-01-06` // Write the given stream to stderr. // // If the stream's writable end is dropped this function will either return @@ -954,61 +968,53 @@ extern wasip3_subtask_status_t stdout_write_via_stream(stdin_stream_u8_t data, s // dropped and this function will return an error-code. extern wasip3_subtask_status_t stderr_write_via_stream(stdin_stream_u8_t data, stderr_result_void_error_code_t *result); -// Imported Functions from `wasi:cli/terminal-stdin@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/terminal-stdin@0.3.0-rc-2026-01-06` // If stdin is connected to a terminal, return a `terminal-input` handle // allowing further interaction with it. extern bool terminal_stdin_get_terminal_stdin(terminal_stdin_own_terminal_input_t *ret); -// Imported Functions from `wasi:cli/terminal-stdout@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/terminal-stdout@0.3.0-rc-2026-01-06` // If stdout is connected to a terminal, return a `terminal-output` handle // allowing further interaction with it. extern bool terminal_stdout_get_terminal_stdout(terminal_stdout_own_terminal_output_t *ret); -// Imported Functions from `wasi:cli/terminal-stderr@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/terminal-stderr@0.3.0-rc-2026-01-06` // If stderr is connected to a terminal, return a `terminal-output` handle // allowing further interaction with it. extern bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t *ret); -// Imported Functions from `wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06` // Read the current value of the clock. // // The clock is monotonic, therefore calling this function repeatedly will // produce a sequence of non-decreasing values. // // For completeness, this function traps if it's not possible to represent -// the value of the clock in an `instant`. Consequently, implementations +// the value of the clock in a `mark`. Consequently, implementations // should ensure that the starting time is low enough to avoid the // possibility of overflow in practice. -extern monotonic_clock_instant_t monotonic_clock_now(void); +extern monotonic_clock_mark_t monotonic_clock_now(void); // Query the resolution of the clock. Returns the duration of time // corresponding to a clock tick. extern monotonic_clock_duration_t monotonic_clock_get_resolution(void); -// Wait until the specified instant has occurred. -extern wasip3_subtask_status_t monotonic_clock_wait_until(monotonic_clock_instant_t when); +// Wait until the specified mark has occurred. +extern wasip3_subtask_status_t monotonic_clock_wait_until(monotonic_clock_mark_t when); // Wait for the specified duration to elapse. extern wasip3_subtask_status_t monotonic_clock_wait_for(monotonic_clock_duration_t how_long); -// Imported Functions from `wasi:clocks/wall-clock@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:clocks/system-clock@0.3.0-rc-2026-01-06` // Read the current value of the clock. // // This clock is not monotonic, therefore calling this function repeatedly // will not necessarily produce a sequence of non-decreasing values. // -// The returned timestamps represent the number of seconds since -// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], -// also known as [Unix Time]. -// // The nanoseconds field of the output is always less than 1000000000. -// -// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 -// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time -extern void wall_clock_now(wall_clock_datetime_t *ret); -// Query the resolution of the clock. -// -// The nanoseconds field of the output is always less than 1000000000. -extern void wall_clock_get_resolution(wall_clock_datetime_t *ret); +extern void wasi_clocks_system_clock_now(wasi_clocks_system_clock_instant_t *ret); +// Query the resolution of the clock. Returns the smallest duration of time +// that the implementation permits distinguishing. +extern wasi_clocks_system_clock_duration_t wasi_clocks_system_clock_get_resolution(void); -// Imported Functions from `wasi:filesystem/types@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:filesystem/types@0.3.0-rc-2026-01-06` // Return a stream for reading from a file. // // Multiple read, write, and append streams may be active on the same open @@ -1220,11 +1226,11 @@ extern wasip3_subtask_status_t filesystem_method_descriptor_metadata_hash(filesy // This performs the same hash computation as `metadata-hash`. extern wasip3_subtask_status_t filesystem_method_descriptor_metadata_hash_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip3_string_t path, filesystem_result_metadata_hash_value_error_code_t *result); -// Imported Functions from `wasi:filesystem/preopens@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:filesystem/preopens@0.3.0-rc-2026-01-06` // Return the set of preopened directories, and their paths. extern void filesystem_preopens_get_directories(filesystem_preopens_list_tuple2_own_descriptor_string_t *ret); -// Imported Functions from `wasi:sockets/types@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:sockets/types@0.3.0-rc-2026-01-06` // Create a new TCP socket. // // Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. @@ -1737,7 +1743,7 @@ extern bool sockets_method_udp_socket_set_receive_buffer_size(sockets_borrow_udp extern bool sockets_method_udp_socket_get_send_buffer_size(sockets_borrow_udp_socket_t self, uint64_t *ret, sockets_error_code_t *err); extern bool sockets_method_udp_socket_set_send_buffer_size(sockets_borrow_udp_socket_t self, uint64_t value, sockets_error_code_t *err); -// Imported Functions from `wasi:sockets/ip-name-lookup@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:sockets/ip-name-lookup@0.3.0-rc-2026-01-06` // Resolve an internet host name to a list of IP addresses. // // Unicode domain names are automatically converted to ASCII using IDNA encoding. @@ -1762,7 +1768,7 @@ extern bool sockets_method_udp_socket_set_send_buffer_size(sockets_borrow_udp_so // - extern wasip3_subtask_status_t ip_name_lookup_resolve_addresses(wasip3_string_t name, ip_name_lookup_result_list_ip_address_error_code_t *result); -// Imported Functions from `wasi:random/random@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:random/random@0.3.0-rc-2026-01-06` // Return `len` cryptographically-secure random or pseudo-random bytes. // // This function must produce data at least as cryptographically secure and @@ -1782,7 +1788,7 @@ extern void random_get_random_bytes(uint64_t len, wasip3_list_u8_t *ret); // represented as a `u64`. extern uint64_t random_get_random_u64(void); -// Imported Functions from `wasi:random/insecure@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:random/insecure@0.3.0-rc-2026-01-06` // Return `len` insecure pseudo-random bytes. // // This function is not cryptographically secure. Do not use it for @@ -1798,7 +1804,7 @@ extern void random_insecure_get_insecure_random_bytes(uint64_t len, wasip3_list_ // `get-insecure-random-bytes`, represented as a `u64`. extern uint64_t random_insecure_get_insecure_random_u64(void); -// Imported Functions from `wasi:random/insecure-seed@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:random/insecure-seed@0.3.0-rc-2026-01-06` // Return a 128-bit value that may contain a pseudo-random value. // // The returned value is not required to be computed from a CSPRNG, and may @@ -1872,7 +1878,7 @@ void terminal_stdout_option_own_terminal_output_free(terminal_stdout_option_own_ void terminal_stderr_option_own_terminal_output_free(terminal_stderr_option_own_terminal_output_t *ptr); -void filesystem_option_datetime_free(filesystem_option_datetime_t *ptr); +void filesystem_option_instant_free(filesystem_option_instant_t *ptr); void filesystem_descriptor_stat_free(filesystem_descriptor_stat_t *ptr); @@ -2021,6 +2027,11 @@ void wasip3_string_set(wasip3_string_t *ret, const char*s); // stores it into the component model string `ret`. void wasip3_string_dup(wasip3_string_t *ret, const char*s); +// Creates a copy of the input string `s` with length `len` and +// stores it into the component model string `ret`. +// The length is specified in code units (bytes for UTF-8, 16-bit values for UTF-16). +void wasip3_string_dup_n(wasip3_string_t *ret, const char*s, size_t len); + // Deallocates the string pointed to by `ret`, deallocating // the memory behind the string. void wasip3_string_free(wasip3_string_t *ret); diff --git a/libc-bottom-half/sources/wasip2.c b/libc-bottom-half/sources/wasip2.c index ef7c5d627..ef3f67ba2 100644 --- a/libc-bottom-half/sources/wasip2.c +++ b/libc-bottom-half/sources/wasip2.c @@ -1,4 +1,4 @@ -// Generated by `wit-bindgen` 0.48.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! #include "wasi/wasip2.h" #include #include @@ -387,15 +387,15 @@ extern void __wasm_import_tcp_create_socket_create_tcp_socket(int32_t, uint8_t * // Imported Functions from `wasi:sockets/ip-name-lookup@0.2.0` -__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0"), __import_name__("resolve-addresses"))) -extern void __wasm_import_ip_name_lookup_resolve_addresses(int32_t, uint8_t *, size_t, uint8_t *); - __attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0"), __import_name__("[method]resolve-address-stream.resolve-next-address"))) extern void __wasm_import_ip_name_lookup_method_resolve_address_stream_resolve_next_address(int32_t, uint8_t *); __attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0"), __import_name__("[method]resolve-address-stream.subscribe"))) extern int32_t __wasm_import_ip_name_lookup_method_resolve_address_stream_subscribe(int32_t); +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0"), __import_name__("resolve-addresses"))) +extern void __wasm_import_ip_name_lookup_resolve_addresses(int32_t, uint8_t *, size_t, uint8_t *); + // Imported Functions from `wasi:random/random@0.2.0` __attribute__((__import_module__("wasi:random/random@0.2.0"), __import_name__("get-random-bytes"))) @@ -1002,12 +1002,6 @@ ip_name_lookup_borrow_resolve_address_stream_t ip_name_lookup_borrow_resolve_add return (ip_name_lookup_borrow_resolve_address_stream_t) { arg.__handle }; } -void ip_name_lookup_result_own_resolve_address_stream_error_code_free(ip_name_lookup_result_own_resolve_address_stream_error_code_t *ptr) { - if (!ptr->is_err) { - } else { - } -} - void ip_name_lookup_option_ip_address_free(ip_name_lookup_option_ip_address_t *ptr) { if (ptr->is_some) { ip_name_lookup_ip_address_free(&ptr->val); @@ -1021,6 +1015,12 @@ void ip_name_lookup_result_option_ip_address_error_code_free(ip_name_lookup_resu } } +void ip_name_lookup_result_own_resolve_address_stream_error_code_free(ip_name_lookup_result_own_resolve_address_stream_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + void wasip2_string_set(wasip2_string_t *ret, const char*s) { ret->ptr = (uint8_t*) s; ret->len = strlen(s); @@ -1032,6 +1032,12 @@ void wasip2_string_dup(wasip2_string_t *ret, const char*s) { memcpy(ret->ptr, s, ret->len * 1); } +void wasip2_string_dup_n(wasip2_string_t *ret, const char*s, size_t len) { + ret->len = len; + ret->ptr = (uint8_t*) cabi_realloc(NULL, 0, 1, ret->len * 1); + memcpy(ret->ptr, s, ret->len * 1); +} + void wasip2_string_free(wasip2_string_t *ret) { if (ret->len > 0) { free(ret->ptr); @@ -4195,33 +4201,6 @@ bool tcp_create_socket_create_tcp_socket(tcp_create_socket_ip_address_family_t a } } -bool ip_name_lookup_resolve_addresses(ip_name_lookup_borrow_network_t network, wasip2_string_t *name, ip_name_lookup_own_resolve_address_stream_t *ret, ip_name_lookup_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - uint8_t *ptr = (uint8_t *) &ret_area; - __wasm_import_ip_name_lookup_resolve_addresses((network).__handle, (uint8_t *) (*name).ptr, (*name).len, ptr); - ip_name_lookup_result_own_resolve_address_stream_error_code_t result; - switch ((int32_t) *((uint8_t*) (ptr + 0))) { - case 0: { - result.is_err = false; - result.val.ok = (ip_name_lookup_own_resolve_address_stream_t) { *((int32_t*) (ptr + 4)) }; - break; - } - case 1: { - result.is_err = true; - result.val.err = (int32_t) *((uint8_t*) (ptr + 4)); - break; - } - } - if (!result.is_err) { - *ret = result.val.ok; - return 1; - } else { - *err = result.val.err; - return 0; - } -} - bool ip_name_lookup_method_resolve_address_stream_resolve_next_address(ip_name_lookup_borrow_resolve_address_stream_t self, ip_name_lookup_option_ip_address_t *ret, ip_name_lookup_error_code_t *err) { __attribute__((__aligned__(2))) uint8_t ret_area[22]; @@ -4294,6 +4273,33 @@ ip_name_lookup_own_pollable_t ip_name_lookup_method_resolve_address_stream_subsc return (ip_name_lookup_own_pollable_t) { ret }; } +bool ip_name_lookup_resolve_addresses(ip_name_lookup_borrow_network_t network, wasip2_string_t *name, ip_name_lookup_own_resolve_address_stream_t *ret, ip_name_lookup_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + uint8_t *ptr = (uint8_t *) &ret_area; + __wasm_import_ip_name_lookup_resolve_addresses((network).__handle, (uint8_t *) (*name).ptr, (*name).len, ptr); + ip_name_lookup_result_own_resolve_address_stream_error_code_t result; + switch ((int32_t) *((uint8_t*) (ptr + 0))) { + case 0: { + result.is_err = false; + result.val.ok = (ip_name_lookup_own_resolve_address_stream_t) { *((int32_t*) (ptr + 4)) }; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) *((uint8_t*) (ptr + 4)); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + void random_get_random_bytes(uint64_t len, wasip2_list_u8_t *ret) { __attribute__((__aligned__(sizeof(void*)))) uint8_t ret_area[(2*sizeof(void*))]; diff --git a/libc-bottom-half/sources/wasip2_component_type.o b/libc-bottom-half/sources/wasip2_component_type.o index 92cccf9b4a38544eccbccfeaabe600a201aa39a4..abbd242946ebf1c4c3b4933cb92293b05f6a0461 100644 GIT binary patch delta 34 pcmcZ?axY{9x0aZRo&j%pW{GZ6W?o8qYMyQ~n}MFG;bcWETL99M3d{fi delta 34 pcmcZ?axY{9x0aZpo)K?(W{GZ6W?o8qYMyQ~n}ME*#biY-TL99L3ef-n diff --git a/libc-bottom-half/sources/wasip3.c b/libc-bottom-half/sources/wasip3.c index b58e84ded..f37ac874f 100644 --- a/libc-bottom-half/sources/wasip3.c +++ b/libc-bottom-half/sources/wasip3.c @@ -1,304 +1,304 @@ -// Generated by `wit-bindgen` 0.48.0. DO NOT EDIT! +// Generated by `wit-bindgen` 0.51.0. DO NOT EDIT! #include "wasi/wasip3.h" #include #include -// Imported Functions from `wasi:cli/environment@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/environment@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2025-09-16"), __import_name__("get-environment"))) +__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2026-01-06"), __import_name__("get-environment"))) extern void __wasm_import_environment_get_environment(uint8_t *); -__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2025-09-16"), __import_name__("get-arguments"))) +__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2026-01-06"), __import_name__("get-arguments"))) extern void __wasm_import_environment_get_arguments(uint8_t *); -__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2025-09-16"), __import_name__("get-initial-cwd"))) +__attribute__((__import_module__("wasi:cli/environment@0.3.0-rc-2026-01-06"), __import_name__("get-initial-cwd"))) extern void __wasm_import_environment_get_initial_cwd(uint8_t *); -// Imported Functions from `wasi:cli/exit@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/exit@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/exit@0.3.0-rc-2025-09-16"), __import_name__("exit"))) +__attribute__((__import_module__("wasi:cli/exit@0.3.0-rc-2026-01-06"), __import_name__("exit"))) _Noreturn extern void __wasm_import_exit_exit(int32_t); -// Imported Functions from `wasi:cli/stdin@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/stdin@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("read-via-stream"))) extern void __wasm_import_stdin_read_via_stream(uint8_t *); -// Imported Functions from `wasi:cli/stdout@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/stdout@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/stdout@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]write-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdout@0.3.0-rc-2026-01-06"), __import_name__("[async-lower]write-via-stream"))) extern int32_t __wasm_import_stdout_write_via_stream(int32_t, uint8_t *); -// Imported Functions from `wasi:cli/stderr@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/stderr@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/stderr@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]write-via-stream"))) +__attribute__((__import_module__("wasi:cli/stderr@0.3.0-rc-2026-01-06"), __import_name__("[async-lower]write-via-stream"))) extern int32_t __wasm_import_stderr_write_via_stream(int32_t, uint8_t *); -// Imported Functions from `wasi:cli/terminal-stdin@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/terminal-stdin@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/terminal-stdin@0.3.0-rc-2025-09-16"), __import_name__("get-terminal-stdin"))) +__attribute__((__import_module__("wasi:cli/terminal-stdin@0.3.0-rc-2026-01-06"), __import_name__("get-terminal-stdin"))) extern void __wasm_import_terminal_stdin_get_terminal_stdin(uint8_t *); -// Imported Functions from `wasi:cli/terminal-stdout@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/terminal-stdout@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/terminal-stdout@0.3.0-rc-2025-09-16"), __import_name__("get-terminal-stdout"))) +__attribute__((__import_module__("wasi:cli/terminal-stdout@0.3.0-rc-2026-01-06"), __import_name__("get-terminal-stdout"))) extern void __wasm_import_terminal_stdout_get_terminal_stdout(uint8_t *); -// Imported Functions from `wasi:cli/terminal-stderr@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:cli/terminal-stderr@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:cli/terminal-stderr@0.3.0-rc-2025-09-16"), __import_name__("get-terminal-stderr"))) +__attribute__((__import_module__("wasi:cli/terminal-stderr@0.3.0-rc-2026-01-06"), __import_name__("get-terminal-stderr"))) extern void __wasm_import_terminal_stderr_get_terminal_stderr(uint8_t *); -// Imported Functions from `wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16"), __import_name__("now"))) +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06"), __import_name__("now"))) extern int64_t __wasm_import_monotonic_clock_now(void); -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16"), __import_name__("get-resolution"))) +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06"), __import_name__("get-resolution"))) extern int64_t __wasm_import_monotonic_clock_get_resolution(void); -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]wait-until"))) +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06"), __import_name__("[async-lower]wait-until"))) extern int32_t __wasm_import_monotonic_clock_wait_until(int64_t); -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]wait-for"))) +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.3.0-rc-2026-01-06"), __import_name__("[async-lower]wait-for"))) extern int32_t __wasm_import_monotonic_clock_wait_for(int64_t); -// Imported Functions from `wasi:clocks/wall-clock@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:clocks/system-clock@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:clocks/wall-clock@0.3.0-rc-2025-09-16"), __import_name__("now"))) -extern void __wasm_import_wall_clock_now(uint8_t *); +__attribute__((__import_module__("wasi:clocks/system-clock@0.3.0-rc-2026-01-06"), __import_name__("now"))) +extern void __wasm_import_wasi_clocks_system_clock_now(uint8_t *); -__attribute__((__import_module__("wasi:clocks/wall-clock@0.3.0-rc-2025-09-16"), __import_name__("get-resolution"))) -extern void __wasm_import_wall_clock_get_resolution(uint8_t *); +__attribute__((__import_module__("wasi:clocks/system-clock@0.3.0-rc-2026-01-06"), __import_name__("get-resolution"))) +extern int64_t __wasm_import_wasi_clocks_system_clock_get_resolution(void); -// Imported Functions from `wasi:filesystem/types@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:filesystem/types@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[method]descriptor.read-via-stream"))) extern void __wasm_import_filesystem_method_descriptor_read_via_stream(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.write-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.write-via-stream"))) extern int32_t __wasm_import_filesystem_method_descriptor_write_via_stream(int32_t, int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.append-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.append-via-stream"))) extern int32_t __wasm_import_filesystem_method_descriptor_append_via_stream(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.advise"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.advise"))) extern int32_t __wasm_import_filesystem_method_descriptor_advise(int32_t, int64_t, int64_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.sync-data"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.sync-data"))) extern int32_t __wasm_import_filesystem_method_descriptor_sync_data(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.get-flags"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.get-flags"))) extern int32_t __wasm_import_filesystem_method_descriptor_get_flags(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.get-type"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.get-type"))) extern int32_t __wasm_import_filesystem_method_descriptor_get_type(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.set-size"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.set-size"))) extern int32_t __wasm_import_filesystem_method_descriptor_set_size(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.set-times"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.set-times"))) extern int32_t __wasm_import_filesystem_method_descriptor_set_times(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.read-directory"))) extern int32_t __wasm_import_filesystem_method_descriptor_read_directory(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.sync"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.sync"))) extern int32_t __wasm_import_filesystem_method_descriptor_sync(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.create-directory-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.create-directory-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_create_directory_at(int32_t, uint8_t *, size_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.stat"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.stat"))) extern int32_t __wasm_import_filesystem_method_descriptor_stat(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.stat-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.stat-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_stat_at(int32_t, int32_t, uint8_t *, size_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.set-times-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.set-times-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_set_times_at(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.link-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.link-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_link_at(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.open-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.open-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_open_at(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.readlink-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.readlink-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_readlink_at(int32_t, uint8_t *, size_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.remove-directory-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.remove-directory-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_remove_directory_at(int32_t, uint8_t *, size_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.rename-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.rename-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_rename_at(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.symlink-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.symlink-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_symlink_at(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.unlink-file-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.unlink-file-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_unlink_file_at(int32_t, uint8_t *, size_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.is-same-object"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.is-same-object"))) extern int32_t __wasm_import_filesystem_method_descriptor_is_same_object(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.metadata-hash"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.metadata-hash"))) extern int32_t __wasm_import_filesystem_method_descriptor_metadata_hash(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]descriptor.metadata-hash-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]descriptor.metadata-hash-at"))) extern int32_t __wasm_import_filesystem_method_descriptor_metadata_hash_at(int32_t, int32_t, uint8_t *, size_t, uint8_t *); -// Imported Functions from `wasi:filesystem/preopens@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:filesystem/preopens@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:filesystem/preopens@0.3.0-rc-2025-09-16"), __import_name__("get-directories"))) +__attribute__((__import_module__("wasi:filesystem/preopens@0.3.0-rc-2026-01-06"), __import_name__("get-directories"))) extern void __wasm_import_filesystem_preopens_get_directories(uint8_t *); -// Imported Functions from `wasi:sockets/types@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:sockets/types@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[static]tcp-socket.create"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[static]tcp-socket.create"))) extern void __wasm_import_sockets_static_tcp_socket_create(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.bind"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.bind"))) extern void __wasm_import_sockets_method_tcp_socket_bind(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]tcp-socket.connect"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]tcp-socket.connect"))) extern int32_t __wasm_import_sockets_method_tcp_socket_connect(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.listen"))) extern void __wasm_import_sockets_method_tcp_socket_listen(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]tcp-socket.send"))) extern int32_t __wasm_import_sockets_method_tcp_socket_send(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.receive"))) extern void __wasm_import_sockets_method_tcp_socket_receive(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-local-address"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-local-address"))) extern void __wasm_import_sockets_method_tcp_socket_get_local_address(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-remote-address"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-remote-address"))) extern void __wasm_import_sockets_method_tcp_socket_get_remote_address(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-is-listening"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-is-listening"))) extern int32_t __wasm_import_sockets_method_tcp_socket_get_is_listening(int32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-address-family"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-address-family"))) extern int32_t __wasm_import_sockets_method_tcp_socket_get_address_family(int32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-listen-backlog-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-listen-backlog-size"))) extern void __wasm_import_sockets_method_tcp_socket_set_listen_backlog_size(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-keep-alive-enabled"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-keep-alive-enabled"))) extern void __wasm_import_sockets_method_tcp_socket_get_keep_alive_enabled(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-keep-alive-enabled"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-keep-alive-enabled"))) extern void __wasm_import_sockets_method_tcp_socket_set_keep_alive_enabled(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-keep-alive-idle-time"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-keep-alive-idle-time"))) extern void __wasm_import_sockets_method_tcp_socket_get_keep_alive_idle_time(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-keep-alive-idle-time"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-keep-alive-idle-time"))) extern void __wasm_import_sockets_method_tcp_socket_set_keep_alive_idle_time(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-keep-alive-interval"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-keep-alive-interval"))) extern void __wasm_import_sockets_method_tcp_socket_get_keep_alive_interval(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-keep-alive-interval"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-keep-alive-interval"))) extern void __wasm_import_sockets_method_tcp_socket_set_keep_alive_interval(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-keep-alive-count"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-keep-alive-count"))) extern void __wasm_import_sockets_method_tcp_socket_get_keep_alive_count(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-keep-alive-count"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-keep-alive-count"))) extern void __wasm_import_sockets_method_tcp_socket_set_keep_alive_count(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-hop-limit"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-hop-limit"))) extern void __wasm_import_sockets_method_tcp_socket_get_hop_limit(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-hop-limit"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-hop-limit"))) extern void __wasm_import_sockets_method_tcp_socket_set_hop_limit(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-receive-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-receive-buffer-size"))) extern void __wasm_import_sockets_method_tcp_socket_get_receive_buffer_size(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-receive-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-receive-buffer-size"))) extern void __wasm_import_sockets_method_tcp_socket_set_receive_buffer_size(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.get-send-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.get-send-buffer-size"))) extern void __wasm_import_sockets_method_tcp_socket_get_send_buffer_size(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]tcp-socket.set-send-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]tcp-socket.set-send-buffer-size"))) extern void __wasm_import_sockets_method_tcp_socket_set_send_buffer_size(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[static]udp-socket.create"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[static]udp-socket.create"))) extern void __wasm_import_sockets_static_udp_socket_create(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.bind"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.bind"))) extern void __wasm_import_sockets_method_udp_socket_bind(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.connect"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.connect"))) extern void __wasm_import_sockets_method_udp_socket_connect(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.disconnect"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.disconnect"))) extern void __wasm_import_sockets_method_udp_socket_disconnect(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]udp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]udp-socket.send"))) extern int32_t __wasm_import_sockets_method_udp_socket_send(uint8_t *, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][method]udp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][method]udp-socket.receive"))) extern int32_t __wasm_import_sockets_method_udp_socket_receive(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-local-address"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.get-local-address"))) extern void __wasm_import_sockets_method_udp_socket_get_local_address(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-remote-address"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.get-remote-address"))) extern void __wasm_import_sockets_method_udp_socket_get_remote_address(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-address-family"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.get-address-family"))) extern int32_t __wasm_import_sockets_method_udp_socket_get_address_family(int32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-unicast-hop-limit"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.get-unicast-hop-limit"))) extern void __wasm_import_sockets_method_udp_socket_get_unicast_hop_limit(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.set-unicast-hop-limit"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.set-unicast-hop-limit"))) extern void __wasm_import_sockets_method_udp_socket_set_unicast_hop_limit(int32_t, int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-receive-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.get-receive-buffer-size"))) extern void __wasm_import_sockets_method_udp_socket_get_receive_buffer_size(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.set-receive-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.set-receive-buffer-size"))) extern void __wasm_import_sockets_method_udp_socket_set_receive_buffer_size(int32_t, int64_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.get-send-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.get-send-buffer-size"))) extern void __wasm_import_sockets_method_udp_socket_get_send_buffer_size(int32_t, uint8_t *); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[method]udp-socket.set-send-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[method]udp-socket.set-send-buffer-size"))) extern void __wasm_import_sockets_method_udp_socket_set_send_buffer_size(int32_t, int64_t, uint8_t *); -// Imported Functions from `wasi:sockets/ip-name-lookup@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:sockets/ip-name-lookup@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.3.0-rc-2025-09-16"), __import_name__("[async-lower]resolve-addresses"))) +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.3.0-rc-2026-01-06"), __import_name__("[async-lower]resolve-addresses"))) extern int32_t __wasm_import_ip_name_lookup_resolve_addresses(uint8_t *, size_t, uint8_t *); -// Imported Functions from `wasi:random/random@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:random/random@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:random/random@0.3.0-rc-2025-09-16"), __import_name__("get-random-bytes"))) +__attribute__((__import_module__("wasi:random/random@0.3.0-rc-2026-01-06"), __import_name__("get-random-bytes"))) extern void __wasm_import_random_get_random_bytes(int64_t, uint8_t *); -__attribute__((__import_module__("wasi:random/random@0.3.0-rc-2025-09-16"), __import_name__("get-random-u64"))) +__attribute__((__import_module__("wasi:random/random@0.3.0-rc-2026-01-06"), __import_name__("get-random-u64"))) extern int64_t __wasm_import_random_get_random_u64(void); -// Imported Functions from `wasi:random/insecure@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:random/insecure@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:random/insecure@0.3.0-rc-2025-09-16"), __import_name__("get-insecure-random-bytes"))) +__attribute__((__import_module__("wasi:random/insecure@0.3.0-rc-2026-01-06"), __import_name__("get-insecure-random-bytes"))) extern void __wasm_import_random_insecure_get_insecure_random_bytes(int64_t, uint8_t *); -__attribute__((__import_module__("wasi:random/insecure@0.3.0-rc-2025-09-16"), __import_name__("get-insecure-random-u64"))) +__attribute__((__import_module__("wasi:random/insecure@0.3.0-rc-2026-01-06"), __import_name__("get-insecure-random-u64"))) extern int64_t __wasm_import_random_insecure_get_insecure_random_u64(void); -// Imported Functions from `wasi:random/insecure-seed@0.3.0-rc-2025-09-16` +// Imported Functions from `wasi:random/insecure-seed@0.3.0-rc-2026-01-06` -__attribute__((__import_module__("wasi:random/insecure-seed@0.3.0-rc-2025-09-16"), __import_name__("get-insecure-seed"))) +__attribute__((__import_module__("wasi:random/insecure-seed@0.3.0-rc-2026-01-06"), __import_name__("get-insecure-seed"))) extern void __wasm_import_random_insecure_seed_get_insecure_seed(uint8_t *); // Canonical ABI intrinsics @@ -358,19 +358,19 @@ void stdin_result_void_error_code_free(stdin_result_void_error_code_t *ptr) { } } -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[stream-new-0]read-via-stream"))) extern uint64_t stdin_stream_u8__new(void); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-read-0]read-via-stream"))) extern uint32_t stdin_stream_u8__read(uint32_t, uint8_t*, size_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-write-0]read-via-stream"))) extern uint32_t stdin_stream_u8__write(uint32_t, const uint8_t*, size_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-read-0]read-via-stream"))) extern uint32_t stdin_stream_u8__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-write-0]read-via-stream"))) extern uint32_t stdin_stream_u8__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-readable-0]read-via-stream"))) extern void stdin_stream_u8__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-writable-0]read-via-stream"))) extern void stdin_stream_u8__drop_writable(uint32_t); stdin_stream_u8_t stdin_stream_u8_new(stdin_stream_u8_writer_t *writer) { @@ -404,19 +404,19 @@ void stdin_stream_u8_drop_writable(stdin_stream_u8_writer_t writer) { } -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-new-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[future-new-1]read-via-stream"))) extern uint64_t stdin_future_result_void_error_code__new(void); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-read-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][future-read-1]read-via-stream"))) extern uint32_t stdin_future_result_void_error_code__read(uint32_t, uint8_t*); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-write-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][future-write-1]read-via-stream"))) extern uint32_t stdin_future_result_void_error_code__write(uint32_t, const uint8_t*); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-read-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[future-cancel-read-1]read-via-stream"))) extern uint32_t stdin_future_result_void_error_code__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-write-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[future-cancel-write-1]read-via-stream"))) extern uint32_t stdin_future_result_void_error_code__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-readable-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[future-drop-readable-1]read-via-stream"))) extern void stdin_future_result_void_error_code__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-writable-1]read-via-stream"))) +__attribute__((__import_module__("wasi:cli/stdin@0.3.0-rc-2026-01-06"), __import_name__("[future-drop-writable-1]read-via-stream"))) extern void stdin_future_result_void_error_code__drop_writable(uint32_t); stdin_future_result_void_error_code_t stdin_future_result_void_error_code_new(stdin_future_result_void_error_code_writer_t *writer) { @@ -462,7 +462,7 @@ void stderr_result_void_error_code_free(stderr_result_void_error_code_t *ptr) { } } -__attribute__((__import_module__("wasi:cli/terminal-input@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]terminal-input"))) +__attribute__((__import_module__("wasi:cli/terminal-input@0.3.0-rc-2026-01-06"), __import_name__("[resource-drop]terminal-input"))) extern void __wasm_import_terminal_input_terminal_input_drop(int32_t handle); void terminal_input_terminal_input_drop_own(terminal_input_own_terminal_input_t handle) { @@ -473,7 +473,7 @@ terminal_input_borrow_terminal_input_t terminal_input_borrow_terminal_input(term return (terminal_input_borrow_terminal_input_t) { arg.__handle }; } -__attribute__((__import_module__("wasi:cli/terminal-output@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]terminal-output"))) +__attribute__((__import_module__("wasi:cli/terminal-output@0.3.0-rc-2026-01-06"), __import_name__("[resource-drop]terminal-output"))) extern void __wasm_import_terminal_output_terminal_output_drop(int32_t handle); void terminal_output_terminal_output_drop_own(terminal_output_own_terminal_output_t handle) { @@ -499,15 +499,15 @@ void terminal_stderr_option_own_terminal_output_free(terminal_stderr_option_own_ } } -void filesystem_option_datetime_free(filesystem_option_datetime_t *ptr) { +void filesystem_option_instant_free(filesystem_option_instant_t *ptr) { if (ptr->is_some) { } } void filesystem_descriptor_stat_free(filesystem_descriptor_stat_t *ptr) { - filesystem_option_datetime_free(&ptr->data_access_timestamp); - filesystem_option_datetime_free(&ptr->data_modification_timestamp); - filesystem_option_datetime_free(&ptr->status_change_timestamp); + filesystem_option_instant_free(&ptr->data_access_timestamp); + filesystem_option_instant_free(&ptr->data_modification_timestamp); + filesystem_option_instant_free(&ptr->status_change_timestamp); } void filesystem_new_timestamp_free(filesystem_new_timestamp_t *ptr) { @@ -522,7 +522,7 @@ void filesystem_directory_entry_free(filesystem_directory_entry_t *ptr) { wasip3_string_free(&ptr->name); } -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]descriptor"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[resource-drop]descriptor"))) extern void __wasm_import_filesystem_descriptor_drop(int32_t handle); void filesystem_descriptor_drop_own(filesystem_own_descriptor_t handle) { @@ -577,19 +577,19 @@ void filesystem_result_metadata_hash_value_error_code_free(filesystem_result_met } } -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-new-0][method]descriptor.read-via-stream"))) extern uint64_t filesystem_stream_u8__new(void); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-read-0][method]descriptor.read-via-stream"))) extern uint32_t filesystem_stream_u8__read(uint32_t, uint8_t*, size_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-write-0][method]descriptor.read-via-stream"))) extern uint32_t filesystem_stream_u8__write(uint32_t, const uint8_t*, size_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-read-0][method]descriptor.read-via-stream"))) extern uint32_t filesystem_stream_u8__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-write-0][method]descriptor.read-via-stream"))) extern uint32_t filesystem_stream_u8__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-readable-0][method]descriptor.read-via-stream"))) extern void filesystem_stream_u8__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-writable-0][method]descriptor.read-via-stream"))) extern void filesystem_stream_u8__drop_writable(uint32_t); filesystem_stream_u8_t filesystem_stream_u8_new(filesystem_stream_u8_writer_t *writer) { @@ -623,19 +623,19 @@ void filesystem_stream_u8_drop_writable(filesystem_stream_u8_writer_t writer) { } -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-new-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[future-new-1][method]descriptor.read-via-stream"))) extern uint64_t filesystem_future_result_void_error_code__new(void); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-read-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][future-read-1][method]descriptor.read-via-stream"))) extern uint32_t filesystem_future_result_void_error_code__read(uint32_t, uint8_t*); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-write-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][future-write-1][method]descriptor.read-via-stream"))) extern uint32_t filesystem_future_result_void_error_code__write(uint32_t, const uint8_t*); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-read-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[future-cancel-read-1][method]descriptor.read-via-stream"))) extern uint32_t filesystem_future_result_void_error_code__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-write-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[future-cancel-write-1][method]descriptor.read-via-stream"))) extern uint32_t filesystem_future_result_void_error_code__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-readable-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[future-drop-readable-1][method]descriptor.read-via-stream"))) extern void filesystem_future_result_void_error_code__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-writable-1][method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[future-drop-writable-1][method]descriptor.read-via-stream"))) extern void filesystem_future_result_void_error_code__drop_writable(uint32_t); filesystem_future_result_void_error_code_t filesystem_future_result_void_error_code_new(filesystem_future_result_void_error_code_writer_t *writer) { @@ -669,19 +669,19 @@ void filesystem_future_result_void_error_code_drop_writable(filesystem_future_re } -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-new-0][method]descriptor.read-directory"))) extern uint64_t filesystem_stream_directory_entry__new(void); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-read-0][method]descriptor.read-directory"))) extern uint32_t filesystem_stream_directory_entry__read(uint32_t, uint8_t*, size_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-write-0][method]descriptor.read-directory"))) extern uint32_t filesystem_stream_directory_entry__write(uint32_t, const uint8_t*, size_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-read-0][method]descriptor.read-directory"))) extern uint32_t filesystem_stream_directory_entry__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-write-0][method]descriptor.read-directory"))) extern uint32_t filesystem_stream_directory_entry__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-readable-0][method]descriptor.read-directory"))) extern void filesystem_stream_directory_entry__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0][method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-writable-0][method]descriptor.read-directory"))) extern void filesystem_stream_directory_entry__drop_writable(uint32_t); filesystem_stream_directory_entry_t filesystem_stream_directory_entry_new(filesystem_stream_directory_entry_writer_t *writer) { @@ -752,7 +752,7 @@ void sockets_ip_socket_address_free(sockets_ip_socket_address_t *ptr) { } } -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]tcp-socket"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[resource-drop]tcp-socket"))) extern void __wasm_import_sockets_tcp_socket_drop(int32_t handle); void sockets_tcp_socket_drop_own(sockets_own_tcp_socket_t handle) { @@ -763,7 +763,7 @@ sockets_borrow_tcp_socket_t sockets_borrow_tcp_socket(sockets_own_tcp_socket_t a return (sockets_borrow_tcp_socket_t) { arg.__handle }; } -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[resource-drop]udp-socket"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[resource-drop]udp-socket"))) extern void __wasm_import_sockets_udp_socket_drop(int32_t handle); void sockets_udp_socket_drop_own(sockets_own_udp_socket_t handle) { @@ -863,19 +863,19 @@ void sockets_result_tuple2_list_u8_ip_socket_address_error_code_free(sockets_res } } -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-new-0][method]tcp-socket.listen"))) extern uint64_t sockets_stream_own_tcp_socket__new(void); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-read-0][method]tcp-socket.listen"))) extern uint32_t sockets_stream_own_tcp_socket__read(uint32_t, uint8_t*, size_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-write-0][method]tcp-socket.listen"))) extern uint32_t sockets_stream_own_tcp_socket__write(uint32_t, const uint8_t*, size_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-read-0][method]tcp-socket.listen"))) extern uint32_t sockets_stream_own_tcp_socket__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-write-0][method]tcp-socket.listen"))) extern uint32_t sockets_stream_own_tcp_socket__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-readable-0][method]tcp-socket.listen"))) extern void sockets_stream_own_tcp_socket__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0][method]tcp-socket.listen"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-writable-0][method]tcp-socket.listen"))) extern void sockets_stream_own_tcp_socket__drop_writable(uint32_t); sockets_stream_own_tcp_socket_t sockets_stream_own_tcp_socket_new(sockets_stream_own_tcp_socket_writer_t *writer) { @@ -909,19 +909,19 @@ void sockets_stream_own_tcp_socket_drop_writable(sockets_stream_own_tcp_socket_w } -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-new-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-new-0][method]tcp-socket.send"))) extern uint64_t sockets_stream_u8__new(void); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-read-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-read-0][method]tcp-socket.send"))) extern uint32_t sockets_stream_u8__read(uint32_t, uint8_t*, size_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][stream-write-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][stream-write-0][method]tcp-socket.send"))) extern uint32_t sockets_stream_u8__write(uint32_t, const uint8_t*, size_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-read-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-read-0][method]tcp-socket.send"))) extern uint32_t sockets_stream_u8__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-cancel-write-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-cancel-write-0][method]tcp-socket.send"))) extern uint32_t sockets_stream_u8__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-readable-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-readable-0][method]tcp-socket.send"))) extern void sockets_stream_u8__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[stream-drop-writable-0][method]tcp-socket.send"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[stream-drop-writable-0][method]tcp-socket.send"))) extern void sockets_stream_u8__drop_writable(uint32_t); sockets_stream_u8_t sockets_stream_u8_new(sockets_stream_u8_writer_t *writer) { @@ -955,19 +955,19 @@ void sockets_stream_u8_drop_writable(sockets_stream_u8_writer_t writer) { } -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-new-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[future-new-1][method]tcp-socket.receive"))) extern uint64_t sockets_future_result_void_error_code__new(void); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-read-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][future-read-1][method]tcp-socket.receive"))) extern uint32_t sockets_future_result_void_error_code__read(uint32_t, uint8_t*); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[async-lower][future-write-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[async-lower][future-write-1][method]tcp-socket.receive"))) extern uint32_t sockets_future_result_void_error_code__write(uint32_t, const uint8_t*); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-read-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[future-cancel-read-1][method]tcp-socket.receive"))) extern uint32_t sockets_future_result_void_error_code__cancel_read(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-cancel-write-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[future-cancel-write-1][method]tcp-socket.receive"))) extern uint32_t sockets_future_result_void_error_code__cancel_write(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-readable-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[future-drop-readable-1][method]tcp-socket.receive"))) extern void sockets_future_result_void_error_code__drop_readable(uint32_t); -__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2025-09-16"), __import_name__("[future-drop-writable-1][method]tcp-socket.receive"))) +__attribute__((__import_module__("wasi:sockets/types@0.3.0-rc-2026-01-06"), __import_name__("[future-drop-writable-1][method]tcp-socket.receive"))) extern void sockets_future_result_void_error_code__drop_writable(uint32_t); sockets_future_result_void_error_code_t sockets_future_result_void_error_code_new(sockets_future_result_void_error_code_writer_t *writer) { @@ -1034,6 +1034,12 @@ void wasip3_string_dup(wasip3_string_t *ret, const char*s) { memcpy(ret->ptr, s, ret->len * 1); } +void wasip3_string_dup_n(wasip3_string_t *ret, const char*s, size_t len) { + ret->len = len; + ret->ptr = (uint8_t*) cabi_realloc(NULL, 0, 1, ret->len * 1); + memcpy(ret->ptr, s, ret->len * 1); +} + void wasip3_string_free(wasip3_string_t *ret) { if (ret->len > 0) { free(ret->ptr); @@ -1099,13 +1105,6 @@ void wasip3_task_cancel() { __task_cancel(); } -__attribute__((__import_module__("$root"), __import_name__("[backpressure-set]"))) -extern void __backpressure_set(bool enable); - -void wasip3_backpressure_set(bool enable) { - __backpressure_set(enable); -} - __attribute__((__import_module__("$root"), __import_name__("[backpressure-inc]"))) extern void __backpressure_inc(void); @@ -1121,33 +1120,27 @@ void wasip3_backpressure_dec(void) { } __attribute__((__import_module__("$root"), __import_name__("[context-get-0]"))) -extern void* __context_get(void); +extern void* __context_get_0(void); -void* wasip3_context_get() { - return __context_get(); +void* wasip3_context_get_0(void) { + return __context_get_0(); } __attribute__((__import_module__("$root"), __import_name__("[context-set-0]"))) -extern void __context_set(void*); +extern void __context_set_0(void*); + -void wasip3_context_set(void *val) { - return __context_set(val); +void wasip3_context_set_0(void *value) { + __context_set_0(value); } __attribute__((__import_module__("$root"), __import_name__("[thread-yield]"))) extern uint32_t __thread_yield(void); -void wasip3_yield(void) { +void wasip3_thread_yield(void) { __thread_yield(); } -__attribute__((__import_module__("$root"), __import_name__("[cancellable][thread-yield]"))) -extern uint32_t __thread_yield_cancellable(void); - -uint32_t wasip3_yield_cancellable(void) { - return __thread_yield_cancellable(); -} - // Component Adapters @@ -1281,7 +1274,7 @@ bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t * return option.is_some; } -monotonic_clock_instant_t monotonic_clock_now(void) { +monotonic_clock_mark_t monotonic_clock_now(void) { int64_t ret = __wasm_import_monotonic_clock_now(); return (uint64_t) (ret); } @@ -1291,7 +1284,7 @@ monotonic_clock_duration_t monotonic_clock_get_resolution(void) { return (uint64_t) (ret); } -wasip3_subtask_status_t monotonic_clock_wait_until(monotonic_clock_instant_t when) { +wasip3_subtask_status_t monotonic_clock_wait_until(monotonic_clock_mark_t when) { return __wasm_import_monotonic_clock_wait_until((int64_t) (when)); } @@ -1299,26 +1292,20 @@ wasip3_subtask_status_t monotonic_clock_wait_for(monotonic_clock_duration_t how_ return __wasm_import_monotonic_clock_wait_for((int64_t) (how_long)); } -void wall_clock_now(wall_clock_datetime_t *ret) { +void wasi_clocks_system_clock_now(wasi_clocks_system_clock_instant_t *ret) { __attribute__((__aligned__(8))) uint8_t ret_area[16]; uint8_t *ptr = (uint8_t *) &ret_area; - __wasm_import_wall_clock_now(ptr); - *ret = (wall_clock_datetime_t) { - (uint64_t) (uint64_t) (*((int64_t*) (ptr + 0))), + __wasm_import_wasi_clocks_system_clock_now(ptr); + *ret = (wasi_clocks_system_clock_instant_t) { + (int64_t) *((int64_t*) (ptr + 0)), (uint32_t) (uint32_t) (*((int32_t*) (ptr + 8))), }; } -void wall_clock_get_resolution(wall_clock_datetime_t *ret) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - uint8_t *ptr = (uint8_t *) &ret_area; - __wasm_import_wall_clock_get_resolution(ptr); - *ret = (wall_clock_datetime_t) { - (uint64_t) (uint64_t) (*((int64_t*) (ptr + 0))), - (uint32_t) (uint32_t) (*((int32_t*) (ptr + 8))), - }; +wasi_clocks_system_clock_duration_t wasi_clocks_system_clock_get_resolution(void) { + int64_t ret = __wasm_import_wasi_clocks_system_clock_get_resolution(); + return (uint64_t) (ret); } void filesystem_method_descriptor_read_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_tuple2_stream_u8_future_result_void_error_code_t *ret) { diff --git a/libc-bottom-half/sources/wasip3_component_type.o b/libc-bottom-half/sources/wasip3_component_type.o index 2134f29a58f9add8550532cd099d3c263b8317a3..68f4f3604b601e2b750b65bc5532d01a799cf67a 100644 GIT binary patch delta 509 zcmbPZzu10)B;(nMQf?d@Z5bVz7#$5KX4J8n=^7a78ccj+3uR5#XAFfgyBLc(A@XLd zER*w@0w#ws3BV+Cn37@4t4t0srZlq?jG4?_4P!oGu7@!*S+ZfwTP)@D@$%- zQTAj{)=mqUodS$b98AnijQlJN94Vzmi6xo&dCUw9j73cB#i_~pc`3ye+zNZ)LdOK&%r>?SkFMWC|TFYzzAlEAQLkKFMDQQ zaYiH&^Q6E%mUrS zl$4^>;$o;5#3%2Pc@7UuiOH*EuvC+DLNGftX?K?UlaO#RHo0OTClAfBUo6KgQXKFY(Ufvb}RV{vV delta 516 zcmZ2%KgWK8B;&D(Qf?fpY#AMy7#)o!X4J8n>Ka(;8cuv;3uR5#XAFfgyBLc(A@XLd zER*w@0w#ws3BV+Cn37@4t4t0srZlq?jG4?_4P!oGu7@!*S+ZfwTP)@CF4iwk%*oLOvmFfdjP(q3 zi;{JX42&QaE1R(j0yXf$&1ZCqWMXDw6hg9ca|hc}E|}Ym1{JNSDYki+;Bzhom>O}Q8Ue1%0^P)v6rdxE8J##lsw5^Klz9#hZpq0TW#i#IsmYRZ zh^UaBJXOvIE+;ejm7D_1EdufmVupG~yyclCx=ERNDe0+sy2)$?dL|Z=)8uUd5Ria9 diff --git a/wasi/wasi-libc-wasip2.wit b/wasi/wasi-libc-wasip2.wit new file mode 100644 index 000000000..a3b1657e2 --- /dev/null +++ b/wasi/wasi-libc-wasip2.wit @@ -0,0 +1,5 @@ +package wasi-libc:wasip2; + +world wasip3 { + include wasi:cli/command@0.2.0; +} \ No newline at end of file diff --git a/wasi/wasi-libc-wasip3.wit b/wasi/wasi-libc-wasip3.wit new file mode 100644 index 000000000..68726e260 --- /dev/null +++ b/wasi/wasi-libc-wasip3.wit @@ -0,0 +1,10 @@ +package wasi-libc:wasip3; + +world wasip3 { + include wasi:cli/command@0.3.0-rc-2026-01-06; + include wasi:clocks/imports@0.3.0-rc-2026-01-06; + include wasi:filesystem/imports@0.3.0-rc-2026-01-06; + include wasi:http/middleware@0.3.0-rc-2026-01-06; + include wasi:random/imports@0.3.0-rc-2026-01-06; + include wasi:sockets/imports@0.3.0-rc-2026-01-06; +} \ No newline at end of file From 640a4eb268b337c6d1ecef8859686febe38eb39b Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 10:49:49 +0000 Subject: [PATCH 23/41] Update wasip2 --- .../headers/public/wasi/__generated_wasip2.h | 1229 +++++++++++++++++ wasi/wasi-libc-wasip2.wit | 8 +- 2 files changed, 1236 insertions(+), 1 deletion(-) diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip2.h b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h index ffd7e86f7..e4f14db97 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip2.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h @@ -66,6 +66,7 @@ typedef struct { typedef io_error_own_error_t streams_own_error_t; +// An error for input-stream and output-stream operations. typedef struct streams_stream_error_t { uint8_t tag; union { @@ -73,7 +74,13 @@ typedef struct streams_stream_error_t { } val; } streams_stream_error_t; +// The last operation (a write or flush) failed before completion. +// +// More information is available in the `error` payload. #define STREAMS_STREAM_ERROR_LAST_OPERATION_FAILED 0 +// The stream is closed: no more input will be accepted by the +// stream. A closed output-stream will return this error on all +// future operations. #define STREAMS_STREAM_ERROR_CLOSED 1 typedef struct streams_own_input_stream_t { @@ -165,12 +172,17 @@ typedef struct { terminal_stderr_own_terminal_output_t val; } terminal_stderr_option_own_terminal_output_t; +// An instant in time, in nanoseconds. An instant is relative to an +// unspecified initial value, and can only be compared to instances from +// the same monotonic-clock. typedef uint64_t monotonic_clock_instant_t; +// A duration of time, in nanoseconds. typedef uint64_t monotonic_clock_duration_t; typedef poll_own_pollable_t monotonic_clock_own_pollable_t; +// A time and date in seconds plus nanoseconds. typedef struct wall_clock_datetime_t { uint64_t seconds; uint32_t nanoseconds; @@ -178,39 +190,95 @@ typedef struct wall_clock_datetime_t { typedef wall_clock_datetime_t filesystem_datetime_t; +// File size or length of a region within a file. typedef uint64_t filesystem_filesize_t; +// The type of a filesystem object referenced by a descriptor. +// +// Note: This was called `filetype` in earlier versions of WASI. typedef uint8_t filesystem_descriptor_type_t; +// The type of the descriptor or file is unknown or is different from +// any of the other types specified. #define FILESYSTEM_DESCRIPTOR_TYPE_UNKNOWN 0 +// The descriptor refers to a block device inode. #define FILESYSTEM_DESCRIPTOR_TYPE_BLOCK_DEVICE 1 +// The descriptor refers to a character device inode. #define FILESYSTEM_DESCRIPTOR_TYPE_CHARACTER_DEVICE 2 +// The descriptor refers to a directory inode. #define FILESYSTEM_DESCRIPTOR_TYPE_DIRECTORY 3 +// The descriptor refers to a named pipe. #define FILESYSTEM_DESCRIPTOR_TYPE_FIFO 4 +// The file refers to a symbolic link inode. #define FILESYSTEM_DESCRIPTOR_TYPE_SYMBOLIC_LINK 5 +// The descriptor refers to a regular file inode. #define FILESYSTEM_DESCRIPTOR_TYPE_REGULAR_FILE 6 +// The descriptor refers to a socket. #define FILESYSTEM_DESCRIPTOR_TYPE_SOCKET 7 +// Descriptor flags. +// +// Note: This was called `fdflags` in earlier versions of WASI. typedef uint8_t filesystem_descriptor_flags_t; +// Read mode: Data can be read. #define FILESYSTEM_DESCRIPTOR_FLAGS_READ (1 << 0) +// Write mode: Data can be written to. #define FILESYSTEM_DESCRIPTOR_FLAGS_WRITE (1 << 1) +// Request that writes be performed according to synchronized I/O file +// integrity completion. The data stored in the file and the file's +// metadata are synchronized. This is similar to `O_SYNC` in POSIX. +// +// The precise semantics of this operation have not yet been defined for +// WASI. At this time, it should be interpreted as a request, and not a +// requirement. #define FILESYSTEM_DESCRIPTOR_FLAGS_FILE_INTEGRITY_SYNC (1 << 2) +// Request that writes be performed according to synchronized I/O data +// integrity completion. Only the data stored in the file is +// synchronized. This is similar to `O_DSYNC` in POSIX. +// +// The precise semantics of this operation have not yet been defined for +// WASI. At this time, it should be interpreted as a request, and not a +// requirement. #define FILESYSTEM_DESCRIPTOR_FLAGS_DATA_INTEGRITY_SYNC (1 << 3) +// Requests that reads be performed at the same level of integrety +// requested for writes. This is similar to `O_RSYNC` in POSIX. +// +// The precise semantics of this operation have not yet been defined for +// WASI. At this time, it should be interpreted as a request, and not a +// requirement. #define FILESYSTEM_DESCRIPTOR_FLAGS_REQUESTED_WRITE_SYNC (1 << 4) +// Mutating directories mode: Directory contents may be mutated. +// +// When this flag is unset on a descriptor, operations using the +// descriptor which would create, rename, delete, modify the data or +// metadata of filesystem objects, or obtain another handle which +// would permit any of those, shall fail with `error-code::read-only` if +// they would otherwise succeed. +// +// This may only be set on directories. #define FILESYSTEM_DESCRIPTOR_FLAGS_MUTATE_DIRECTORY (1 << 5) +// Flags determining the method of how paths are resolved. typedef uint8_t filesystem_path_flags_t; +// As long as the resolved path corresponds to a symbolic link, it is +// expanded. #define FILESYSTEM_PATH_FLAGS_SYMLINK_FOLLOW (1 << 0) +// Open flags used by `open-at`. typedef uint8_t filesystem_open_flags_t; +// Create file if it does not exist, similar to `O_CREAT` in POSIX. #define FILESYSTEM_OPEN_FLAGS_CREATE (1 << 0) +// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. #define FILESYSTEM_OPEN_FLAGS_DIRECTORY (1 << 1) +// Fail if file already exists, similar to `O_EXCL` in POSIX. #define FILESYSTEM_OPEN_FLAGS_EXCLUSIVE (1 << 2) +// Truncate file to size 0, similar to `O_TRUNC` in POSIX. #define FILESYSTEM_OPEN_FLAGS_TRUNCATE (1 << 3) +// Number of hard links to an inode. typedef uint64_t filesystem_link_count_t; typedef struct { @@ -218,15 +286,35 @@ typedef struct { filesystem_datetime_t val; } filesystem_option_datetime_t; +// File attributes. +// +// Note: This was called `filestat` in earlier versions of WASI. typedef struct filesystem_descriptor_stat_t { + // File type. filesystem_descriptor_type_t type; + // Number of hard links to the file. filesystem_link_count_t link_count; + // For regular files, the file size in bytes. For symbolic links, the + // length in bytes of the pathname contained in the symbolic link. filesystem_filesize_t size; + // Last data access timestamp. + // + // If the `option` is none, the platform doesn't maintain an access + // timestamp for this file. filesystem_option_datetime_t data_access_timestamp; + // Last data modification timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // modification timestamp for this file. filesystem_option_datetime_t data_modification_timestamp; + // Last file status-change timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // status-change timestamp for this file. filesystem_option_datetime_t status_change_timestamp; } filesystem_descriptor_stat_t; +// When setting a timestamp, this gives the value to set it to. typedef struct filesystem_new_timestamp_t { uint8_t tag; union { @@ -234,66 +322,131 @@ typedef struct filesystem_new_timestamp_t { } val; } filesystem_new_timestamp_t; +// Leave the timestamp set to its previous value. #define FILESYSTEM_NEW_TIMESTAMP_NO_CHANGE 0 +// Set the timestamp to the current time of the system clock associated +// with the filesystem. #define FILESYSTEM_NEW_TIMESTAMP_NOW 1 +// Set the timestamp to the given value. #define FILESYSTEM_NEW_TIMESTAMP_TIMESTAMP 2 +// A directory entry. typedef struct filesystem_directory_entry_t { + // The type of the file referred to by this directory entry. filesystem_descriptor_type_t type; + // The name of the object. wasip2_string_t name; } filesystem_directory_entry_t; +// Error codes returned by functions, similar to `errno` in POSIX. +// Not all of these error codes are returned by the functions provided by this +// API; some are used in higher-level library layers, and others are provided +// merely for alignment with POSIX. typedef uint8_t filesystem_error_code_t; +// Permission denied, similar to `EACCES` in POSIX. #define FILESYSTEM_ERROR_CODE_ACCESS 0 +// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. #define FILESYSTEM_ERROR_CODE_WOULD_BLOCK 1 +// Connection already in progress, similar to `EALREADY` in POSIX. #define FILESYSTEM_ERROR_CODE_ALREADY 2 +// Bad descriptor, similar to `EBADF` in POSIX. #define FILESYSTEM_ERROR_CODE_BAD_DESCRIPTOR 3 +// Device or resource busy, similar to `EBUSY` in POSIX. #define FILESYSTEM_ERROR_CODE_BUSY 4 +// Resource deadlock would occur, similar to `EDEADLK` in POSIX. #define FILESYSTEM_ERROR_CODE_DEADLOCK 5 +// Storage quota exceeded, similar to `EDQUOT` in POSIX. #define FILESYSTEM_ERROR_CODE_QUOTA 6 +// File exists, similar to `EEXIST` in POSIX. #define FILESYSTEM_ERROR_CODE_EXIST 7 +// File too large, similar to `EFBIG` in POSIX. #define FILESYSTEM_ERROR_CODE_FILE_TOO_LARGE 8 +// Illegal byte sequence, similar to `EILSEQ` in POSIX. #define FILESYSTEM_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE 9 +// Operation in progress, similar to `EINPROGRESS` in POSIX. #define FILESYSTEM_ERROR_CODE_IN_PROGRESS 10 +// Interrupted function, similar to `EINTR` in POSIX. #define FILESYSTEM_ERROR_CODE_INTERRUPTED 11 +// Invalid argument, similar to `EINVAL` in POSIX. #define FILESYSTEM_ERROR_CODE_INVALID 12 +// I/O error, similar to `EIO` in POSIX. #define FILESYSTEM_ERROR_CODE_IO 13 +// Is a directory, similar to `EISDIR` in POSIX. #define FILESYSTEM_ERROR_CODE_IS_DIRECTORY 14 +// Too many levels of symbolic links, similar to `ELOOP` in POSIX. #define FILESYSTEM_ERROR_CODE_LOOP 15 +// Too many links, similar to `EMLINK` in POSIX. #define FILESYSTEM_ERROR_CODE_TOO_MANY_LINKS 16 +// Message too large, similar to `EMSGSIZE` in POSIX. #define FILESYSTEM_ERROR_CODE_MESSAGE_SIZE 17 +// Filename too long, similar to `ENAMETOOLONG` in POSIX. #define FILESYSTEM_ERROR_CODE_NAME_TOO_LONG 18 +// No such device, similar to `ENODEV` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_DEVICE 19 +// No such file or directory, similar to `ENOENT` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_ENTRY 20 +// No locks available, similar to `ENOLCK` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_LOCK 21 +// Not enough space, similar to `ENOMEM` in POSIX. #define FILESYSTEM_ERROR_CODE_INSUFFICIENT_MEMORY 22 +// No space left on device, similar to `ENOSPC` in POSIX. #define FILESYSTEM_ERROR_CODE_INSUFFICIENT_SPACE 23 +// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_DIRECTORY 24 +// Directory not empty, similar to `ENOTEMPTY` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_EMPTY 25 +// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_RECOVERABLE 26 +// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. #define FILESYSTEM_ERROR_CODE_UNSUPPORTED 27 +// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_TTY 28 +// No such device or address, similar to `ENXIO` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_SUCH_DEVICE 29 +// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. #define FILESYSTEM_ERROR_CODE_OVERFLOW 30 +// Operation not permitted, similar to `EPERM` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_PERMITTED 31 +// Broken pipe, similar to `EPIPE` in POSIX. #define FILESYSTEM_ERROR_CODE_PIPE 32 +// Read-only file system, similar to `EROFS` in POSIX. #define FILESYSTEM_ERROR_CODE_READ_ONLY 33 +// Invalid seek, similar to `ESPIPE` in POSIX. #define FILESYSTEM_ERROR_CODE_INVALID_SEEK 34 +// Text file busy, similar to `ETXTBSY` in POSIX. #define FILESYSTEM_ERROR_CODE_TEXT_FILE_BUSY 35 +// Cross-device link, similar to `EXDEV` in POSIX. #define FILESYSTEM_ERROR_CODE_CROSS_DEVICE 36 +// File or memory access pattern advisory information. typedef uint8_t filesystem_advice_t; +// The application has no advice to give on its behavior with respect +// to the specified data. #define FILESYSTEM_ADVICE_NORMAL 0 +// The application expects to access the specified data sequentially +// from lower offsets to higher offsets. #define FILESYSTEM_ADVICE_SEQUENTIAL 1 +// The application expects to access the specified data in a random +// order. #define FILESYSTEM_ADVICE_RANDOM 2 +// The application expects to access the specified data in the near +// future. #define FILESYSTEM_ADVICE_WILL_NEED 3 +// The application expects that it will not access the specified data +// in the near future. #define FILESYSTEM_ADVICE_DONT_NEED 4 +// The application expects to access the specified data once and then +// not reuse it thereafter. #define FILESYSTEM_ADVICE_NO_REUSE 5 +// A 128-bit hash value, split into parts because wasm doesn't have a +// 128-bit integer type. typedef struct filesystem_metadata_hash_value_t { + // 64 bits of a 128-bit hash value. uint64_t lower; + // Another 64 bits of a 128-bit hash value. uint64_t upper; } filesystem_metadata_hash_value_t; @@ -457,33 +610,85 @@ typedef struct network_borrow_network_t { int32_t __handle; } network_borrow_network_t; +// Error codes. +// +// In theory, every API can return any error code. +// In practice, API's typically only return the errors documented per API +// combined with a couple of errors that are always possible: +// - `unknown` +// - `access-denied` +// - `not-supported` +// - `out-of-memory` +// - `concurrency-conflict` +// +// See each individual API for what the POSIX equivalents are. They sometimes differ per API. typedef uint8_t network_error_code_t; +// Unknown error #define NETWORK_ERROR_CODE_UNKNOWN 0 +// Access denied. +// +// POSIX equivalent: EACCES, EPERM #define NETWORK_ERROR_CODE_ACCESS_DENIED 1 +// The operation is not supported. +// +// POSIX equivalent: EOPNOTSUPP #define NETWORK_ERROR_CODE_NOT_SUPPORTED 2 +// One of the arguments is invalid. +// +// POSIX equivalent: EINVAL #define NETWORK_ERROR_CODE_INVALID_ARGUMENT 3 +// Not enough memory to complete the operation. +// +// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY #define NETWORK_ERROR_CODE_OUT_OF_MEMORY 4 +// The operation timed out before it could finish completely. #define NETWORK_ERROR_CODE_TIMEOUT 5 +// This operation is incompatible with another asynchronous operation that is already in progress. +// +// POSIX equivalent: EALREADY #define NETWORK_ERROR_CODE_CONCURRENCY_CONFLICT 6 +// Trying to finish an asynchronous operation that: +// - has not been started yet, or: +// - was already finished by a previous `finish-*` call. +// +// Note: this is scheduled to be removed when `future`s are natively supported. #define NETWORK_ERROR_CODE_NOT_IN_PROGRESS 7 +// The operation has been aborted because it could not be completed immediately. +// +// Note: this is scheduled to be removed when `future`s are natively supported. #define NETWORK_ERROR_CODE_WOULD_BLOCK 8 +// The operation is not valid in the socket's current state. #define NETWORK_ERROR_CODE_INVALID_STATE 9 +// A new socket resource could not be created because of a system limit. #define NETWORK_ERROR_CODE_NEW_SOCKET_LIMIT 10 +// A bind operation failed because the provided address is not an address that the `network` can bind to. #define NETWORK_ERROR_CODE_ADDRESS_NOT_BINDABLE 11 +// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. #define NETWORK_ERROR_CODE_ADDRESS_IN_USE 12 +// The remote address is not reachable #define NETWORK_ERROR_CODE_REMOTE_UNREACHABLE 13 +// The TCP connection was forcefully rejected #define NETWORK_ERROR_CODE_CONNECTION_REFUSED 14 +// The TCP connection was reset. #define NETWORK_ERROR_CODE_CONNECTION_RESET 15 +// A TCP connection was aborted. #define NETWORK_ERROR_CODE_CONNECTION_ABORTED 16 +// The size of a datagram sent to a UDP socket exceeded the maximum +// supported size. #define NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE 17 +// Name does not exist or has no suitable associated IP addresses. #define NETWORK_ERROR_CODE_NAME_UNRESOLVABLE 18 +// A temporary failure in name resolution occurred. #define NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE 19 +// A permanent failure in name resolution occurred. #define NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE 20 typedef uint8_t network_ip_address_family_t; +// Similar to `AF_INET` in POSIX. #define NETWORK_IP_ADDRESS_FAMILY_IPV4 0 +// Similar to `AF_INET6` in POSIX. #define NETWORK_IP_ADDRESS_FAMILY_IPV6 1 typedef struct network_ipv4_address_t { @@ -516,14 +721,20 @@ typedef struct network_ip_address_t { #define NETWORK_IP_ADDRESS_IPV6 1 typedef struct network_ipv4_socket_address_t { + // sin_port uint16_t port; + // sin_addr network_ipv4_address_t address; } network_ipv4_socket_address_t; typedef struct network_ipv6_socket_address_t { + // sin6_port uint16_t port; + // sin6_flowinfo uint32_t flow_info; + // sin6_addr network_ipv6_address_t address; + // sin6_scope_id uint32_t scope_id; } network_ipv6_socket_address_t; @@ -546,8 +757,17 @@ typedef network_ip_socket_address_t udp_ip_socket_address_t; typedef network_ip_address_family_t udp_ip_address_family_t; +// A received datagram. typedef struct udp_incoming_datagram_t { + // The payload. + // + // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. wasip2_list_u8_t data; + // The source address. + // + // This field is guaranteed to match the remote address the stream was initialized with, if any. + // + // Equivalent to the `src_addr` out parameter of `recvfrom`. udp_ip_socket_address_t remote_address; } udp_incoming_datagram_t; @@ -556,8 +776,17 @@ typedef struct { udp_ip_socket_address_t val; } udp_option_ip_socket_address_t; +// A datagram to be sent out. typedef struct udp_outgoing_datagram_t { + // The payload. wasip2_list_u8_t data; + // The destination address. + // + // The requirements on this field depend on how the stream was initialized: + // - with a remote address: this field must be None or match the stream's remote address exactly. + // - without a remote address: this field is required. + // + // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`. udp_option_ip_socket_address_t remote_address; } udp_outgoing_datagram_t; @@ -675,8 +904,11 @@ typedef network_ip_address_family_t tcp_ip_address_family_t; typedef uint8_t tcp_shutdown_type_t; +// Similar to `SHUT_RD` in POSIX. #define TCP_SHUTDOWN_TYPE_RECEIVE 0 +// Similar to `SHUT_WR` in POSIX. #define TCP_SHUTDOWN_TYPE_SEND 1 +// Similar to `SHUT_RDWR` in POSIX. #define TCP_SHUTDOWN_TYPE_BOTH 2 typedef struct tcp_own_tcp_socket_t { @@ -854,28 +1086,217 @@ extern bool environment_initial_cwd(wasip2_string_t *ret); _Noreturn extern void exit_exit(exit_result_void_void_t *status); // Imported Functions from `wasi:io/error@0.2.0` +// Returns a string that is suitable to assist humans in debugging +// this error. +// +// WARNING: The returned string should not be consumed mechanically! +// It may change across platforms, hosts, or other implementation +// details. Parsing this string is a major platform-compatibility +// hazard. extern void io_error_method_error_to_debug_string(io_error_borrow_error_t self, wasip2_string_t *ret); // Imported Functions from `wasi:io/poll@0.2.0` +// Return the readiness of a pollable. This function never blocks. +// +// Returns `true` when the pollable is ready, and `false` otherwise. extern bool poll_method_pollable_ready(poll_borrow_pollable_t self); +// `block` returns immediately if the pollable is ready, and otherwise +// blocks until ready. +// +// This function is equivalent to calling `poll.poll` on a list +// containing only this pollable. extern void poll_method_pollable_block(poll_borrow_pollable_t self); +// Poll for completion on a set of pollables. +// +// This function takes a list of pollables, which identify I/O sources of +// interest, and waits until one or more of the events is ready for I/O. +// +// The result `list` contains one or more indices of handles in the +// argument list that is ready for I/O. +// +// If the list contains more elements than can be indexed with a `u32` +// value, this function traps. +// +// A timeout can be implemented by adding a pollable from the +// wasi-clocks API to the list. +// +// This function does not return a `result`; polling in itself does not +// do any I/O so it doesn't fail. If any of the I/O sources identified by +// the pollables has an error, it is indicated by marking the source as +// being reaedy for I/O. extern void poll_poll(poll_list_borrow_pollable_t *in, wasip2_list_u32_t *ret); // Imported Functions from `wasi:io/streams@0.2.0` +// Perform a non-blocking read from the stream. +// +// When the source of a `read` is binary data, the bytes from the source +// are returned verbatim. When the source of a `read` is known to the +// implementation to be text, bytes containing the UTF-8 encoding of the +// text are returned. +// +// This function returns a list of bytes containing the read data, +// when successful. The returned list will contain up to `len` bytes; +// it may return fewer than requested, but not more. The list is +// empty when no bytes are available for reading at this time. The +// pollable given by `subscribe` will be ready when more bytes are +// available. +// +// This function fails with a `stream-error` when the operation +// encounters an error, giving `last-operation-failed`, or when the +// stream is closed, giving `closed`. +// +// When the caller gives a `len` of 0, it represents a request to +// read 0 bytes. If the stream is still open, this call should +// succeed and return an empty list, or otherwise fail with `closed`. +// +// The `len` parameter is a `u64`, which could represent a list of u8 which +// is not possible to allocate in wasm32, or not desirable to allocate as +// as a return value by the callee. The callee may return a list of bytes +// less than `len` in size while more bytes are available for reading. extern bool streams_method_input_stream_read(streams_borrow_input_stream_t self, uint64_t len, wasip2_list_u8_t *ret, streams_stream_error_t *err); +// Read bytes from a stream, after blocking until at least one byte can +// be read. Except for blocking, behavior is identical to `read`. extern bool streams_method_input_stream_blocking_read(streams_borrow_input_stream_t self, uint64_t len, wasip2_list_u8_t *ret, streams_stream_error_t *err); +// Skip bytes from a stream. Returns number of bytes skipped. +// +// Behaves identical to `read`, except instead of returning a list +// of bytes, returns the number of bytes consumed from the stream. extern bool streams_method_input_stream_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err); +// Skip bytes from a stream, after blocking until at least one byte +// can be skipped. Except for blocking behavior, identical to `skip`. extern bool streams_method_input_stream_blocking_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err); +// Create a `pollable` which will resolve once either the specified stream +// has bytes available to read or the other end of the stream has been +// closed. +// The created `pollable` is a child resource of the `input-stream`. +// Implementations may trap if the `input-stream` is dropped before +// all derived `pollable`s created with this function are dropped. extern streams_own_pollable_t streams_method_input_stream_subscribe(streams_borrow_input_stream_t self); +// Check readiness for writing. This function never blocks. +// +// Returns the number of bytes permitted for the next call to `write`, +// or an error. Calling `write` with more bytes than this function has +// permitted will trap. +// +// When this function returns 0 bytes, the `subscribe` pollable will +// become ready when this function will report at least 1 byte, or an +// error. extern bool streams_method_output_stream_check_write(streams_borrow_output_stream_t self, uint64_t *ret, streams_stream_error_t *err); +// Perform a write. This function never blocks. +// +// When the destination of a `write` is binary data, the bytes from +// `contents` are written verbatim. When the destination of a `write` is +// known to the implementation to be text, the bytes of `contents` are +// transcoded from UTF-8 into the encoding of the destination and then +// written. +// +// Precondition: check-write gave permit of Ok(n) and contents has a +// length of less than or equal to n. Otherwise, this function will trap. +// +// returns Err(closed) without writing if the stream has closed since +// the last call to check-write provided a permit. extern bool streams_method_output_stream_write(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err); +// Perform a write of up to 4096 bytes, and then flush the stream. Block +// until all of these operations are complete, or an error occurs. +// +// This is a convenience wrapper around the use of `check-write`, +// `subscribe`, `write`, and `flush`, and is implemented with the +// following pseudo-code: +// +// ```text +// let pollable = this.subscribe(); +// while !contents.is_empty() { +// // Wait for the stream to become writable +// pollable.block(); +// let Ok(n) = this.check-write(); // eliding error handling +// let len = min(n, contents.len()); +// let (chunk, rest) = contents.split_at(len); +// this.write(chunk ); // eliding error handling +// contents = rest; +// } +// this.flush(); +// // Wait for completion of `flush` +// pollable.block(); +// // Check for any errors that arose during `flush` +// let _ = this.check-write(); // eliding error handling +// ``` extern bool streams_method_output_stream_blocking_write_and_flush(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err); +// Request to flush buffered output. This function never blocks. +// +// This tells the output-stream that the caller intends any buffered +// output to be flushed. the output which is expected to be flushed +// is all that has been passed to `write` prior to this call. +// +// Upon calling this function, the `output-stream` will not accept any +// writes (`check-write` will return `ok(0)`) until the flush has +// completed. The `subscribe` pollable will become ready when the +// flush has completed and the stream can accept more writes. extern bool streams_method_output_stream_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err); +// Request to flush buffered output, and block until flush completes +// and stream is ready for writing again. extern bool streams_method_output_stream_blocking_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err); +// Create a `pollable` which will resolve once the output-stream +// is ready for more writing, or an error has occured. When this +// pollable is ready, `check-write` will return `ok(n)` with n>0, or an +// error. +// +// If the stream is closed, this pollable is always ready immediately. +// +// The created `pollable` is a child resource of the `output-stream`. +// Implementations may trap if the `output-stream` is dropped before +// all derived `pollable`s created with this function are dropped. extern streams_own_pollable_t streams_method_output_stream_subscribe(streams_borrow_output_stream_t self); +// Write zeroes to a stream. +// +// This should be used precisely like `write` with the exact same +// preconditions (must use check-write first), but instead of +// passing a list of bytes, you simply pass the number of zero-bytes +// that should be written. extern bool streams_method_output_stream_write_zeroes(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err); +// Perform a write of up to 4096 zeroes, and then flush the stream. +// Block until all of these operations are complete, or an error +// occurs. +// +// This is a convenience wrapper around the use of `check-write`, +// `subscribe`, `write-zeroes`, and `flush`, and is implemented with +// the following pseudo-code: +// +// ```text +// let pollable = this.subscribe(); +// while num_zeroes != 0 { +// // Wait for the stream to become writable +// pollable.block(); +// let Ok(n) = this.check-write(); // eliding error handling +// let len = min(n, num_zeroes); +// this.write-zeroes(len); // eliding error handling +// num_zeroes -= len; +// } +// this.flush(); +// // Wait for completion of `flush` +// pollable.block(); +// // Check for any errors that arose during `flush` +// let _ = this.check-write(); // eliding error handling +// ``` extern bool streams_method_output_stream_blocking_write_zeroes_and_flush(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err); +// Read from one stream and write to another. +// +// The behavior of splice is equivelant to: +// 1. calling `check-write` on the `output-stream` +// 2. calling `read` on the `input-stream` with the smaller of the +// `check-write` permitted length and the `len` provided to `splice` +// 3. calling `write` on the `output-stream` with that read data. +// +// Any error reported by the call to `check-write`, `read`, or +// `write` ends the splice and reports that error. +// +// This function returns the number of bytes transferred; it may be less +// than `len`. extern bool streams_method_output_stream_splice(streams_borrow_output_stream_t self, streams_borrow_input_stream_t src, uint64_t len, uint64_t *ret, streams_stream_error_t *err); +// Read from one stream and write to another, with blocking. +// +// This is similar to `splice`, except that it blocks until the +// `output-stream` is ready for writing, and the `input-stream` +// is ready for reading, before performing the `splice`. extern bool streams_method_output_stream_blocking_splice(streams_borrow_output_stream_t self, streams_borrow_input_stream_t src, uint64_t len, uint64_t *ret, streams_stream_error_t *err); // Imported Functions from `wasi:cli/stdin@0.2.0` @@ -903,122 +1324,930 @@ extern bool terminal_stdout_get_terminal_stdout(terminal_stdout_own_terminal_out extern bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t *ret); // Imported Functions from `wasi:clocks/monotonic-clock@0.2.0` +// Read the current value of the clock. +// +// The clock is monotonic, therefore calling this function repeatedly will +// produce a sequence of non-decreasing values. extern monotonic_clock_instant_t monotonic_clock_now(void); +// Query the resolution of the clock. Returns the duration of time +// corresponding to a clock tick. extern monotonic_clock_duration_t monotonic_clock_resolution(void); +// Create a `pollable` which will resolve once the specified instant +// occured. extern monotonic_clock_own_pollable_t monotonic_clock_subscribe_instant(monotonic_clock_instant_t when); +// Create a `pollable` which will resolve once the given duration has +// elapsed, starting at the time at which this function was called. +// occured. extern monotonic_clock_own_pollable_t monotonic_clock_subscribe_duration(monotonic_clock_duration_t when); // Imported Functions from `wasi:clocks/wall-clock@0.2.0` +// Read the current value of the clock. +// +// This clock is not monotonic, therefore calling this function repeatedly +// will not necessarily produce a sequence of non-decreasing values. +// +// The returned timestamps represent the number of seconds since +// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], +// also known as [Unix Time]. +// +// The nanoseconds field of the output is always less than 1000000000. +// +// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 +// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time extern void wall_clock_now(wall_clock_datetime_t *ret); +// Query the resolution of the clock. +// +// The nanoseconds field of the output is always less than 1000000000. extern void wall_clock_resolution(wall_clock_datetime_t *ret); // Imported Functions from `wasi:filesystem/types@0.2.0` +// Return a stream for reading from a file, if available. +// +// May fail with an error-code describing why the file cannot be read. +// +// Multiple read, write, and append streams may be active on the same open +// file and they do not interfere with each other. +// +// Note: This allows using `read-stream`, which is similar to `read` in POSIX. extern bool filesystem_method_descriptor_read_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_own_input_stream_t *ret, filesystem_error_code_t *err); +// Return a stream for writing to a file, if available. +// +// May fail with an error-code describing why the file cannot be written. +// +// Note: This allows using `write-stream`, which is similar to `write` in +// POSIX. extern bool filesystem_method_descriptor_write_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_own_output_stream_t *ret, filesystem_error_code_t *err); +// Return a stream for appending to a file, if available. +// +// May fail with an error-code describing why the file cannot be appended. +// +// Note: This allows using `write-stream`, which is similar to `write` with +// `O_APPEND` in in POSIX. extern bool filesystem_method_descriptor_append_via_stream(filesystem_borrow_descriptor_t self, filesystem_own_output_stream_t *ret, filesystem_error_code_t *err); +// Provide file advisory information on a descriptor. +// +// This is similar to `posix_fadvise` in POSIX. extern bool filesystem_method_descriptor_advise(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_filesize_t length, filesystem_advice_t advice, filesystem_error_code_t *err); +// Synchronize the data of a file to disk. +// +// This function succeeds with no effect if the file descriptor is not +// opened for writing. +// +// Note: This is similar to `fdatasync` in POSIX. extern bool filesystem_method_descriptor_sync_data(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err); +// Get flags associated with a descriptor. +// +// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. +// +// Note: This returns the value that was the `fs_flags` value returned +// from `fdstat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_get_flags(filesystem_borrow_descriptor_t self, filesystem_descriptor_flags_t *ret, filesystem_error_code_t *err); +// Get the dynamic type of a descriptor. +// +// Note: This returns the same value as the `type` field of the `fd-stat` +// returned by `stat`, `stat-at` and similar. +// +// Note: This returns similar flags to the `st_mode & S_IFMT` value provided +// by `fstat` in POSIX. +// +// Note: This returns the value that was the `fs_filetype` value returned +// from `fdstat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_get_type(filesystem_borrow_descriptor_t self, filesystem_descriptor_type_t *ret, filesystem_error_code_t *err); +// Adjust the size of an open file. If this increases the file's size, the +// extra bytes are filled with zeros. +// +// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. extern bool filesystem_method_descriptor_set_size(filesystem_borrow_descriptor_t self, filesystem_filesize_t size, filesystem_error_code_t *err); +// Adjust the timestamps of an open file or directory. +// +// Note: This is similar to `futimens` in POSIX. +// +// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. extern bool filesystem_method_descriptor_set_times(filesystem_borrow_descriptor_t self, filesystem_new_timestamp_t *data_access_timestamp, filesystem_new_timestamp_t *data_modification_timestamp, filesystem_error_code_t *err); +// Read from a descriptor, without using and updating the descriptor's offset. +// +// This function returns a list of bytes containing the data that was +// read, along with a bool which, when true, indicates that the end of the +// file was reached. The returned list will contain up to `length` bytes; it +// may return fewer than requested, if the end of the file is reached or +// if the I/O operation is interrupted. +// +// In the future, this may change to return a `stream`. +// +// Note: This is similar to `pread` in POSIX. extern bool filesystem_method_descriptor_read(filesystem_borrow_descriptor_t self, filesystem_filesize_t length, filesystem_filesize_t offset, wasip2_tuple2_list_u8_bool_t *ret, filesystem_error_code_t *err); +// Write to a descriptor, without using and updating the descriptor's offset. +// +// It is valid to write past the end of a file; the file is extended to the +// extent of the write, with bytes between the previous end and the start of +// the write set to zero. +// +// In the future, this may change to take a `stream`. +// +// Note: This is similar to `pwrite` in POSIX. extern bool filesystem_method_descriptor_write(filesystem_borrow_descriptor_t self, wasip2_list_u8_t *buffer, filesystem_filesize_t offset, filesystem_filesize_t *ret, filesystem_error_code_t *err); +// Read directory entries from a directory. +// +// On filesystems where directories contain entries referring to themselves +// and their parents, often named `.` and `..` respectively, these entries +// are omitted. +// +// This always returns a new stream which starts at the beginning of the +// directory. Multiple streams may be active on the same directory, and they +// do not interfere with each other. extern bool filesystem_method_descriptor_read_directory(filesystem_borrow_descriptor_t self, filesystem_own_directory_entry_stream_t *ret, filesystem_error_code_t *err); +// Synchronize the data and metadata of a file to disk. +// +// This function succeeds with no effect if the file descriptor is not +// opened for writing. +// +// Note: This is similar to `fsync` in POSIX. extern bool filesystem_method_descriptor_sync(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err); +// Create a directory. +// +// Note: This is similar to `mkdirat` in POSIX. extern bool filesystem_method_descriptor_create_directory_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); +// Return the attributes of an open file or directory. +// +// Note: This is similar to `fstat` in POSIX, except that it does not return +// device and inode information. For testing whether two descriptors refer to +// the same underlying filesystem object, use `is-same-object`. To obtain +// additional data that can be used do determine whether a file has been +// modified, use `metadata-hash`. +// +// Note: This was called `fd_filestat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_stat(filesystem_borrow_descriptor_t self, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err); +// Return the attributes of a file or directory. +// +// Note: This is similar to `fstatat` in POSIX, except that it does not +// return device and inode information. See the `stat` description for a +// discussion of alternatives. +// +// Note: This was called `path_filestat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_stat_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err); +// Adjust the timestamps of a file or directory. +// +// Note: This is similar to `utimensat` in POSIX. +// +// Note: This was called `path_filestat_set_times` in earlier versions of +// WASI. extern bool filesystem_method_descriptor_set_times_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_new_timestamp_t *data_access_timestamp, filesystem_new_timestamp_t *data_modification_timestamp, filesystem_error_code_t *err); +// Create a hard link. +// +// Note: This is similar to `linkat` in POSIX. extern bool filesystem_method_descriptor_link_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t old_path_flags, wasip2_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, wasip2_string_t *new_path, filesystem_error_code_t *err); +// Open a file or directory. +// +// The returned descriptor is not guaranteed to be the lowest-numbered +// 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 descriptor is +// guaranteed to be less than 2**31. +// +// If `flags` contains `descriptor-flags::mutate-directory`, and the base +// descriptor doesn't have `descriptor-flags::mutate-directory` set, +// `open-at` fails with `error-code::read-only`. +// +// If `flags` contains `write` or `mutate-directory`, or `open-flags` +// contains `truncate` or `create`, and the base descriptor doesn't have +// `descriptor-flags::mutate-directory` set, `open-at` fails with +// `error-code::read-only`. +// +// Note: This is similar to `openat` in POSIX. extern bool filesystem_method_descriptor_open_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_open_flags_t open_flags, filesystem_descriptor_flags_t flags, filesystem_own_descriptor_t *ret, filesystem_error_code_t *err); +// Read the contents of a symbolic link. +// +// If the contents contain an absolute or rooted path in the underlying +// filesystem, this function fails with `error-code::not-permitted`. +// +// Note: This is similar to `readlinkat` in POSIX. extern bool filesystem_method_descriptor_readlink_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, wasip2_string_t *ret, filesystem_error_code_t *err); +// Remove a directory. +// +// Return `error-code::not-empty` if the directory is not empty. +// +// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. extern bool filesystem_method_descriptor_remove_directory_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); +// Rename a filesystem object. +// +// Note: This is similar to `renameat` in POSIX. extern bool filesystem_method_descriptor_rename_at(filesystem_borrow_descriptor_t self, wasip2_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, wasip2_string_t *new_path, filesystem_error_code_t *err); +// Create a symbolic link (also known as a "symlink"). +// +// If `old-path` starts with `/`, the function fails with +// `error-code::not-permitted`. +// +// Note: This is similar to `symlinkat` in POSIX. extern bool filesystem_method_descriptor_symlink_at(filesystem_borrow_descriptor_t self, wasip2_string_t *old_path, wasip2_string_t *new_path, filesystem_error_code_t *err); +// Unlink a filesystem object that is not a directory. +// +// Return `error-code::is-directory` if the path refers to a directory. +// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. extern bool filesystem_method_descriptor_unlink_file_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); +// Test whether two descriptors refer to the same filesystem object. +// +// In POSIX, this corresponds to testing whether the two descriptors have the +// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. +// wasi-filesystem does not expose device and inode numbers, so this function +// may be used instead. extern bool filesystem_method_descriptor_is_same_object(filesystem_borrow_descriptor_t self, filesystem_borrow_descriptor_t other); +// Return a hash of the metadata associated with a filesystem object referred +// to by a descriptor. +// +// This returns a hash of the last-modification timestamp and file size, and +// may also include the inode number, device number, birth timestamp, and +// other metadata fields that may change when the file is modified or +// replaced. It may also include a secret value chosen by the +// implementation and not otherwise exposed. +// +// Implementations are encourated to provide the following properties: +// +// - If the file is not modified or replaced, the computed hash value should +// usually not change. +// - If the object is modified or replaced, the computed hash value should +// usually change. +// - The inputs to the hash should not be easily computable from the +// computed hash. +// +// However, none of these is required. extern bool filesystem_method_descriptor_metadata_hash(filesystem_borrow_descriptor_t self, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err); +// Return a hash of the metadata associated with a filesystem object referred +// to by a directory descriptor and a relative path. +// +// This performs the same hash computation as `metadata-hash`. extern bool filesystem_method_descriptor_metadata_hash_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err); +// Read a single directory entry from a `directory-entry-stream`. extern bool filesystem_method_directory_entry_stream_read_directory_entry(filesystem_borrow_directory_entry_stream_t self, filesystem_option_directory_entry_t *ret, filesystem_error_code_t *err); +// Attempts to extract a filesystem-related `error-code` from the stream +// `error` provided. +// +// Stream operations which return `stream-error::last-operation-failed` +// have a payload with more information about the operation that failed. +// This payload can be passed through to this function to see if there's +// filesystem-related information about the error to return. +// +// Note that this function is fallible because not all stream-related +// errors are filesystem-related errors. extern bool filesystem_filesystem_error_code(filesystem_borrow_error_t err_, filesystem_error_code_t *ret); // Imported Functions from `wasi:filesystem/preopens@0.2.0` +// Return the set of preopened directories, and their path. extern void filesystem_preopens_get_directories(filesystem_preopens_list_tuple2_own_descriptor_string_t *ret); // Imported Functions from `wasi:sockets/instance-network@0.2.0` +// Get a handle to the default network. extern instance_network_own_network_t instance_network_instance_network(void); // Imported Functions from `wasi:sockets/udp@0.2.0` +// Bind the socket to a specific network on the provided IP address and port. +// +// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which +// network interface(s) to bind to. +// If the port is zero, the socket will be bound to a random free port. +// +// # Typical errors +// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) +// - `invalid-state`: The socket is already bound. (EINVAL) +// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) +// - `address-in-use`: Address is already in use. (EADDRINUSE) +// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) +// - `not-in-progress`: A `bind` operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// Unlike in POSIX, in WASI the bind operation is async. This enables +// interactive WASI hosts to inject permission prompts. Runtimes that +// don't want to make use of this ability can simply call the native +// `bind` as part of either `start-bind` or `finish-bind`. +// +// # References +// - +// - +// - +// - extern bool udp_method_udp_socket_start_bind(udp_borrow_udp_socket_t self, udp_borrow_network_t network, udp_ip_socket_address_t *local_address, udp_error_code_t *err); extern bool udp_method_udp_socket_finish_bind(udp_borrow_udp_socket_t self, udp_error_code_t *err); +// Set up inbound & outbound communication channels, optionally to a specific peer. +// +// This function only changes the local socket configuration and does not generate any network traffic. +// On success, the `remote-address` of the socket is updated. The `local-address` may be updated as well, +// based on the best network path to `remote-address`. +// +// When a `remote-address` is provided, the returned streams are limited to communicating with that specific peer: +// - `send` can only be used to send to this destination. +// - `receive` will only return datagrams sent from the provided `remote-address`. +// +// This method may be called multiple times on the same socket to change its association, but +// only the most recently returned pair of streams will be operational. Implementations may trap if +// the streams returned by a previous invocation haven't been dropped yet before calling `stream` again. +// +// The POSIX equivalent in pseudo-code is: +// ```text +// if (was previously connected) { +// connect(s, AF_UNSPEC) +// } +// if (remote_address is Some) { +// connect(s, remote_address) +// } +// ``` +// +// Unlike in POSIX, the socket must already be explicitly bound. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-state`: The socket is not bound. +// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// +// # References +// - +// - +// - +// - extern bool udp_method_udp_socket_stream(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *maybe_remote_address, udp_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_t *ret, udp_error_code_t *err); +// Get the current bound address. +// +// POSIX mentions: +// > If the socket has not been bound to a local name, the value +// > stored in the object pointed to by `address` is unspecified. +// +// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. +// +// # References +// - +// - +// - +// - extern bool udp_method_udp_socket_local_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err); +// Get the address the socket is currently streaming to. +// +// # Typical errors +// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) +// +// # References +// - +// - +// - +// - extern bool udp_method_udp_socket_remote_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err); +// Whether this is a IPv4 or IPv6 socket. +// +// Equivalent to the SO_DOMAIN socket option. extern udp_ip_address_family_t udp_method_udp_socket_address_family(udp_borrow_udp_socket_t self); +// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// +// # Typical errors +// - `invalid-argument`: (set) The TTL value must be 1 or higher. extern bool udp_method_udp_socket_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t *ret, udp_error_code_t *err); extern bool udp_method_udp_socket_set_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t value, udp_error_code_t *err); +// The kernel buffer space reserved for sends/receives on this socket. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. extern bool udp_method_udp_socket_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err); extern bool udp_method_udp_socket_set_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err); extern bool udp_method_udp_socket_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err); extern bool udp_method_udp_socket_set_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err); +// Create a `pollable` which will resolve once the socket is ready for I/O. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. extern udp_own_pollable_t udp_method_udp_socket_subscribe(udp_borrow_udp_socket_t self); +// Receive messages on the socket. +// +// This function attempts to receive up to `max-results` datagrams on the socket without blocking. +// The returned list may contain fewer elements than requested, but never more. +// +// This function returns successfully with an empty list when either: +// - `max-results` is 0, or: +// - `max-results` is greater than 0, but no results are immediately available. +// This function never returns `error(would-block)`. +// +// # Typical errors +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// +// # References +// - +// - +// - +// - +// - +// - +// - +// - extern bool udp_method_incoming_datagram_stream_receive(udp_borrow_incoming_datagram_stream_t self, uint64_t max_results, udp_list_incoming_datagram_t *ret, udp_error_code_t *err); +// Create a `pollable` which will resolve once the stream is ready to receive again. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. extern udp_own_pollable_t udp_method_incoming_datagram_stream_subscribe(udp_borrow_incoming_datagram_stream_t self); +// Check readiness for sending. This function never blocks. +// +// Returns the number of datagrams permitted for the next call to `send`, +// or an error. Calling `send` with more datagrams than this function has +// permitted will trap. +// +// When this function returns ok(0), the `subscribe` pollable will +// become ready when this function will report at least ok(1), or an +// error. +// +// Never returns `would-block`. extern bool udp_method_outgoing_datagram_stream_check_send(udp_borrow_outgoing_datagram_stream_t self, uint64_t *ret, udp_error_code_t *err); +// Send messages on the socket. +// +// This function attempts to send all provided `datagrams` on the socket without blocking and +// returns how many messages were actually sent (or queued for sending). This function never +// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned. +// +// This function semantically behaves the same as iterating the `datagrams` list and sequentially +// sending each individual datagram until either the end of the list has been reached or the first error occurred. +// If at least one datagram has been sent successfully, this function never returns an error. +// +// If the input list is empty, the function returns `ok(0)`. +// +// Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if +// either `check-send` was not called or `datagrams` contains more items than `check-send` permitted. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN) +// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ) +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) +// +// # References +// - +// - +// - +// - +// - +// - +// - +// - extern bool udp_method_outgoing_datagram_stream_send(udp_borrow_outgoing_datagram_stream_t self, udp_list_outgoing_datagram_t *datagrams, uint64_t *ret, udp_error_code_t *err); +// Create a `pollable` which will resolve once the stream is ready to send again. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. extern udp_own_pollable_t udp_method_outgoing_datagram_stream_subscribe(udp_borrow_outgoing_datagram_stream_t self); // Imported Functions from `wasi:sockets/udp-create-socket@0.2.0` +// Create a new UDP socket. +// +// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX. +// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. +// +// This function does not require a network capability handle. This is considered to be safe because +// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind` is called, +// the socket is effectively an in-memory configuration object, unable to communicate with the outside world. +// +// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. +// +// # Typical errors +// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) +// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) +// +// # References: +// - +// - +// - +// - extern bool udp_create_socket_create_udp_socket(udp_create_socket_ip_address_family_t address_family, udp_create_socket_own_udp_socket_t *ret, udp_create_socket_error_code_t *err); // Imported Functions from `wasi:sockets/tcp@0.2.0` +// Bind the socket to a specific network on the provided IP address and port. +// +// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which +// network interface(s) to bind to. +// If the TCP/UDP port is zero, the socket will be bound to a random free port. +// +// Bind can be attempted multiple times on the same socket, even with +// different arguments on each iteration. But never concurrently and +// only as long as the previous bind failed. Once a bind succeeds, the +// binding can't be changed anymore. +// +// # Typical errors +// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) +// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) +// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL) +// - `invalid-state`: The socket is already bound. (EINVAL) +// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) +// - `address-in-use`: Address is already in use. (EADDRINUSE) +// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) +// - `not-in-progress`: A `bind` operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT +// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR +// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior +// and SO_REUSEADDR performs something different entirely. +// +// Unlike in POSIX, in WASI the bind operation is async. This enables +// interactive WASI hosts to inject permission prompts. Runtimes that +// don't want to make use of this ability can simply call the native +// `bind` as part of either `start-bind` or `finish-bind`. +// +// # References +// - +// - +// - +// - extern bool tcp_method_tcp_socket_start_bind(tcp_borrow_tcp_socket_t self, tcp_borrow_network_t network, tcp_ip_socket_address_t *local_address, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_finish_bind(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); +// Connect to a remote endpoint. +// +// On success: +// - the socket is transitioned into the `connection` state. +// - a pair of streams is returned that can be used to read & write to the connection +// +// After a failed connection attempt, the socket will be in the `closed` +// state and the only valid action left is to `drop` the socket. A single +// socket can not be used to connect more than once. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) +// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) +// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows) +// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. +// - `invalid-state`: The socket is already in the `connected` state. (EISCONN) +// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows) +// - `timeout`: Connection timed out. (ETIMEDOUT) +// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) +// - `connection-reset`: The connection was reset. (ECONNRESET) +// - `connection-aborted`: The connection was aborted. (ECONNABORTED) +// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) +// - `not-in-progress`: A connect operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// The POSIX equivalent of `start-connect` is the regular `connect` syscall. +// Because all WASI sockets are non-blocking this is expected to return +// EINPROGRESS, which should be translated to `ok()` in WASI. +// +// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` +// with a timeout of 0 on the socket descriptor. Followed by a check for +// the `SO_ERROR` socket option, in case the poll signaled readiness. +// +// # References +// - +// - +// - +// - extern bool tcp_method_tcp_socket_start_connect(tcp_borrow_tcp_socket_t self, tcp_borrow_network_t network, tcp_ip_socket_address_t *remote_address, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_finish_connect(tcp_borrow_tcp_socket_t self, tcp_tuple2_own_input_stream_own_output_stream_t *ret, tcp_error_code_t *err); +// Start listening for new connections. +// +// Transitions the socket into the `listening` state. +// +// Unlike POSIX, the socket must already be explicitly bound. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) +// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD) +// - `invalid-state`: The socket is already in the `listening` state. +// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE) +// - `not-in-progress`: A listen operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// Unlike in POSIX, in WASI the listen operation is async. This enables +// interactive WASI hosts to inject permission prompts. Runtimes that +// don't want to make use of this ability can simply call the native +// `listen` as part of either `start-listen` or `finish-listen`. +// +// # References +// - +// - +// - +// - extern bool tcp_method_tcp_socket_start_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_finish_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); +// Accept a new client socket. +// +// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket: +// - `address-family` +// - `keep-alive-enabled` +// - `keep-alive-idle-time` +// - `keep-alive-interval` +// - `keep-alive-count` +// - `hop-limit` +// - `receive-buffer-size` +// - `send-buffer-size` +// +// On success, this function returns the newly accepted client socket along with +// a pair of streams that can be used to read & write to the connection. +// +// # Typical errors +// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) +// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) +// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED) +// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) +// +// # References +// - +// - +// - +// - extern bool tcp_method_tcp_socket_accept(tcp_borrow_tcp_socket_t self, tcp_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ret, tcp_error_code_t *err); +// Get the bound local address. +// +// POSIX mentions: +// > If the socket has not been bound to a local name, the value +// > stored in the object pointed to by `address` is unspecified. +// +// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. +// +// # References +// - +// - +// - +// - extern bool tcp_method_tcp_socket_local_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err); +// Get the remote address. +// +// # Typical errors +// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) +// +// # References +// - +// - +// - +// - extern bool tcp_method_tcp_socket_remote_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err); +// Whether the socket is in the `listening` state. +// +// Equivalent to the SO_ACCEPTCONN socket option. extern bool tcp_method_tcp_socket_is_listening(tcp_borrow_tcp_socket_t self); +// Whether this is a IPv4 or IPv6 socket. +// +// Equivalent to the SO_DOMAIN socket option. extern tcp_ip_address_family_t tcp_method_tcp_socket_address_family(tcp_borrow_tcp_socket_t self); +// Hints the desired listen queue size. Implementations are free to ignore this. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// +// # Typical errors +// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. +// - `invalid-argument`: (set) The provided value was 0. +// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state. extern bool tcp_method_tcp_socket_set_listen_backlog_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); +// Enables or disables keepalive. +// +// The keepalive behavior can be adjusted using: +// - `keep-alive-idle-time` +// - `keep-alive-interval` +// - `keep-alive-count` +// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. +// +// Equivalent to the SO_KEEPALIVE socket option. extern bool tcp_method_tcp_socket_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool value, tcp_error_code_t *err); +// Amount of time the connection has to be idle before TCP starts sending keepalive packets. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err); +// The time between keepalive packets. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the TCP_KEEPINTVL socket option. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err); +// The maximum amount of keepalive packets TCP should send before aborting the connection. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the TCP_KEEPCNT socket option. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t value, tcp_error_code_t *err); +// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// +// # Typical errors +// - `invalid-argument`: (set) The TTL value must be 1 or higher. extern bool tcp_method_tcp_socket_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t value, tcp_error_code_t *err); +// The kernel buffer space reserved for sends/receives on this socket. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); +// Create a `pollable` which can be used to poll for, or block on, +// completion of any of the asynchronous operations of this socket. +// +// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` +// return `error(would-block)`, this pollable can be used to wait for +// their success or failure, after which the method can be retried. +// +// The pollable is not limited to the async operation that happens to be +// in progress at the time of calling `subscribe` (if any). Theoretically, +// `subscribe` only has to be called once per socket and can then be +// (re)used for the remainder of the socket's lifetime. +// +// See +// for a more information. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. extern tcp_own_pollable_t tcp_method_tcp_socket_subscribe(tcp_borrow_tcp_socket_t self); +// Initiate a graceful shutdown. +// +// - `receive`: The socket is not expecting to receive any data from +// the peer. The `input-stream` associated with this socket will be +// closed. Any data still in the receive queue at time of calling +// this method will be discarded. +// - `send`: The socket has no more data to send to the peer. The `output-stream` +// associated with this socket will be closed and a FIN packet will be sent. +// - `both`: Same effect as `receive` & `send` combined. +// +// This function is idempotent. Shutting a down a direction more than once +// has no effect and returns `ok`. +// +// The shutdown function does not close (drop) the socket. +// +// # Typical errors +// - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) +// +// # References +// - +// - +// - +// - extern bool tcp_method_tcp_socket_shutdown(tcp_borrow_tcp_socket_t self, tcp_shutdown_type_t shutdown_type, tcp_error_code_t *err); // Imported Functions from `wasi:sockets/tcp-create-socket@0.2.0` +// Create a new TCP socket. +// +// Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. +// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. +// +// This function does not require a network capability handle. This is considered to be safe because +// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`connect` +// is called, the socket is effectively an in-memory configuration object, unable to communicate with the outside world. +// +// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. +// +// # Typical errors +// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) +// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) +// +// # References +// - +// - +// - +// - extern bool tcp_create_socket_create_tcp_socket(tcp_create_socket_ip_address_family_t address_family, tcp_create_socket_own_tcp_socket_t *ret, tcp_create_socket_error_code_t *err); // Imported Functions from `wasi:sockets/ip-name-lookup@0.2.0` +// Returns the next address from the resolver. +// +// This function should be called multiple times. On each call, it will +// return the next address in connection order preference. If all +// addresses have been exhausted, this function returns `none`. +// +// This function never returns IPv4-mapped IPv6 addresses. +// +// # Typical errors +// - `name-unresolvable`: Name does not exist or has no suitable associated IP addresses. (EAI_NONAME, EAI_NODATA, EAI_ADDRFAMILY) +// - `temporary-resolver-failure`: A temporary failure in name resolution occurred. (EAI_AGAIN) +// - `permanent-resolver-failure`: A permanent failure in name resolution occurred. (EAI_FAIL) +// - `would-block`: A result is not available yet. (EWOULDBLOCK, EAGAIN) extern bool ip_name_lookup_method_resolve_address_stream_resolve_next_address(ip_name_lookup_borrow_resolve_address_stream_t self, ip_name_lookup_option_ip_address_t *ret, ip_name_lookup_error_code_t *err); +// Create a `pollable` which will resolve once the stream is ready for I/O. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. extern ip_name_lookup_own_pollable_t ip_name_lookup_method_resolve_address_stream_subscribe(ip_name_lookup_borrow_resolve_address_stream_t self); +// Resolve an internet host name to a list of IP addresses. +// +// Unicode domain names are automatically converted to ASCII using IDNA encoding. +// If the input is an IP address string, the address is parsed and returned +// as-is without making any external requests. +// +// See the wasi-socket proposal README.md for a comparison with getaddrinfo. +// +// This function never blocks. It either immediately fails or immediately +// returns successfully with a `resolve-address-stream` that can be used +// to (asynchronously) fetch the results. +// +// # Typical errors +// - `invalid-argument`: `name` is a syntactically invalid domain name or IP address. +// +// # References: +// - +// - +// - +// - extern bool ip_name_lookup_resolve_addresses(ip_name_lookup_borrow_network_t network, wasip2_string_t *name, ip_name_lookup_own_resolve_address_stream_t *ret, ip_name_lookup_error_code_t *err); // Imported Functions from `wasi:random/random@0.2.0` +// Return `len` cryptographically-secure random or pseudo-random bytes. +// +// This function must produce data at least as cryptographically secure and +// fast as an adequately seeded cryptographically-secure pseudo-random +// number generator (CSPRNG). It must not block, from the perspective of +// the calling program, under any circumstances, including on the first +// request and on requests for numbers of bytes. The returned data must +// always be unpredictable. +// +// This function must always return fresh data. Deterministic environments +// must omit this function, rather than implementing it with deterministic +// data. extern void random_get_random_bytes(uint64_t len, wasip2_list_u8_t *ret); +// Return a cryptographically-secure random or pseudo-random `u64` value. +// +// This function returns the same type of data as `get-random-bytes`, +// represented as a `u64`. extern uint64_t random_get_random_u64(void); // Imported Functions from `wasi:random/insecure@0.2.0` +// Return `len` insecure pseudo-random bytes. +// +// This function is not cryptographically secure. Do not use it for +// anything related to security. +// +// There are no requirements on the values of the returned bytes, however +// implementations are encouraged to return evenly distributed values with +// a long period. extern void random_insecure_get_insecure_random_bytes(uint64_t len, wasip2_list_u8_t *ret); +// Return an insecure pseudo-random `u64` value. +// +// This function returns the same type of pseudo-random data as +// `get-insecure-random-bytes`, represented as a `u64`. extern uint64_t random_insecure_get_insecure_random_u64(void); // Imported Functions from `wasi:random/insecure-seed@0.2.0` +// Return a 128-bit value that may contain a pseudo-random value. +// +// The returned value is not required to be computed from a CSPRNG, and may +// even be entirely deterministic. Host implementations are encouraged to +// provide pseudo-random values to any program exposed to +// attacker-controlled content, to enable DoS protection built into many +// languages' hash-map implementations. +// +// This function is intended to only be called once, by a source language +// to initialize Denial Of Service (DoS) protection in its hash-map +// implementation. +// +// # Expected future evolution +// +// This will likely be changed to a value import, to prevent it from being +// called multiple times and potentially used for purposes other than DoS +// protection. extern void random_insecure_seed_insecure_seed(wasip2_tuple2_u64_u64_t *ret); // Helper Functions diff --git a/wasi/wasi-libc-wasip2.wit b/wasi/wasi-libc-wasip2.wit index a3b1657e2..8ec7de0b4 100644 --- a/wasi/wasi-libc-wasip2.wit +++ b/wasi/wasi-libc-wasip2.wit @@ -1,5 +1,11 @@ package wasi-libc:wasip2; -world wasip3 { +world wasip2 { include wasi:cli/command@0.2.0; + include wasi:clocks/imports@0.2.0; + include wasi:filesystem/imports@0.2.0; + include wasi:http/proxy@0.2.0; + include wasi:random/imports@0.2.0; + include wasi:io/imports@0.2.0; + include wasi:sockets/imports@0.2.0; } \ No newline at end of file From d3b8d3495454dafe0324724b50bbbbc6d60a4b96 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 15:50:56 +0000 Subject: [PATCH 24/41] Bindings --- .../headers/public/wasi/__generated_wasip2.h | 1062 +++++++++++++++++ .../headers/public/wasi/__generated_wasip3.h | 3 - libc-bottom-half/sources/wasip3.c | 3 - 3 files changed, 1062 insertions(+), 6 deletions(-) diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip2.h b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h index 371088299..e4f14db97 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip2.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip2.h @@ -66,6 +66,7 @@ typedef struct { typedef io_error_own_error_t streams_own_error_t; +// An error for input-stream and output-stream operations. typedef struct streams_stream_error_t { uint8_t tag; union { @@ -73,7 +74,13 @@ typedef struct streams_stream_error_t { } val; } streams_stream_error_t; +// The last operation (a write or flush) failed before completion. +// +// More information is available in the `error` payload. #define STREAMS_STREAM_ERROR_LAST_OPERATION_FAILED 0 +// The stream is closed: no more input will be accepted by the +// stream. A closed output-stream will return this error on all +// future operations. #define STREAMS_STREAM_ERROR_CLOSED 1 typedef struct streams_own_input_stream_t { @@ -165,12 +172,17 @@ typedef struct { terminal_stderr_own_terminal_output_t val; } terminal_stderr_option_own_terminal_output_t; +// An instant in time, in nanoseconds. An instant is relative to an +// unspecified initial value, and can only be compared to instances from +// the same monotonic-clock. typedef uint64_t monotonic_clock_instant_t; +// A duration of time, in nanoseconds. typedef uint64_t monotonic_clock_duration_t; typedef poll_own_pollable_t monotonic_clock_own_pollable_t; +// A time and date in seconds plus nanoseconds. typedef struct wall_clock_datetime_t { uint64_t seconds; uint32_t nanoseconds; @@ -178,39 +190,95 @@ typedef struct wall_clock_datetime_t { typedef wall_clock_datetime_t filesystem_datetime_t; +// File size or length of a region within a file. typedef uint64_t filesystem_filesize_t; +// The type of a filesystem object referenced by a descriptor. +// +// Note: This was called `filetype` in earlier versions of WASI. typedef uint8_t filesystem_descriptor_type_t; +// The type of the descriptor or file is unknown or is different from +// any of the other types specified. #define FILESYSTEM_DESCRIPTOR_TYPE_UNKNOWN 0 +// The descriptor refers to a block device inode. #define FILESYSTEM_DESCRIPTOR_TYPE_BLOCK_DEVICE 1 +// The descriptor refers to a character device inode. #define FILESYSTEM_DESCRIPTOR_TYPE_CHARACTER_DEVICE 2 +// The descriptor refers to a directory inode. #define FILESYSTEM_DESCRIPTOR_TYPE_DIRECTORY 3 +// The descriptor refers to a named pipe. #define FILESYSTEM_DESCRIPTOR_TYPE_FIFO 4 +// The file refers to a symbolic link inode. #define FILESYSTEM_DESCRIPTOR_TYPE_SYMBOLIC_LINK 5 +// The descriptor refers to a regular file inode. #define FILESYSTEM_DESCRIPTOR_TYPE_REGULAR_FILE 6 +// The descriptor refers to a socket. #define FILESYSTEM_DESCRIPTOR_TYPE_SOCKET 7 +// Descriptor flags. +// +// Note: This was called `fdflags` in earlier versions of WASI. typedef uint8_t filesystem_descriptor_flags_t; +// Read mode: Data can be read. #define FILESYSTEM_DESCRIPTOR_FLAGS_READ (1 << 0) +// Write mode: Data can be written to. #define FILESYSTEM_DESCRIPTOR_FLAGS_WRITE (1 << 1) +// Request that writes be performed according to synchronized I/O file +// integrity completion. The data stored in the file and the file's +// metadata are synchronized. This is similar to `O_SYNC` in POSIX. +// +// The precise semantics of this operation have not yet been defined for +// WASI. At this time, it should be interpreted as a request, and not a +// requirement. #define FILESYSTEM_DESCRIPTOR_FLAGS_FILE_INTEGRITY_SYNC (1 << 2) +// Request that writes be performed according to synchronized I/O data +// integrity completion. Only the data stored in the file is +// synchronized. This is similar to `O_DSYNC` in POSIX. +// +// The precise semantics of this operation have not yet been defined for +// WASI. At this time, it should be interpreted as a request, and not a +// requirement. #define FILESYSTEM_DESCRIPTOR_FLAGS_DATA_INTEGRITY_SYNC (1 << 3) +// Requests that reads be performed at the same level of integrety +// requested for writes. This is similar to `O_RSYNC` in POSIX. +// +// The precise semantics of this operation have not yet been defined for +// WASI. At this time, it should be interpreted as a request, and not a +// requirement. #define FILESYSTEM_DESCRIPTOR_FLAGS_REQUESTED_WRITE_SYNC (1 << 4) +// Mutating directories mode: Directory contents may be mutated. +// +// When this flag is unset on a descriptor, operations using the +// descriptor which would create, rename, delete, modify the data or +// metadata of filesystem objects, or obtain another handle which +// would permit any of those, shall fail with `error-code::read-only` if +// they would otherwise succeed. +// +// This may only be set on directories. #define FILESYSTEM_DESCRIPTOR_FLAGS_MUTATE_DIRECTORY (1 << 5) +// Flags determining the method of how paths are resolved. typedef uint8_t filesystem_path_flags_t; +// As long as the resolved path corresponds to a symbolic link, it is +// expanded. #define FILESYSTEM_PATH_FLAGS_SYMLINK_FOLLOW (1 << 0) +// Open flags used by `open-at`. typedef uint8_t filesystem_open_flags_t; +// Create file if it does not exist, similar to `O_CREAT` in POSIX. #define FILESYSTEM_OPEN_FLAGS_CREATE (1 << 0) +// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. #define FILESYSTEM_OPEN_FLAGS_DIRECTORY (1 << 1) +// Fail if file already exists, similar to `O_EXCL` in POSIX. #define FILESYSTEM_OPEN_FLAGS_EXCLUSIVE (1 << 2) +// Truncate file to size 0, similar to `O_TRUNC` in POSIX. #define FILESYSTEM_OPEN_FLAGS_TRUNCATE (1 << 3) +// Number of hard links to an inode. typedef uint64_t filesystem_link_count_t; typedef struct { @@ -218,15 +286,35 @@ typedef struct { filesystem_datetime_t val; } filesystem_option_datetime_t; +// File attributes. +// +// Note: This was called `filestat` in earlier versions of WASI. typedef struct filesystem_descriptor_stat_t { + // File type. filesystem_descriptor_type_t type; + // Number of hard links to the file. filesystem_link_count_t link_count; + // For regular files, the file size in bytes. For symbolic links, the + // length in bytes of the pathname contained in the symbolic link. filesystem_filesize_t size; + // Last data access timestamp. + // + // If the `option` is none, the platform doesn't maintain an access + // timestamp for this file. filesystem_option_datetime_t data_access_timestamp; + // Last data modification timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // modification timestamp for this file. filesystem_option_datetime_t data_modification_timestamp; + // Last file status-change timestamp. + // + // If the `option` is none, the platform doesn't maintain a + // status-change timestamp for this file. filesystem_option_datetime_t status_change_timestamp; } filesystem_descriptor_stat_t; +// When setting a timestamp, this gives the value to set it to. typedef struct filesystem_new_timestamp_t { uint8_t tag; union { @@ -234,66 +322,131 @@ typedef struct filesystem_new_timestamp_t { } val; } filesystem_new_timestamp_t; +// Leave the timestamp set to its previous value. #define FILESYSTEM_NEW_TIMESTAMP_NO_CHANGE 0 +// Set the timestamp to the current time of the system clock associated +// with the filesystem. #define FILESYSTEM_NEW_TIMESTAMP_NOW 1 +// Set the timestamp to the given value. #define FILESYSTEM_NEW_TIMESTAMP_TIMESTAMP 2 +// A directory entry. typedef struct filesystem_directory_entry_t { + // The type of the file referred to by this directory entry. filesystem_descriptor_type_t type; + // The name of the object. wasip2_string_t name; } filesystem_directory_entry_t; +// Error codes returned by functions, similar to `errno` in POSIX. +// Not all of these error codes are returned by the functions provided by this +// API; some are used in higher-level library layers, and others are provided +// merely for alignment with POSIX. typedef uint8_t filesystem_error_code_t; +// Permission denied, similar to `EACCES` in POSIX. #define FILESYSTEM_ERROR_CODE_ACCESS 0 +// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. #define FILESYSTEM_ERROR_CODE_WOULD_BLOCK 1 +// Connection already in progress, similar to `EALREADY` in POSIX. #define FILESYSTEM_ERROR_CODE_ALREADY 2 +// Bad descriptor, similar to `EBADF` in POSIX. #define FILESYSTEM_ERROR_CODE_BAD_DESCRIPTOR 3 +// Device or resource busy, similar to `EBUSY` in POSIX. #define FILESYSTEM_ERROR_CODE_BUSY 4 +// Resource deadlock would occur, similar to `EDEADLK` in POSIX. #define FILESYSTEM_ERROR_CODE_DEADLOCK 5 +// Storage quota exceeded, similar to `EDQUOT` in POSIX. #define FILESYSTEM_ERROR_CODE_QUOTA 6 +// File exists, similar to `EEXIST` in POSIX. #define FILESYSTEM_ERROR_CODE_EXIST 7 +// File too large, similar to `EFBIG` in POSIX. #define FILESYSTEM_ERROR_CODE_FILE_TOO_LARGE 8 +// Illegal byte sequence, similar to `EILSEQ` in POSIX. #define FILESYSTEM_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE 9 +// Operation in progress, similar to `EINPROGRESS` in POSIX. #define FILESYSTEM_ERROR_CODE_IN_PROGRESS 10 +// Interrupted function, similar to `EINTR` in POSIX. #define FILESYSTEM_ERROR_CODE_INTERRUPTED 11 +// Invalid argument, similar to `EINVAL` in POSIX. #define FILESYSTEM_ERROR_CODE_INVALID 12 +// I/O error, similar to `EIO` in POSIX. #define FILESYSTEM_ERROR_CODE_IO 13 +// Is a directory, similar to `EISDIR` in POSIX. #define FILESYSTEM_ERROR_CODE_IS_DIRECTORY 14 +// Too many levels of symbolic links, similar to `ELOOP` in POSIX. #define FILESYSTEM_ERROR_CODE_LOOP 15 +// Too many links, similar to `EMLINK` in POSIX. #define FILESYSTEM_ERROR_CODE_TOO_MANY_LINKS 16 +// Message too large, similar to `EMSGSIZE` in POSIX. #define FILESYSTEM_ERROR_CODE_MESSAGE_SIZE 17 +// Filename too long, similar to `ENAMETOOLONG` in POSIX. #define FILESYSTEM_ERROR_CODE_NAME_TOO_LONG 18 +// No such device, similar to `ENODEV` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_DEVICE 19 +// No such file or directory, similar to `ENOENT` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_ENTRY 20 +// No locks available, similar to `ENOLCK` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_LOCK 21 +// Not enough space, similar to `ENOMEM` in POSIX. #define FILESYSTEM_ERROR_CODE_INSUFFICIENT_MEMORY 22 +// No space left on device, similar to `ENOSPC` in POSIX. #define FILESYSTEM_ERROR_CODE_INSUFFICIENT_SPACE 23 +// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_DIRECTORY 24 +// Directory not empty, similar to `ENOTEMPTY` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_EMPTY 25 +// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_RECOVERABLE 26 +// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. #define FILESYSTEM_ERROR_CODE_UNSUPPORTED 27 +// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_TTY 28 +// No such device or address, similar to `ENXIO` in POSIX. #define FILESYSTEM_ERROR_CODE_NO_SUCH_DEVICE 29 +// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. #define FILESYSTEM_ERROR_CODE_OVERFLOW 30 +// Operation not permitted, similar to `EPERM` in POSIX. #define FILESYSTEM_ERROR_CODE_NOT_PERMITTED 31 +// Broken pipe, similar to `EPIPE` in POSIX. #define FILESYSTEM_ERROR_CODE_PIPE 32 +// Read-only file system, similar to `EROFS` in POSIX. #define FILESYSTEM_ERROR_CODE_READ_ONLY 33 +// Invalid seek, similar to `ESPIPE` in POSIX. #define FILESYSTEM_ERROR_CODE_INVALID_SEEK 34 +// Text file busy, similar to `ETXTBSY` in POSIX. #define FILESYSTEM_ERROR_CODE_TEXT_FILE_BUSY 35 +// Cross-device link, similar to `EXDEV` in POSIX. #define FILESYSTEM_ERROR_CODE_CROSS_DEVICE 36 +// File or memory access pattern advisory information. typedef uint8_t filesystem_advice_t; +// The application has no advice to give on its behavior with respect +// to the specified data. #define FILESYSTEM_ADVICE_NORMAL 0 +// The application expects to access the specified data sequentially +// from lower offsets to higher offsets. #define FILESYSTEM_ADVICE_SEQUENTIAL 1 +// The application expects to access the specified data in a random +// order. #define FILESYSTEM_ADVICE_RANDOM 2 +// The application expects to access the specified data in the near +// future. #define FILESYSTEM_ADVICE_WILL_NEED 3 +// The application expects that it will not access the specified data +// in the near future. #define FILESYSTEM_ADVICE_DONT_NEED 4 +// The application expects to access the specified data once and then +// not reuse it thereafter. #define FILESYSTEM_ADVICE_NO_REUSE 5 +// A 128-bit hash value, split into parts because wasm doesn't have a +// 128-bit integer type. typedef struct filesystem_metadata_hash_value_t { + // 64 bits of a 128-bit hash value. uint64_t lower; + // Another 64 bits of a 128-bit hash value. uint64_t upper; } filesystem_metadata_hash_value_t; @@ -457,33 +610,85 @@ typedef struct network_borrow_network_t { int32_t __handle; } network_borrow_network_t; +// Error codes. +// +// In theory, every API can return any error code. +// In practice, API's typically only return the errors documented per API +// combined with a couple of errors that are always possible: +// - `unknown` +// - `access-denied` +// - `not-supported` +// - `out-of-memory` +// - `concurrency-conflict` +// +// See each individual API for what the POSIX equivalents are. They sometimes differ per API. typedef uint8_t network_error_code_t; +// Unknown error #define NETWORK_ERROR_CODE_UNKNOWN 0 +// Access denied. +// +// POSIX equivalent: EACCES, EPERM #define NETWORK_ERROR_CODE_ACCESS_DENIED 1 +// The operation is not supported. +// +// POSIX equivalent: EOPNOTSUPP #define NETWORK_ERROR_CODE_NOT_SUPPORTED 2 +// One of the arguments is invalid. +// +// POSIX equivalent: EINVAL #define NETWORK_ERROR_CODE_INVALID_ARGUMENT 3 +// Not enough memory to complete the operation. +// +// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY #define NETWORK_ERROR_CODE_OUT_OF_MEMORY 4 +// The operation timed out before it could finish completely. #define NETWORK_ERROR_CODE_TIMEOUT 5 +// This operation is incompatible with another asynchronous operation that is already in progress. +// +// POSIX equivalent: EALREADY #define NETWORK_ERROR_CODE_CONCURRENCY_CONFLICT 6 +// Trying to finish an asynchronous operation that: +// - has not been started yet, or: +// - was already finished by a previous `finish-*` call. +// +// Note: this is scheduled to be removed when `future`s are natively supported. #define NETWORK_ERROR_CODE_NOT_IN_PROGRESS 7 +// The operation has been aborted because it could not be completed immediately. +// +// Note: this is scheduled to be removed when `future`s are natively supported. #define NETWORK_ERROR_CODE_WOULD_BLOCK 8 +// The operation is not valid in the socket's current state. #define NETWORK_ERROR_CODE_INVALID_STATE 9 +// A new socket resource could not be created because of a system limit. #define NETWORK_ERROR_CODE_NEW_SOCKET_LIMIT 10 +// A bind operation failed because the provided address is not an address that the `network` can bind to. #define NETWORK_ERROR_CODE_ADDRESS_NOT_BINDABLE 11 +// A bind operation failed because the provided address is already in use or because there are no ephemeral ports available. #define NETWORK_ERROR_CODE_ADDRESS_IN_USE 12 +// The remote address is not reachable #define NETWORK_ERROR_CODE_REMOTE_UNREACHABLE 13 +// The TCP connection was forcefully rejected #define NETWORK_ERROR_CODE_CONNECTION_REFUSED 14 +// The TCP connection was reset. #define NETWORK_ERROR_CODE_CONNECTION_RESET 15 +// A TCP connection was aborted. #define NETWORK_ERROR_CODE_CONNECTION_ABORTED 16 +// The size of a datagram sent to a UDP socket exceeded the maximum +// supported size. #define NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE 17 +// Name does not exist or has no suitable associated IP addresses. #define NETWORK_ERROR_CODE_NAME_UNRESOLVABLE 18 +// A temporary failure in name resolution occurred. #define NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE 19 +// A permanent failure in name resolution occurred. #define NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE 20 typedef uint8_t network_ip_address_family_t; +// Similar to `AF_INET` in POSIX. #define NETWORK_IP_ADDRESS_FAMILY_IPV4 0 +// Similar to `AF_INET6` in POSIX. #define NETWORK_IP_ADDRESS_FAMILY_IPV6 1 typedef struct network_ipv4_address_t { @@ -516,14 +721,20 @@ typedef struct network_ip_address_t { #define NETWORK_IP_ADDRESS_IPV6 1 typedef struct network_ipv4_socket_address_t { + // sin_port uint16_t port; + // sin_addr network_ipv4_address_t address; } network_ipv4_socket_address_t; typedef struct network_ipv6_socket_address_t { + // sin6_port uint16_t port; + // sin6_flowinfo uint32_t flow_info; + // sin6_addr network_ipv6_address_t address; + // sin6_scope_id uint32_t scope_id; } network_ipv6_socket_address_t; @@ -546,8 +757,17 @@ typedef network_ip_socket_address_t udp_ip_socket_address_t; typedef network_ip_address_family_t udp_ip_address_family_t; +// A received datagram. typedef struct udp_incoming_datagram_t { + // The payload. + // + // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. wasip2_list_u8_t data; + // The source address. + // + // This field is guaranteed to match the remote address the stream was initialized with, if any. + // + // Equivalent to the `src_addr` out parameter of `recvfrom`. udp_ip_socket_address_t remote_address; } udp_incoming_datagram_t; @@ -556,8 +776,17 @@ typedef struct { udp_ip_socket_address_t val; } udp_option_ip_socket_address_t; +// A datagram to be sent out. typedef struct udp_outgoing_datagram_t { + // The payload. wasip2_list_u8_t data; + // The destination address. + // + // The requirements on this field depend on how the stream was initialized: + // - with a remote address: this field must be None or match the stream's remote address exactly. + // - without a remote address: this field is required. + // + // If this value is None, the send operation is equivalent to `send` in POSIX. Otherwise it is equivalent to `sendto`. udp_option_ip_socket_address_t remote_address; } udp_outgoing_datagram_t; @@ -675,8 +904,11 @@ typedef network_ip_address_family_t tcp_ip_address_family_t; typedef uint8_t tcp_shutdown_type_t; +// Similar to `SHUT_RD` in POSIX. #define TCP_SHUTDOWN_TYPE_RECEIVE 0 +// Similar to `SHUT_WR` in POSIX. #define TCP_SHUTDOWN_TYPE_SEND 1 +// Similar to `SHUT_RDWR` in POSIX. #define TCP_SHUTDOWN_TYPE_BOTH 2 typedef struct tcp_own_tcp_socket_t { @@ -854,20 +1086,115 @@ extern bool environment_initial_cwd(wasip2_string_t *ret); _Noreturn extern void exit_exit(exit_result_void_void_t *status); // Imported Functions from `wasi:io/error@0.2.0` +// Returns a string that is suitable to assist humans in debugging +// this error. +// +// WARNING: The returned string should not be consumed mechanically! +// It may change across platforms, hosts, or other implementation +// details. Parsing this string is a major platform-compatibility +// hazard. extern void io_error_method_error_to_debug_string(io_error_borrow_error_t self, wasip2_string_t *ret); // Imported Functions from `wasi:io/poll@0.2.0` +// Return the readiness of a pollable. This function never blocks. +// +// Returns `true` when the pollable is ready, and `false` otherwise. extern bool poll_method_pollable_ready(poll_borrow_pollable_t self); +// `block` returns immediately if the pollable is ready, and otherwise +// blocks until ready. +// +// This function is equivalent to calling `poll.poll` on a list +// containing only this pollable. extern void poll_method_pollable_block(poll_borrow_pollable_t self); +// Poll for completion on a set of pollables. +// +// This function takes a list of pollables, which identify I/O sources of +// interest, and waits until one or more of the events is ready for I/O. +// +// The result `list` contains one or more indices of handles in the +// argument list that is ready for I/O. +// +// If the list contains more elements than can be indexed with a `u32` +// value, this function traps. +// +// A timeout can be implemented by adding a pollable from the +// wasi-clocks API to the list. +// +// This function does not return a `result`; polling in itself does not +// do any I/O so it doesn't fail. If any of the I/O sources identified by +// the pollables has an error, it is indicated by marking the source as +// being reaedy for I/O. extern void poll_poll(poll_list_borrow_pollable_t *in, wasip2_list_u32_t *ret); // Imported Functions from `wasi:io/streams@0.2.0` +// Perform a non-blocking read from the stream. +// +// When the source of a `read` is binary data, the bytes from the source +// are returned verbatim. When the source of a `read` is known to the +// implementation to be text, bytes containing the UTF-8 encoding of the +// text are returned. +// +// This function returns a list of bytes containing the read data, +// when successful. The returned list will contain up to `len` bytes; +// it may return fewer than requested, but not more. The list is +// empty when no bytes are available for reading at this time. The +// pollable given by `subscribe` will be ready when more bytes are +// available. +// +// This function fails with a `stream-error` when the operation +// encounters an error, giving `last-operation-failed`, or when the +// stream is closed, giving `closed`. +// +// When the caller gives a `len` of 0, it represents a request to +// read 0 bytes. If the stream is still open, this call should +// succeed and return an empty list, or otherwise fail with `closed`. +// +// The `len` parameter is a `u64`, which could represent a list of u8 which +// is not possible to allocate in wasm32, or not desirable to allocate as +// as a return value by the callee. The callee may return a list of bytes +// less than `len` in size while more bytes are available for reading. extern bool streams_method_input_stream_read(streams_borrow_input_stream_t self, uint64_t len, wasip2_list_u8_t *ret, streams_stream_error_t *err); +// Read bytes from a stream, after blocking until at least one byte can +// be read. Except for blocking, behavior is identical to `read`. extern bool streams_method_input_stream_blocking_read(streams_borrow_input_stream_t self, uint64_t len, wasip2_list_u8_t *ret, streams_stream_error_t *err); +// Skip bytes from a stream. Returns number of bytes skipped. +// +// Behaves identical to `read`, except instead of returning a list +// of bytes, returns the number of bytes consumed from the stream. extern bool streams_method_input_stream_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err); +// Skip bytes from a stream, after blocking until at least one byte +// can be skipped. Except for blocking behavior, identical to `skip`. extern bool streams_method_input_stream_blocking_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err); +// Create a `pollable` which will resolve once either the specified stream +// has bytes available to read or the other end of the stream has been +// closed. +// The created `pollable` is a child resource of the `input-stream`. +// Implementations may trap if the `input-stream` is dropped before +// all derived `pollable`s created with this function are dropped. extern streams_own_pollable_t streams_method_input_stream_subscribe(streams_borrow_input_stream_t self); +// Check readiness for writing. This function never blocks. +// +// Returns the number of bytes permitted for the next call to `write`, +// or an error. Calling `write` with more bytes than this function has +// permitted will trap. +// +// When this function returns 0 bytes, the `subscribe` pollable will +// become ready when this function will report at least 1 byte, or an +// error. extern bool streams_method_output_stream_check_write(streams_borrow_output_stream_t self, uint64_t *ret, streams_stream_error_t *err); +// Perform a write. This function never blocks. +// +// When the destination of a `write` is binary data, the bytes from +// `contents` are written verbatim. When the destination of a `write` is +// known to the implementation to be text, the bytes of `contents` are +// transcoded from UTF-8 into the encoding of the destination and then +// written. +// +// Precondition: check-write gave permit of Ok(n) and contents has a +// length of less than or equal to n. Otherwise, this function will trap. +// +// returns Err(closed) without writing if the stream has closed since +// the last call to check-write provided a permit. extern bool streams_method_output_stream_write(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err); // Perform a write of up to 4096 bytes, and then flush the stream. Block // until all of these operations are complete, or an error occurs. @@ -894,9 +1221,37 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // let _ = this.check-write(); // eliding error handling // ``` extern bool streams_method_output_stream_blocking_write_and_flush(streams_borrow_output_stream_t self, wasip2_list_u8_t *contents, streams_stream_error_t *err); +// Request to flush buffered output. This function never blocks. +// +// This tells the output-stream that the caller intends any buffered +// output to be flushed. the output which is expected to be flushed +// is all that has been passed to `write` prior to this call. +// +// Upon calling this function, the `output-stream` will not accept any +// writes (`check-write` will return `ok(0)`) until the flush has +// completed. The `subscribe` pollable will become ready when the +// flush has completed and the stream can accept more writes. extern bool streams_method_output_stream_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err); +// Request to flush buffered output, and block until flush completes +// and stream is ready for writing again. extern bool streams_method_output_stream_blocking_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err); +// Create a `pollable` which will resolve once the output-stream +// is ready for more writing, or an error has occured. When this +// pollable is ready, `check-write` will return `ok(n)` with n>0, or an +// error. +// +// If the stream is closed, this pollable is always ready immediately. +// +// The created `pollable` is a child resource of the `output-stream`. +// Implementations may trap if the `output-stream` is dropped before +// all derived `pollable`s created with this function are dropped. extern streams_own_pollable_t streams_method_output_stream_subscribe(streams_borrow_output_stream_t self); +// Write zeroes to a stream. +// +// This should be used precisely like `write` with the exact same +// preconditions (must use check-write first), but instead of +// passing a list of bytes, you simply pass the number of zero-bytes +// that should be written. extern bool streams_method_output_stream_write_zeroes(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err); // Perform a write of up to 4096 zeroes, and then flush the stream. // Block until all of these operations are complete, or an error @@ -923,7 +1278,25 @@ extern bool streams_method_output_stream_write_zeroes(streams_borrow_output_stre // let _ = this.check-write(); // eliding error handling // ``` extern bool streams_method_output_stream_blocking_write_zeroes_and_flush(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err); +// Read from one stream and write to another. +// +// The behavior of splice is equivelant to: +// 1. calling `check-write` on the `output-stream` +// 2. calling `read` on the `input-stream` with the smaller of the +// `check-write` permitted length and the `len` provided to `splice` +// 3. calling `write` on the `output-stream` with that read data. +// +// Any error reported by the call to `check-write`, `read`, or +// `write` ends the splice and reports that error. +// +// This function returns the number of bytes transferred; it may be less +// than `len`. extern bool streams_method_output_stream_splice(streams_borrow_output_stream_t self, streams_borrow_input_stream_t src, uint64_t len, uint64_t *ret, streams_stream_error_t *err); +// Read from one stream and write to another, with blocking. +// +// This is similar to `splice`, except that it blocks until the +// `output-stream` is ready for writing, and the `input-stream` +// is ready for reading, before performing the `splice`. extern bool streams_method_output_stream_blocking_splice(streams_borrow_output_stream_t self, streams_borrow_input_stream_t src, uint64_t len, uint64_t *ret, streams_stream_error_t *err); // Imported Functions from `wasi:cli/stdin@0.2.0` @@ -951,40 +1324,232 @@ extern bool terminal_stdout_get_terminal_stdout(terminal_stdout_own_terminal_out extern bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t *ret); // Imported Functions from `wasi:clocks/monotonic-clock@0.2.0` +// Read the current value of the clock. +// +// The clock is monotonic, therefore calling this function repeatedly will +// produce a sequence of non-decreasing values. extern monotonic_clock_instant_t monotonic_clock_now(void); +// Query the resolution of the clock. Returns the duration of time +// corresponding to a clock tick. extern monotonic_clock_duration_t monotonic_clock_resolution(void); +// Create a `pollable` which will resolve once the specified instant +// occured. extern monotonic_clock_own_pollable_t monotonic_clock_subscribe_instant(monotonic_clock_instant_t when); +// Create a `pollable` which will resolve once the given duration has +// elapsed, starting at the time at which this function was called. +// occured. extern monotonic_clock_own_pollable_t monotonic_clock_subscribe_duration(monotonic_clock_duration_t when); // Imported Functions from `wasi:clocks/wall-clock@0.2.0` +// Read the current value of the clock. +// +// This clock is not monotonic, therefore calling this function repeatedly +// will not necessarily produce a sequence of non-decreasing values. +// +// The returned timestamps represent the number of seconds since +// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], +// also known as [Unix Time]. +// +// The nanoseconds field of the output is always less than 1000000000. +// +// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 +// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time extern void wall_clock_now(wall_clock_datetime_t *ret); +// Query the resolution of the clock. +// +// The nanoseconds field of the output is always less than 1000000000. extern void wall_clock_resolution(wall_clock_datetime_t *ret); // Imported Functions from `wasi:filesystem/types@0.2.0` +// Return a stream for reading from a file, if available. +// +// May fail with an error-code describing why the file cannot be read. +// +// Multiple read, write, and append streams may be active on the same open +// file and they do not interfere with each other. +// +// Note: This allows using `read-stream`, which is similar to `read` in POSIX. extern bool filesystem_method_descriptor_read_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_own_input_stream_t *ret, filesystem_error_code_t *err); +// Return a stream for writing to a file, if available. +// +// May fail with an error-code describing why the file cannot be written. +// +// Note: This allows using `write-stream`, which is similar to `write` in +// POSIX. extern bool filesystem_method_descriptor_write_via_stream(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_own_output_stream_t *ret, filesystem_error_code_t *err); +// Return a stream for appending to a file, if available. +// +// May fail with an error-code describing why the file cannot be appended. +// +// Note: This allows using `write-stream`, which is similar to `write` with +// `O_APPEND` in in POSIX. extern bool filesystem_method_descriptor_append_via_stream(filesystem_borrow_descriptor_t self, filesystem_own_output_stream_t *ret, filesystem_error_code_t *err); +// Provide file advisory information on a descriptor. +// +// This is similar to `posix_fadvise` in POSIX. extern bool filesystem_method_descriptor_advise(filesystem_borrow_descriptor_t self, filesystem_filesize_t offset, filesystem_filesize_t length, filesystem_advice_t advice, filesystem_error_code_t *err); +// Synchronize the data of a file to disk. +// +// This function succeeds with no effect if the file descriptor is not +// opened for writing. +// +// Note: This is similar to `fdatasync` in POSIX. extern bool filesystem_method_descriptor_sync_data(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err); +// Get flags associated with a descriptor. +// +// Note: This returns similar flags to `fcntl(fd, F_GETFL)` in POSIX. +// +// Note: This returns the value that was the `fs_flags` value returned +// from `fdstat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_get_flags(filesystem_borrow_descriptor_t self, filesystem_descriptor_flags_t *ret, filesystem_error_code_t *err); +// Get the dynamic type of a descriptor. +// +// Note: This returns the same value as the `type` field of the `fd-stat` +// returned by `stat`, `stat-at` and similar. +// +// Note: This returns similar flags to the `st_mode & S_IFMT` value provided +// by `fstat` in POSIX. +// +// Note: This returns the value that was the `fs_filetype` value returned +// from `fdstat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_get_type(filesystem_borrow_descriptor_t self, filesystem_descriptor_type_t *ret, filesystem_error_code_t *err); +// Adjust the size of an open file. If this increases the file's size, the +// extra bytes are filled with zeros. +// +// Note: This was called `fd_filestat_set_size` in earlier versions of WASI. extern bool filesystem_method_descriptor_set_size(filesystem_borrow_descriptor_t self, filesystem_filesize_t size, filesystem_error_code_t *err); +// Adjust the timestamps of an open file or directory. +// +// Note: This is similar to `futimens` in POSIX. +// +// Note: This was called `fd_filestat_set_times` in earlier versions of WASI. extern bool filesystem_method_descriptor_set_times(filesystem_borrow_descriptor_t self, filesystem_new_timestamp_t *data_access_timestamp, filesystem_new_timestamp_t *data_modification_timestamp, filesystem_error_code_t *err); +// Read from a descriptor, without using and updating the descriptor's offset. +// +// This function returns a list of bytes containing the data that was +// read, along with a bool which, when true, indicates that the end of the +// file was reached. The returned list will contain up to `length` bytes; it +// may return fewer than requested, if the end of the file is reached or +// if the I/O operation is interrupted. +// +// In the future, this may change to return a `stream`. +// +// Note: This is similar to `pread` in POSIX. extern bool filesystem_method_descriptor_read(filesystem_borrow_descriptor_t self, filesystem_filesize_t length, filesystem_filesize_t offset, wasip2_tuple2_list_u8_bool_t *ret, filesystem_error_code_t *err); +// Write to a descriptor, without using and updating the descriptor's offset. +// +// It is valid to write past the end of a file; the file is extended to the +// extent of the write, with bytes between the previous end and the start of +// the write set to zero. +// +// In the future, this may change to take a `stream`. +// +// Note: This is similar to `pwrite` in POSIX. extern bool filesystem_method_descriptor_write(filesystem_borrow_descriptor_t self, wasip2_list_u8_t *buffer, filesystem_filesize_t offset, filesystem_filesize_t *ret, filesystem_error_code_t *err); +// Read directory entries from a directory. +// +// On filesystems where directories contain entries referring to themselves +// and their parents, often named `.` and `..` respectively, these entries +// are omitted. +// +// This always returns a new stream which starts at the beginning of the +// directory. Multiple streams may be active on the same directory, and they +// do not interfere with each other. extern bool filesystem_method_descriptor_read_directory(filesystem_borrow_descriptor_t self, filesystem_own_directory_entry_stream_t *ret, filesystem_error_code_t *err); +// Synchronize the data and metadata of a file to disk. +// +// This function succeeds with no effect if the file descriptor is not +// opened for writing. +// +// Note: This is similar to `fsync` in POSIX. extern bool filesystem_method_descriptor_sync(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err); +// Create a directory. +// +// Note: This is similar to `mkdirat` in POSIX. extern bool filesystem_method_descriptor_create_directory_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); +// Return the attributes of an open file or directory. +// +// Note: This is similar to `fstat` in POSIX, except that it does not return +// device and inode information. For testing whether two descriptors refer to +// the same underlying filesystem object, use `is-same-object`. To obtain +// additional data that can be used do determine whether a file has been +// modified, use `metadata-hash`. +// +// Note: This was called `fd_filestat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_stat(filesystem_borrow_descriptor_t self, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err); +// Return the attributes of a file or directory. +// +// Note: This is similar to `fstatat` in POSIX, except that it does not +// return device and inode information. See the `stat` description for a +// discussion of alternatives. +// +// Note: This was called `path_filestat_get` in earlier versions of WASI. extern bool filesystem_method_descriptor_stat_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err); +// Adjust the timestamps of a file or directory. +// +// Note: This is similar to `utimensat` in POSIX. +// +// Note: This was called `path_filestat_set_times` in earlier versions of +// WASI. extern bool filesystem_method_descriptor_set_times_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_new_timestamp_t *data_access_timestamp, filesystem_new_timestamp_t *data_modification_timestamp, filesystem_error_code_t *err); +// Create a hard link. +// +// Note: This is similar to `linkat` in POSIX. extern bool filesystem_method_descriptor_link_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t old_path_flags, wasip2_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, wasip2_string_t *new_path, filesystem_error_code_t *err); +// Open a file or directory. +// +// The returned descriptor is not guaranteed to be the lowest-numbered +// 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 descriptor is +// guaranteed to be less than 2**31. +// +// If `flags` contains `descriptor-flags::mutate-directory`, and the base +// descriptor doesn't have `descriptor-flags::mutate-directory` set, +// `open-at` fails with `error-code::read-only`. +// +// If `flags` contains `write` or `mutate-directory`, or `open-flags` +// contains `truncate` or `create`, and the base descriptor doesn't have +// `descriptor-flags::mutate-directory` set, `open-at` fails with +// `error-code::read-only`. +// +// Note: This is similar to `openat` in POSIX. extern bool filesystem_method_descriptor_open_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_open_flags_t open_flags, filesystem_descriptor_flags_t flags, filesystem_own_descriptor_t *ret, filesystem_error_code_t *err); +// Read the contents of a symbolic link. +// +// If the contents contain an absolute or rooted path in the underlying +// filesystem, this function fails with `error-code::not-permitted`. +// +// Note: This is similar to `readlinkat` in POSIX. extern bool filesystem_method_descriptor_readlink_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, wasip2_string_t *ret, filesystem_error_code_t *err); +// Remove a directory. +// +// Return `error-code::not-empty` if the directory is not empty. +// +// Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. extern bool filesystem_method_descriptor_remove_directory_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); +// Rename a filesystem object. +// +// Note: This is similar to `renameat` in POSIX. extern bool filesystem_method_descriptor_rename_at(filesystem_borrow_descriptor_t self, wasip2_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, wasip2_string_t *new_path, filesystem_error_code_t *err); +// Create a symbolic link (also known as a "symlink"). +// +// If `old-path` starts with `/`, the function fails with +// `error-code::not-permitted`. +// +// Note: This is similar to `symlinkat` in POSIX. extern bool filesystem_method_descriptor_symlink_at(filesystem_borrow_descriptor_t self, wasip2_string_t *old_path, wasip2_string_t *new_path, filesystem_error_code_t *err); +// Unlink a filesystem object that is not a directory. +// +// Return `error-code::is-directory` if the path refers to a directory. +// Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. extern bool filesystem_method_descriptor_unlink_file_at(filesystem_borrow_descriptor_t self, wasip2_string_t *path, filesystem_error_code_t *err); +// Test whether two descriptors refer to the same filesystem object. +// +// In POSIX, this corresponds to testing whether the two descriptors have the +// same device (`st_dev`) and inode (`st_ino` or `d_ino`) numbers. +// wasi-filesystem does not expose device and inode numbers, so this function +// may be used instead. extern bool filesystem_method_descriptor_is_same_object(filesystem_borrow_descriptor_t self, filesystem_borrow_descriptor_t other); // Return a hash of the metadata associated with a filesystem object referred // to by a descriptor. @@ -1006,17 +1571,60 @@ extern bool filesystem_method_descriptor_is_same_object(filesystem_borrow_descri // // However, none of these is required. extern bool filesystem_method_descriptor_metadata_hash(filesystem_borrow_descriptor_t self, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err); +// Return a hash of the metadata associated with a filesystem object referred +// to by a directory descriptor and a relative path. +// +// This performs the same hash computation as `metadata-hash`. extern bool filesystem_method_descriptor_metadata_hash_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, wasip2_string_t *path, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err); +// Read a single directory entry from a `directory-entry-stream`. extern bool filesystem_method_directory_entry_stream_read_directory_entry(filesystem_borrow_directory_entry_stream_t self, filesystem_option_directory_entry_t *ret, filesystem_error_code_t *err); +// Attempts to extract a filesystem-related `error-code` from the stream +// `error` provided. +// +// Stream operations which return `stream-error::last-operation-failed` +// have a payload with more information about the operation that failed. +// This payload can be passed through to this function to see if there's +// filesystem-related information about the error to return. +// +// Note that this function is fallible because not all stream-related +// errors are filesystem-related errors. extern bool filesystem_filesystem_error_code(filesystem_borrow_error_t err_, filesystem_error_code_t *ret); // Imported Functions from `wasi:filesystem/preopens@0.2.0` +// Return the set of preopened directories, and their path. extern void filesystem_preopens_get_directories(filesystem_preopens_list_tuple2_own_descriptor_string_t *ret); // Imported Functions from `wasi:sockets/instance-network@0.2.0` +// Get a handle to the default network. extern instance_network_own_network_t instance_network_instance_network(void); // Imported Functions from `wasi:sockets/udp@0.2.0` +// Bind the socket to a specific network on the provided IP address and port. +// +// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which +// network interface(s) to bind to. +// If the port is zero, the socket will be bound to a random free port. +// +// # Typical errors +// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) +// - `invalid-state`: The socket is already bound. (EINVAL) +// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) +// - `address-in-use`: Address is already in use. (EADDRINUSE) +// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) +// - `not-in-progress`: A `bind` operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// Unlike in POSIX, in WASI the bind operation is async. This enables +// interactive WASI hosts to inject permission prompts. Runtimes that +// don't want to make use of this ability can simply call the native +// `bind` as part of either `start-bind` or `finish-bind`. +// +// # References +// - +// - +// - +// - extern bool udp_method_udp_socket_start_bind(udp_borrow_udp_socket_t self, udp_borrow_network_t network, udp_ip_socket_address_t *local_address, udp_error_code_t *err); extern bool udp_method_udp_socket_finish_bind(udp_borrow_udp_socket_t self, udp_error_code_t *err); // Set up inbound & outbound communication channels, optionally to a specific peer. @@ -1060,52 +1668,441 @@ extern bool udp_method_udp_socket_finish_bind(udp_borrow_udp_socket_t self, udp_ // - // - extern bool udp_method_udp_socket_stream(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *maybe_remote_address, udp_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_t *ret, udp_error_code_t *err); +// Get the current bound address. +// +// POSIX mentions: +// > If the socket has not been bound to a local name, the value +// > stored in the object pointed to by `address` is unspecified. +// +// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. +// +// # References +// - +// - +// - +// - extern bool udp_method_udp_socket_local_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err); +// Get the address the socket is currently streaming to. +// +// # Typical errors +// - `invalid-state`: The socket is not streaming to a specific remote address. (ENOTCONN) +// +// # References +// - +// - +// - +// - extern bool udp_method_udp_socket_remote_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err); +// Whether this is a IPv4 or IPv6 socket. +// +// Equivalent to the SO_DOMAIN socket option. extern udp_ip_address_family_t udp_method_udp_socket_address_family(udp_borrow_udp_socket_t self); +// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// +// # Typical errors +// - `invalid-argument`: (set) The TTL value must be 1 or higher. extern bool udp_method_udp_socket_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t *ret, udp_error_code_t *err); extern bool udp_method_udp_socket_set_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t value, udp_error_code_t *err); +// The kernel buffer space reserved for sends/receives on this socket. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. extern bool udp_method_udp_socket_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err); extern bool udp_method_udp_socket_set_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err); extern bool udp_method_udp_socket_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err); extern bool udp_method_udp_socket_set_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err); +// Create a `pollable` which will resolve once the socket is ready for I/O. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. extern udp_own_pollable_t udp_method_udp_socket_subscribe(udp_borrow_udp_socket_t self); +// Receive messages on the socket. +// +// This function attempts to receive up to `max-results` datagrams on the socket without blocking. +// The returned list may contain fewer elements than requested, but never more. +// +// This function returns successfully with an empty list when either: +// - `max-results` is 0, or: +// - `max-results` is greater than 0, but no results are immediately available. +// This function never returns `error(would-block)`. +// +// # Typical errors +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// +// # References +// - +// - +// - +// - +// - +// - +// - +// - extern bool udp_method_incoming_datagram_stream_receive(udp_borrow_incoming_datagram_stream_t self, uint64_t max_results, udp_list_incoming_datagram_t *ret, udp_error_code_t *err); +// Create a `pollable` which will resolve once the stream is ready to receive again. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. extern udp_own_pollable_t udp_method_incoming_datagram_stream_subscribe(udp_borrow_incoming_datagram_stream_t self); +// Check readiness for sending. This function never blocks. +// +// Returns the number of datagrams permitted for the next call to `send`, +// or an error. Calling `send` with more datagrams than this function has +// permitted will trap. +// +// When this function returns ok(0), the `subscribe` pollable will +// become ready when this function will report at least ok(1), or an +// error. +// +// Never returns `would-block`. extern bool udp_method_outgoing_datagram_stream_check_send(udp_borrow_outgoing_datagram_stream_t self, uint64_t *ret, udp_error_code_t *err); +// Send messages on the socket. +// +// This function attempts to send all provided `datagrams` on the socket without blocking and +// returns how many messages were actually sent (or queued for sending). This function never +// returns `error(would-block)`. If none of the datagrams were able to be sent, `ok(0)` is returned. +// +// This function semantically behaves the same as iterating the `datagrams` list and sequentially +// sending each individual datagram until either the end of the list has been reached or the first error occurred. +// If at least one datagram has been sent successfully, this function never returns an error. +// +// If the input list is empty, the function returns `ok(0)`. +// +// Each call to `send` must be permitted by a preceding `check-send`. Implementations must trap if +// either `check-send` was not called or `datagrams` contains more items than `check-send` permitted. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EDESTADDRREQ, EADDRNOTAVAIL) +// - `invalid-argument`: The socket is in "connected" mode and `remote-address` is `some` value that does not match the address passed to `stream`. (EISCONN) +// - `invalid-argument`: The socket is not "connected" and no value for `remote-address` was provided. (EDESTADDRREQ) +// - `remote-unreachable`: The remote address is not reachable. (ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `connection-refused`: The connection was refused. (ECONNREFUSED) +// - `datagram-too-large`: The datagram is too large. (EMSGSIZE) +// +// # References +// - +// - +// - +// - +// - +// - +// - +// - extern bool udp_method_outgoing_datagram_stream_send(udp_borrow_outgoing_datagram_stream_t self, udp_list_outgoing_datagram_t *datagrams, uint64_t *ret, udp_error_code_t *err); +// Create a `pollable` which will resolve once the stream is ready to send again. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. extern udp_own_pollable_t udp_method_outgoing_datagram_stream_subscribe(udp_borrow_outgoing_datagram_stream_t self); // Imported Functions from `wasi:sockets/udp-create-socket@0.2.0` +// Create a new UDP socket. +// +// Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX. +// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. +// +// This function does not require a network capability handle. This is considered to be safe because +// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind` is called, +// the socket is effectively an in-memory configuration object, unable to communicate with the outside world. +// +// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. +// +// # Typical errors +// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) +// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) +// +// # References: +// - +// - +// - +// - extern bool udp_create_socket_create_udp_socket(udp_create_socket_ip_address_family_t address_family, udp_create_socket_own_udp_socket_t *ret, udp_create_socket_error_code_t *err); // Imported Functions from `wasi:sockets/tcp@0.2.0` +// Bind the socket to a specific network on the provided IP address and port. +// +// If the IP address is zero (`0.0.0.0` in IPv4, `::` in IPv6), it is left to the implementation to decide which +// network interface(s) to bind to. +// If the TCP/UDP port is zero, the socket will be bound to a random free port. +// +// Bind can be attempted multiple times on the same socket, even with +// different arguments on each iteration. But never concurrently and +// only as long as the previous bind failed. Once a bind succeeds, the +// binding can't be changed anymore. +// +// # Typical errors +// - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) +// - `invalid-argument`: `local-address` is not a unicast address. (EINVAL) +// - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL) +// - `invalid-state`: The socket is already bound. (EINVAL) +// - `address-in-use`: No ephemeral ports available. (EADDRINUSE, ENOBUFS on Windows) +// - `address-in-use`: Address is already in use. (EADDRINUSE) +// - `address-not-bindable`: `local-address` is not an address that the `network` can bind to. (EADDRNOTAVAIL) +// - `not-in-progress`: A `bind` operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// When binding to a non-zero port, this bind operation shouldn't be affected by the TIME_WAIT +// state of a recently closed socket on the same local address. In practice this means that the SO_REUSEADDR +// socket option should be set implicitly on all platforms, except on Windows where this is the default behavior +// and SO_REUSEADDR performs something different entirely. +// +// Unlike in POSIX, in WASI the bind operation is async. This enables +// interactive WASI hosts to inject permission prompts. Runtimes that +// don't want to make use of this ability can simply call the native +// `bind` as part of either `start-bind` or `finish-bind`. +// +// # References +// - +// - +// - +// - extern bool tcp_method_tcp_socket_start_bind(tcp_borrow_tcp_socket_t self, tcp_borrow_network_t network, tcp_ip_socket_address_t *local_address, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_finish_bind(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); +// Connect to a remote endpoint. +// +// On success: +// - the socket is transitioned into the `connection` state. +// - a pair of streams is returned that can be used to read & write to the connection +// +// After a failed connection attempt, the socket will be in the `closed` +// state and the only valid action left is to `drop` the socket. A single +// socket can not be used to connect more than once. +// +// # Typical errors +// - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) +// - `invalid-argument`: `remote-address` is not a unicast address. (EINVAL, ENETUNREACH on Linux, EAFNOSUPPORT on MacOS) +// - `invalid-argument`: `remote-address` is an IPv4-mapped IPv6 address. (EINVAL, EADDRNOTAVAIL on Illumos) +// - `invalid-argument`: The IP address in `remote-address` is set to INADDR_ANY (`0.0.0.0` / `::`). (EADDRNOTAVAIL on Windows) +// - `invalid-argument`: The port in `remote-address` is set to 0. (EADDRNOTAVAIL on Windows) +// - `invalid-argument`: The socket is already attached to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. +// - `invalid-state`: The socket is already in the `connected` state. (EISCONN) +// - `invalid-state`: The socket is already in the `listening` state. (EOPNOTSUPP, EINVAL on Windows) +// - `timeout`: Connection timed out. (ETIMEDOUT) +// - `connection-refused`: The connection was forcefully rejected. (ECONNREFUSED) +// - `connection-reset`: The connection was reset. (ECONNRESET) +// - `connection-aborted`: The connection was aborted. (ECONNABORTED) +// - `remote-unreachable`: The remote address is not reachable. (EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN, ENONET) +// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE, EADDRNOTAVAIL on Linux, EAGAIN on BSD) +// - `not-in-progress`: A connect operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// The POSIX equivalent of `start-connect` is the regular `connect` syscall. +// Because all WASI sockets are non-blocking this is expected to return +// EINPROGRESS, which should be translated to `ok()` in WASI. +// +// The POSIX equivalent of `finish-connect` is a `poll` for event `POLLOUT` +// with a timeout of 0 on the socket descriptor. Followed by a check for +// the `SO_ERROR` socket option, in case the poll signaled readiness. +// +// # References +// - +// - +// - +// - extern bool tcp_method_tcp_socket_start_connect(tcp_borrow_tcp_socket_t self, tcp_borrow_network_t network, tcp_ip_socket_address_t *remote_address, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_finish_connect(tcp_borrow_tcp_socket_t self, tcp_tuple2_own_input_stream_own_output_stream_t *ret, tcp_error_code_t *err); +// Start listening for new connections. +// +// Transitions the socket into the `listening` state. +// +// Unlike POSIX, the socket must already be explicitly bound. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) +// - `invalid-state`: The socket is already in the `connected` state. (EISCONN, EINVAL on BSD) +// - `invalid-state`: The socket is already in the `listening` state. +// - `address-in-use`: Tried to perform an implicit bind, but there were no ephemeral ports available. (EADDRINUSE) +// - `not-in-progress`: A listen operation is not in progress. +// - `would-block`: Can't finish the operation, it is still in progress. (EWOULDBLOCK, EAGAIN) +// +// # Implementors note +// Unlike in POSIX, in WASI the listen operation is async. This enables +// interactive WASI hosts to inject permission prompts. Runtimes that +// don't want to make use of this ability can simply call the native +// `listen` as part of either `start-listen` or `finish-listen`. +// +// # References +// - +// - +// - +// - extern bool tcp_method_tcp_socket_start_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_finish_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err); +// Accept a new client socket. +// +// The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket: +// - `address-family` +// - `keep-alive-enabled` +// - `keep-alive-idle-time` +// - `keep-alive-interval` +// - `keep-alive-count` +// - `hop-limit` +// - `receive-buffer-size` +// - `send-buffer-size` +// +// On success, this function returns the newly accepted client socket along with +// a pair of streams that can be used to read & write to the connection. +// +// # Typical errors +// - `invalid-state`: Socket is not in the `listening` state. (EINVAL) +// - `would-block`: No pending connections at the moment. (EWOULDBLOCK, EAGAIN) +// - `connection-aborted`: An incoming connection was pending, but was terminated by the client before this listener could accept it. (ECONNABORTED) +// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) +// +// # References +// - +// - +// - +// - extern bool tcp_method_tcp_socket_accept(tcp_borrow_tcp_socket_t self, tcp_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ret, tcp_error_code_t *err); +// Get the bound local address. +// +// POSIX mentions: +// > If the socket has not been bound to a local name, the value +// > stored in the object pointed to by `address` is unspecified. +// +// WASI is stricter and requires `local-address` to return `invalid-state` when the socket hasn't been bound yet. +// +// # Typical errors +// - `invalid-state`: The socket is not bound to any local address. +// +// # References +// - +// - +// - +// - extern bool tcp_method_tcp_socket_local_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err); +// Get the remote address. +// +// # Typical errors +// - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) +// +// # References +// - +// - +// - +// - extern bool tcp_method_tcp_socket_remote_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err); +// Whether the socket is in the `listening` state. +// +// Equivalent to the SO_ACCEPTCONN socket option. extern bool tcp_method_tcp_socket_is_listening(tcp_borrow_tcp_socket_t self); +// Whether this is a IPv4 or IPv6 socket. +// +// Equivalent to the SO_DOMAIN socket option. extern tcp_ip_address_family_t tcp_method_tcp_socket_address_family(tcp_borrow_tcp_socket_t self); +// Hints the desired listen queue size. Implementations are free to ignore this. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// +// # Typical errors +// - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. +// - `invalid-argument`: (set) The provided value was 0. +// - `invalid-state`: (set) The socket is in the `connect-in-progress` or `connected` state. extern bool tcp_method_tcp_socket_set_listen_backlog_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); +// Enables or disables keepalive. +// +// The keepalive behavior can be adjusted using: +// - `keep-alive-idle-time` +// - `keep-alive-interval` +// - `keep-alive-count` +// These properties can be configured while `keep-alive-enabled` is false, but only come into effect when `keep-alive-enabled` is true. +// +// Equivalent to the SO_KEEPALIVE socket option. extern bool tcp_method_tcp_socket_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool value, tcp_error_code_t *err); +// Amount of time the connection has to be idle before TCP starts sending keepalive packets. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the TCP_KEEPIDLE socket option. (TCP_KEEPALIVE on MacOS) +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err); +// The time between keepalive packets. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the TCP_KEEPINTVL socket option. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err); +// The maximum amount of keepalive packets TCP should send before aborting the connection. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the TCP_KEEPCNT socket option. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t value, tcp_error_code_t *err); +// Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// +// # Typical errors +// - `invalid-argument`: (set) The TTL value must be 1 or higher. extern bool tcp_method_tcp_socket_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t value, tcp_error_code_t *err); +// The kernel buffer space reserved for sends/receives on this socket. +// +// If the provided value is 0, an `invalid-argument` error is returned. +// Any other value will never cause an error, but it might be silently clamped and/or rounded. +// I.e. after setting a value, reading the same setting back may return a different value. +// +// Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. +// +// # Typical errors +// - `invalid-argument`: (set) The provided value was 0. extern bool tcp_method_tcp_socket_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err); extern bool tcp_method_tcp_socket_set_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err); +// Create a `pollable` which can be used to poll for, or block on, +// completion of any of the asynchronous operations of this socket. +// +// When `finish-bind`, `finish-listen`, `finish-connect` or `accept` +// return `error(would-block)`, this pollable can be used to wait for +// their success or failure, after which the method can be retried. +// +// The pollable is not limited to the async operation that happens to be +// in progress at the time of calling `subscribe` (if any). Theoretically, +// `subscribe` only has to be called once per socket and can then be +// (re)used for the remainder of the socket's lifetime. +// +// See +// for a more information. +// +// Note: this function is here for WASI Preview2 only. +// It's planned to be removed when `future` is natively supported in Preview3. extern tcp_own_pollable_t tcp_method_tcp_socket_subscribe(tcp_borrow_tcp_socket_t self); // Initiate a graceful shutdown. // @@ -1133,6 +2130,26 @@ extern tcp_own_pollable_t tcp_method_tcp_socket_subscribe(tcp_borrow_tcp_socket_ extern bool tcp_method_tcp_socket_shutdown(tcp_borrow_tcp_socket_t self, tcp_shutdown_type_t shutdown_type, tcp_error_code_t *err); // Imported Functions from `wasi:sockets/tcp-create-socket@0.2.0` +// Create a new TCP socket. +// +// Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. +// On IPv6 sockets, IPV6_V6ONLY is enabled by default and can't be configured otherwise. +// +// This function does not require a network capability handle. This is considered to be safe because +// at time of creation, the socket is not bound to any `network` yet. Up to the moment `bind`/`connect` +// is called, the socket is effectively an in-memory configuration object, unable to communicate with the outside world. +// +// All sockets are non-blocking. Use the wasi-poll interface to block on asynchronous operations. +// +// # Typical errors +// - `not-supported`: The specified `address-family` is not supported. (EAFNOSUPPORT) +// - `new-socket-limit`: The new socket resource could not be created because of a system limit. (EMFILE, ENFILE) +// +// # References +// - +// - +// - +// - extern bool tcp_create_socket_create_tcp_socket(tcp_create_socket_ip_address_family_t address_family, tcp_create_socket_own_tcp_socket_t *ret, tcp_create_socket_error_code_t *err); // Imported Functions from `wasi:sockets/ip-name-lookup@0.2.0` @@ -1178,14 +2195,59 @@ extern ip_name_lookup_own_pollable_t ip_name_lookup_method_resolve_address_strea extern bool ip_name_lookup_resolve_addresses(ip_name_lookup_borrow_network_t network, wasip2_string_t *name, ip_name_lookup_own_resolve_address_stream_t *ret, ip_name_lookup_error_code_t *err); // Imported Functions from `wasi:random/random@0.2.0` +// Return `len` cryptographically-secure random or pseudo-random bytes. +// +// This function must produce data at least as cryptographically secure and +// fast as an adequately seeded cryptographically-secure pseudo-random +// number generator (CSPRNG). It must not block, from the perspective of +// the calling program, under any circumstances, including on the first +// request and on requests for numbers of bytes. The returned data must +// always be unpredictable. +// +// This function must always return fresh data. Deterministic environments +// must omit this function, rather than implementing it with deterministic +// data. extern void random_get_random_bytes(uint64_t len, wasip2_list_u8_t *ret); +// Return a cryptographically-secure random or pseudo-random `u64` value. +// +// This function returns the same type of data as `get-random-bytes`, +// represented as a `u64`. extern uint64_t random_get_random_u64(void); // Imported Functions from `wasi:random/insecure@0.2.0` +// Return `len` insecure pseudo-random bytes. +// +// This function is not cryptographically secure. Do not use it for +// anything related to security. +// +// There are no requirements on the values of the returned bytes, however +// implementations are encouraged to return evenly distributed values with +// a long period. extern void random_insecure_get_insecure_random_bytes(uint64_t len, wasip2_list_u8_t *ret); +// Return an insecure pseudo-random `u64` value. +// +// This function returns the same type of pseudo-random data as +// `get-insecure-random-bytes`, represented as a `u64`. extern uint64_t random_insecure_get_insecure_random_u64(void); // Imported Functions from `wasi:random/insecure-seed@0.2.0` +// Return a 128-bit value that may contain a pseudo-random value. +// +// The returned value is not required to be computed from a CSPRNG, and may +// even be entirely deterministic. Host implementations are encouraged to +// provide pseudo-random values to any program exposed to +// attacker-controlled content, to enable DoS protection built into many +// languages' hash-map implementations. +// +// This function is intended to only be called once, by a source language +// to initialize Denial Of Service (DoS) protection in its hash-map +// implementation. +// +// # Expected future evolution +// +// This will likely be changed to a value import, to prevent it from being +// called multiple times and potentially used for purposes other than DoS +// protection. extern void random_insecure_seed_insecure_seed(wasip2_tuple2_u64_u64_t *ret); // Helper Functions diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h index 727e6867c..f08d6e0c6 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h @@ -78,7 +78,6 @@ void wasip3_backpressure_dec(void); void* wasip3_context_get_0(void); void wasip3_context_set_0(void* value); void wasip3_thread_yield(void); -<<<<<<< HEAD void* wasip3_context_get_1(void); @@ -93,8 +92,6 @@ void wasip3_thread_yield_to(uint32_t thread); uint32_t wasip3_thread_yield_to_cancellable(uint32_t thread); void wasip3_thread_suspend(void); uint32_t wasip3_thread_suspend_cancellable(void); -======= ->>>>>>> sy/wasip3-bindings diff --git a/libc-bottom-half/sources/wasip3.c b/libc-bottom-half/sources/wasip3.c index e672ce62b..f8de0c2ec 100644 --- a/libc-bottom-half/sources/wasip3.c +++ b/libc-bottom-half/sources/wasip3.c @@ -1141,7 +1141,6 @@ void wasip3_thread_yield(void) { __thread_yield(); } -<<<<<<< HEAD __attribute__((__import_module__("$root"), __import_name__("[context-get-1]"))) extern void* __context_get_1(void); @@ -1227,8 +1226,6 @@ uint32_t wasip3_thread_suspend_cancellable(void) { return __thread_suspend_cancellable(); } -======= ->>>>>>> sy/wasip3-bindings // Component Adapters From de2f8bd80dcd26c7c30d0fa0def569cbbaa5d7de Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 16:10:48 +0000 Subject: [PATCH 25/41] Use configure_file for versions --- cmake/bindings.cmake | 104 +++++++++++++++++------------------ wasi/wasi-libc-wasip2.wit | 11 ---- wasi/wasi-libc-wasip2.wit.in | 11 ++++ wasi/wasi-libc-wasip3.wit | 10 ---- wasi/wasi-libc-wasip3.wit.in | 10 ++++ 5 files changed, 73 insertions(+), 73 deletions(-) delete mode 100644 wasi/wasi-libc-wasip2.wit create mode 100644 wasi/wasi-libc-wasip2.wit.in delete mode 100644 wasi/wasi-libc-wasip3.wit create mode 100644 wasi/wasi-libc-wasip3.wit.in diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index 8d81d6f1b..ffb699f87 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -69,9 +69,9 @@ endif() set(bottom_half "${CMAKE_SOURCE_DIR}/libc-bottom-half") set(wasip2_wit_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi/p2/wit) -set(p2 0.2.0) +set(wasip2-version 0.2.0) file(MAKE_DIRECTORY ${wasip2_wit_dir}) -configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip2.wit ${wasip2_wit_dir} COPYONLY) +configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip2.wit.in ${wasip2_wit_dir}/wasi-libc-wasip2.wit) add_custom_target( wasip2-wits COMMAND ${wkg} wit fetch @@ -84,34 +84,34 @@ add_custom_target( --autodrop-borrows yes --rename-world wasip2 --type-section-suffix __wasi_libc - --world wasi:cli/imports@${p2} - --rename wasi:clocks/monotonic-clock@${p2}=monotonic_clock - --rename wasi:clocks/wall-clock@${p2}=wall_clock - --rename wasi:filesystem/preopens@${p2}=filesystem_preopens - --rename wasi:filesystem/types@${p2}=filesystem - --rename wasi:io/error@${p2}=io_error - --rename wasi:io/poll@${p2}=poll - --rename wasi:io/streams@${p2}=streams - --rename wasi:random/insecure-seed@${p2}=random_insecure_seed - --rename wasi:random/insecure@${p2}=random_insecure - --rename wasi:random/random@${p2}=random - --rename wasi:sockets/instance-network@${p2}=instance_network - --rename wasi:sockets/ip-name-lookup@${p2}=ip_name_lookup - --rename wasi:sockets/network@${p2}=network - --rename wasi:sockets/tcp-create-socket@${p2}=tcp_create_socket - --rename wasi:sockets/tcp@${p2}=tcp - --rename wasi:sockets/udp-create-socket@${p2}=udp_create_socket - --rename wasi:sockets/udp@${p2}=udp - --rename wasi:cli/environment@${p2}=environment - --rename wasi:cli/exit@${p2}=exit - --rename wasi:cli/stdin@${p2}=stdin - --rename wasi:cli/stdout@${p2}=stdout - --rename wasi:cli/stderr@${p2}=stderr - --rename wasi:cli/terminal-input@${p2}=terminal_input - --rename wasi:cli/terminal-output@${p2}=terminal_output - --rename wasi:cli/terminal-stdin@${p2}=terminal_stdin - --rename wasi:cli/terminal-stdout@${p2}=terminal_stdout - --rename wasi:cli/terminal-stderr@${p2}=terminal_stderr + --world wasi:cli/imports@${wasip2-version} + --rename wasi:clocks/monotonic-clock@${wasip2-version}=monotonic_clock + --rename wasi:clocks/wall-clock@${wasip2-version}=wall_clock + --rename wasi:filesystem/preopens@${wasip2-version}=filesystem_preopens + --rename wasi:filesystem/types@${wasip2-version}=filesystem + --rename wasi:io/error@${wasip2-version}=io_error + --rename wasi:io/poll@${wasip2-version}=poll + --rename wasi:io/streams@${wasip2-version}=streams + --rename wasi:random/insecure-seed@${wasip2-version}=random_insecure_seed + --rename wasi:random/insecure@${wasip2-version}=random_insecure + --rename wasi:random/random@${wasip2-version}=random + --rename wasi:sockets/instance-network@${wasip2-version}=instance_network + --rename wasi:sockets/ip-name-lookup@${wasip2-version}=ip_name_lookup + --rename wasi:sockets/network@${wasip2-version}=network + --rename wasi:sockets/tcp-create-socket@${wasip2-version}=tcp_create_socket + --rename wasi:sockets/tcp@${wasip2-version}=tcp + --rename wasi:sockets/udp-create-socket@${wasip2-version}=udp_create_socket + --rename wasi:sockets/udp@${wasip2-version}=udp + --rename wasi:cli/environment@${wasip2-version}=environment + --rename wasi:cli/exit@${wasip2-version}=exit + --rename wasi:cli/stdin@${wasip2-version}=stdin + --rename wasi:cli/stdout@${wasip2-version}=stdout + --rename wasi:cli/stderr@${wasip2-version}=stderr + --rename wasi:cli/terminal-input@${wasip2-version}=terminal_input + --rename wasi:cli/terminal-output@${wasip2-version}=terminal_output + --rename wasi:cli/terminal-stdin@${wasip2-version}=terminal_stdin + --rename wasi:cli/terminal-stdout@${wasip2-version}=terminal_stdout + --rename wasi:cli/terminal-stderr@${wasip2-version}=terminal_stderr ${wasip2_wit_dir} COMMAND cmake -E copy wasip2.h ${bottom_half}/headers/public/wasi/__generated_wasip2.h COMMAND cmake -E copy wasip2_component_type.o ${bottom_half}/sources @@ -120,9 +120,9 @@ add_custom_target( ) set(wasip3_wit_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi/p3/wit) -set(p3 0.3.0-rc-2026-01-06) +set(wasip3-version 0.3.0-rc-2026-01-06) file(MAKE_DIRECTORY ${wasip3_wit_dir}) -configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip3.wit ${wasip3_wit_dir} COPYONLY) +configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip3.wit.in ${wasip3_wit_dir}/wasi-libc-wasip3.wit) add_custom_target( wasip3-wits COMMAND ${wkg} wit fetch @@ -135,26 +135,26 @@ add_custom_target( --autodrop-borrows yes --rename-world wasip3 --type-section-suffix __wasi_libc - --world wasi:cli/imports@${p3} - --rename wasi:clocks/monotonic-clock@${p3}=monotonic_clock - --rename wasi:clocks/wall-clock@${p3}=wall_clock - --rename wasi:filesystem/preopens@${p3}=filesystem_preopens - --rename wasi:filesystem/types@${p3}=filesystem - --rename wasi:random/insecure-seed@${p3}=random_insecure_seed - --rename wasi:random/insecure@${p3}=random_insecure - --rename wasi:random/random@${p3}=random - --rename wasi:sockets/types@${p3}=sockets - --rename wasi:sockets/ip-name-lookup@${p3}=ip_name_lookup - --rename wasi:cli/environment@${p3}=environment - --rename wasi:cli/exit@${p3}=exit - --rename wasi:cli/stdin@${p3}=stdin - --rename wasi:cli/stdout@${p3}=stdout - --rename wasi:cli/stderr@${p3}=stderr - --rename wasi:cli/terminal-input@${p3}=terminal_input - --rename wasi:cli/terminal-output@${p3}=terminal_output - --rename wasi:cli/terminal-stdin@${p3}=terminal_stdin - --rename wasi:cli/terminal-stdout@${p3}=terminal_stdout - --rename wasi:cli/terminal-stderr@${p3}=terminal_stderr + --world wasi:cli/imports@${wasip3-version} + --rename wasi:clocks/monotonic-clock@${wasip3-version}=monotonic_clock + --rename wasi:clocks/wall-clock@${wasip3-version}=wall_clock + --rename wasi:filesystem/preopens@${wasip3-version}=filesystem_preopens + --rename wasi:filesystem/types@${wasip3-version}=filesystem + --rename wasi:random/insecure-seed@${wasip3-version}=random_insecure_seed + --rename wasi:random/insecure@${wasip3-version}=random_insecure + --rename wasi:random/random@${wasip3-version}=random + --rename wasi:sockets/types@${wasip3-version}=sockets + --rename wasi:sockets/ip-name-lookup@${wasip3-version}=ip_name_lookup + --rename wasi:cli/environment@${wasip3-version}=environment + --rename wasi:cli/exit@${wasip3-version}=exit + --rename wasi:cli/stdin@${wasip3-version}=stdin + --rename wasi:cli/stdout@${wasip3-version}=stdout + --rename wasi:cli/stderr@${wasip3-version}=stderr + --rename wasi:cli/terminal-input@${wasip3-version}=terminal_input + --rename wasi:cli/terminal-output@${wasip3-version}=terminal_output + --rename wasi:cli/terminal-stdin@${wasip3-version}=terminal_stdin + --rename wasi:cli/terminal-stdout@${wasip3-version}=terminal_stdout + --rename wasi:cli/terminal-stderr@${wasip3-version}=terminal_stderr ${wasip3_wit_dir} COMMAND cmake -E copy wasip3.h ${bottom_half}/headers/public/wasi/__generated_wasip3.h COMMAND cmake -E copy wasip3_component_type.o ${bottom_half}/sources diff --git a/wasi/wasi-libc-wasip2.wit b/wasi/wasi-libc-wasip2.wit deleted file mode 100644 index 8ec7de0b4..000000000 --- a/wasi/wasi-libc-wasip2.wit +++ /dev/null @@ -1,11 +0,0 @@ -package wasi-libc:wasip2; - -world wasip2 { - include wasi:cli/command@0.2.0; - include wasi:clocks/imports@0.2.0; - include wasi:filesystem/imports@0.2.0; - include wasi:http/proxy@0.2.0; - include wasi:random/imports@0.2.0; - include wasi:io/imports@0.2.0; - include wasi:sockets/imports@0.2.0; -} \ No newline at end of file diff --git a/wasi/wasi-libc-wasip2.wit.in b/wasi/wasi-libc-wasip2.wit.in new file mode 100644 index 000000000..a68af3929 --- /dev/null +++ b/wasi/wasi-libc-wasip2.wit.in @@ -0,0 +1,11 @@ +package wasi-libc:wasip2; + +world wasip2 { + include wasi:cli/command@${wasip2-version}; + include wasi:clocks/imports@${wasip2-version}; + include wasi:filesystem/imports@${wasip2-version}; + include wasi:http/proxy@${wasip2-version}; + include wasi:random/imports@${wasip2-version}; + include wasi:io/imports@${wasip2-version}; + include wasi:sockets/imports@${wasip2-version}; +} \ No newline at end of file diff --git a/wasi/wasi-libc-wasip3.wit b/wasi/wasi-libc-wasip3.wit deleted file mode 100644 index 68726e260..000000000 --- a/wasi/wasi-libc-wasip3.wit +++ /dev/null @@ -1,10 +0,0 @@ -package wasi-libc:wasip3; - -world wasip3 { - include wasi:cli/command@0.3.0-rc-2026-01-06; - include wasi:clocks/imports@0.3.0-rc-2026-01-06; - include wasi:filesystem/imports@0.3.0-rc-2026-01-06; - include wasi:http/middleware@0.3.0-rc-2026-01-06; - include wasi:random/imports@0.3.0-rc-2026-01-06; - include wasi:sockets/imports@0.3.0-rc-2026-01-06; -} \ No newline at end of file diff --git a/wasi/wasi-libc-wasip3.wit.in b/wasi/wasi-libc-wasip3.wit.in new file mode 100644 index 000000000..e4f586bd3 --- /dev/null +++ b/wasi/wasi-libc-wasip3.wit.in @@ -0,0 +1,10 @@ +package wasi-libc:wasip3; + +world wasip3 { + include wasi:cli/command@${wasip3-version}; + include wasi:clocks/imports@${wasip3-version}; + include wasi:filesystem/imports@${wasip3-version}; + include wasi:http/middleware@${wasip3-version}; + include wasi:random/imports@${wasip3-version}; + include wasi:sockets/imports@${wasip3-version}; +} \ No newline at end of file From e7bb3b48326dac82a4baf1bc0ce97e86745c3df9 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 16:12:09 +0000 Subject: [PATCH 26/41] Fix target name --- cmake/bindings.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index ffb699f87..7bf9abfd8 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -55,7 +55,7 @@ endif() if (NOT WKG_EXECUTABLE) include(ba-download) ba_download( - wit-bindgen + wkg "https://github.com/bytecodealliance/wasm-pkg-tools" "0.13.0" ) From 8ffc6f7560779e9affefb034be720e1110d0870a Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 16:48:15 +0000 Subject: [PATCH 27/41] Correct downloading wkg --- cmake/ba-download.cmake | 55 ++++++++++++++++++++++++++++++++--------- cmake/bindings.cmake | 10 +++++--- 2 files changed, 49 insertions(+), 16 deletions(-) diff --git a/cmake/ba-download.cmake b/cmake/ba-download.cmake index c3e2dc46f..4a2157a74 100644 --- a/cmake/ba-download.cmake +++ b/cmake/ba-download.cmake @@ -15,11 +15,23 @@ function(ba_download target repo version) endif() if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") - set(os macos) + if (target STREQUAL wkg) + set(os apple-darwin) + else() + set(os macos) + endif() elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux") - set(os linux) + if (target STREQUAL wkg) + set(os unknown-linux-gnu) + else() + set(os linux) + endif() elseif (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - set(os windows) + if (target STREQUAL wkg) + set(os pc-windows-gnu) + else() + set(os windows) + endif() else() set(os "UNKNOWN_OS") message(WARNING "Unsupported system ${CMAKE_HOST_SYSTEM_NAME} for ${target}") @@ -34,20 +46,39 @@ function(ba_download target repo version) set(fmt tar.gz) endif() - if (target STREQUAL wit-bindgen OR target STREQUAL wasm-tools) + if (target STREQUAL wit-bindgen OR target STREQUAL wasm-tools OR target STREQUAL wkg) set(tag v${version}) else() set(tag ${version}) endif() + message(STATUS "Using ${target} ${version} for ${arch}-${os} from ${repo}") - ExternalProject_Add( - ${target} - EXCLUDE_FROM_ALL ON - URL "${repo}/releases/download/${tag}/${target}-${version}-${arch}-${os}.${fmt}" - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - ) + if (target STREQUAL wkg) + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(chmod_cmd "") + else() + set(chmod_cmd chmod +x /wkg) + endif() + ExternalProject_Add( + ${target} + EXCLUDE_FROM_ALL ON + URL "${repo}/releases/download/${tag}/${target}-${arch}-${os}" + DOWNLOAD_NO_EXTRACT ON + DOWNLOAD_NAME wkg-bin + CONFIGURE_COMMAND ${chmod_cmd} + BUILD_COMMAND "" + INSTALL_COMMAND "" + ) + else() + ExternalProject_Add( + ${target} + EXCLUDE_FROM_ALL ON + URL "${repo}/releases/download/${tag}/${target}-${version}-${arch}-${os}.${fmt}" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + ) + endif() endfunction() diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index 7bf9abfd8..3c28ab82f 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -4,6 +4,8 @@ if (NOT BINDINGS_TARGET) return() endif() +include(ExternalProject) + # If `wit-bindgen` is on the system and has the right version, favor that, # otherwise download a known good version. find_program(WIT_BINDGEN_EXECUTABLE NAMES wit-bindgen) @@ -59,8 +61,8 @@ if (NOT WKG_EXECUTABLE) "https://github.com/bytecodealliance/wasm-pkg-tools" "0.13.0" ) - ExternalProject_Get_Property(wkg SOURCE_DIR) - set(wkg "${SOURCE_DIR}/wkg") + ExternalProject_Get_Property(wkg DOWNLOAD_DIR) + set(wkg "${DOWNLOAD_DIR}/wkg-bin") else() add_custom_target(wkg) set(wkg ${WKG_EXECUTABLE}) @@ -116,7 +118,7 @@ add_custom_target( COMMAND cmake -E copy wasip2.h ${bottom_half}/headers/public/wasi/__generated_wasip2.h COMMAND cmake -E copy wasip2_component_type.o ${bottom_half}/sources COMMAND cmake -E copy wasip2.c ${bottom_half}/sources - DEPENDS wit-bindgen wasip2-wits + DEPENDS wit-bindgen wkg wasip2-wits ) set(wasip3_wit_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi/p3/wit) @@ -159,7 +161,7 @@ add_custom_target( COMMAND cmake -E copy wasip3.h ${bottom_half}/headers/public/wasi/__generated_wasip3.h COMMAND cmake -E copy wasip3_component_type.o ${bottom_half}/sources COMMAND cmake -E copy wasip3.c ${bottom_half}/sources - DEPENDS wit-bindgen wasip3-wits + DEPENDS wit-bindgen wkg wasip3-wits ) add_custom_target(bindings DEPENDS bindings-p2 bindings-p3) From befee4d71f44bbe7153af4984e43574fa02ebe68 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 16:49:08 +0000 Subject: [PATCH 28/41] Add comment --- cmake/ba-download.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/ba-download.cmake b/cmake/ba-download.cmake index 4a2157a74..fcf69f6fd 100644 --- a/cmake/ba-download.cmake +++ b/cmake/ba-download.cmake @@ -56,7 +56,8 @@ function(ba_download target repo version) message(STATUS "Using ${target} ${version} for ${arch}-${os} from ${repo}") if (target STREQUAL wkg) - if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + # wkg ships a binary rather than an archive + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") set(chmod_cmd "") else() set(chmod_cmd chmod +x /wkg) From 804b3720abb7e98afe6aed5d6e3e7f4fd2183301 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 16:52:37 +0000 Subject: [PATCH 29/41] Change target names for wkg --- cmake/bindings.cmake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index 3c28ab82f..f7c900f48 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -62,10 +62,10 @@ if (NOT WKG_EXECUTABLE) "0.13.0" ) ExternalProject_Get_Property(wkg DOWNLOAD_DIR) - set(wkg "${DOWNLOAD_DIR}/wkg-bin") + set(wkg_bin "${DOWNLOAD_DIR}/wkg-bin") else() add_custom_target(wkg) - set(wkg ${WKG_EXECUTABLE}) + set(wkg_bin ${WKG_EXECUTABLE}) endif() set(bottom_half "${CMAKE_SOURCE_DIR}/libc-bottom-half") @@ -127,7 +127,7 @@ file(MAKE_DIRECTORY ${wasip3_wit_dir}) configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip3.wit.in ${wasip3_wit_dir}/wasi-libc-wasip3.wit) add_custom_target( wasip3-wits - COMMAND ${wkg} wit fetch + COMMAND ${wkg_bin} wit fetch WORKING_DIRECTORY ${wasip3_wit_dir}/.. ) add_custom_target( From 89ab58725ae809573996d9f014fe1a83f5a6d941 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 17:00:08 +0000 Subject: [PATCH 30/41] Fix wkg --- cmake/ba-download.cmake | 3 +-- cmake/bindings.cmake | 10 ++++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/cmake/ba-download.cmake b/cmake/ba-download.cmake index fcf69f6fd..58797cfaf 100644 --- a/cmake/ba-download.cmake +++ b/cmake/ba-download.cmake @@ -60,14 +60,13 @@ function(ba_download target repo version) if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") set(chmod_cmd "") else() - set(chmod_cmd chmod +x /wkg) + set(chmod_cmd chmod +x ) endif() ExternalProject_Add( ${target} EXCLUDE_FROM_ALL ON URL "${repo}/releases/download/${tag}/${target}-${arch}-${os}" DOWNLOAD_NO_EXTRACT ON - DOWNLOAD_NAME wkg-bin CONFIGURE_COMMAND ${chmod_cmd} BUILD_COMMAND "" INSTALL_COMMAND "" diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index f7c900f48..249884880 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -61,8 +61,8 @@ if (NOT WKG_EXECUTABLE) "https://github.com/bytecodealliance/wasm-pkg-tools" "0.13.0" ) - ExternalProject_Get_Property(wkg DOWNLOAD_DIR) - set(wkg_bin "${DOWNLOAD_DIR}/wkg-bin") + ExternalProject_Get_Property(wkg DOWNLOADED_FILE) + set(wkg_bin "${DOWNLOADED_FILE}") else() add_custom_target(wkg) set(wkg_bin ${WKG_EXECUTABLE}) @@ -76,8 +76,9 @@ file(MAKE_DIRECTORY ${wasip2_wit_dir}) configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip2.wit.in ${wasip2_wit_dir}/wasi-libc-wasip2.wit) add_custom_target( wasip2-wits - COMMAND ${wkg} wit fetch + COMMAND ${wkg_bin} wit fetch WORKING_DIRECTORY ${wasip2_wit_dir}/.. + DEPENDS wkg ) add_custom_target( bindings-p2 @@ -129,6 +130,7 @@ add_custom_target( wasip3-wits COMMAND ${wkg_bin} wit fetch WORKING_DIRECTORY ${wasip3_wit_dir}/.. + DEPENDS wkg ) add_custom_target( bindings-p3 @@ -161,7 +163,7 @@ add_custom_target( COMMAND cmake -E copy wasip3.h ${bottom_half}/headers/public/wasi/__generated_wasip3.h COMMAND cmake -E copy wasip3_component_type.o ${bottom_half}/sources COMMAND cmake -E copy wasip3.c ${bottom_half}/sources - DEPENDS wit-bindgen wkg wasip3-wits + DEPENDS wit-bindgen wasip3-wits ) add_custom_target(bindings DEPENDS bindings-p2 bindings-p3) From 8e553aca284609a63be304253bb6213b523ecf6c Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 17:04:13 +0000 Subject: [PATCH 31/41] Correct sed on mac --- cmake/bindings.cmake | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index 249884880..7e055fce0 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -168,12 +168,18 @@ add_custom_target( add_custom_target(bindings DEPENDS bindings-p2 bindings-p3) +if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(SED_INPLACE_FLAG "''") +else() + set(SED_INPLACE_FLAG "") +endif() + function(wit_bindgen_edit p) add_custom_target( bindings-${p}-edit - COMMAND sed -i '' "'s_#include .wasi${p}\.h._#include \"wasi/wasi${p}.h\"_'" ${bottom_half}/sources/wasi${p}.c - COMMAND sed -i '' "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/__generated_wasi${p}.h - COMMAND sed -i '' "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasi${p}.c + COMMAND sed -i ${SED_INPLACE_FLAG} "'s_#include .wasi${p}\.h._#include \"wasi/wasi${p}.h\"_'" ${bottom_half}/sources/wasi${p}.c + COMMAND sed -i ${SED_INPLACE_FLAG} "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/__generated_wasi${p}.h + COMMAND sed -i ${SED_INPLACE_FLAG} "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasi${p}.c DEPENDS bindings-${p} ) add_dependencies(bindings bindings-${p}-edit) From 80dd8eb6b1b69742649403be8ea02d3ec9120201 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 17:05:24 +0000 Subject: [PATCH 32/41] Add defined symbol for wasip2 --- expected/wasm32-wasip2/defined-symbols.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/expected/wasm32-wasip2/defined-symbols.txt b/expected/wasm32-wasip2/defined-symbols.txt index 1475ea0bb..1b59fe560 100644 --- a/expected/wasm32-wasip2/defined-symbols.txt +++ b/expected/wasm32-wasip2/defined-symbols.txt @@ -1504,6 +1504,7 @@ wasip2_list_u32_free wasip2_list_u8_free wasip2_option_string_free wasip2_string_dup +wasip2_string_dup_n wasip2_string_free wasip2_string_from_c wasip2_string_set From 1ff00a0e8bd06191a818aad4fd5552300bc8017d Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 17:10:48 +0000 Subject: [PATCH 33/41] Update symbols --- expected/wasm32-wasip3/defined-symbols.txt | 15 +++++++-------- expected/wasm32-wasip3/predefined-macros.txt | 1 - expected/wasm32-wasip3/undefined-symbols.txt | 10 ++++------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/expected/wasm32-wasip3/defined-symbols.txt b/expected/wasm32-wasip3/defined-symbols.txt index 81a03a483..43887c518 100644 --- a/expected/wasm32-wasip3/defined-symbols.txt +++ b/expected/wasm32-wasip3/defined-symbols.txt @@ -646,7 +646,7 @@ filesystem_method_descriptor_sync_data filesystem_method_descriptor_unlink_file_at filesystem_method_descriptor_write_via_stream filesystem_new_timestamp_free -filesystem_option_datetime_free +filesystem_option_instant_free filesystem_preopens_get_directories filesystem_preopens_list_tuple2_own_descriptor_string_free filesystem_preopens_tuple2_own_descriptor_string_free @@ -1459,31 +1459,30 @@ vswprintf vswscanf vwprintf vwscanf -wall_clock_get_resolution -wall_clock_now +wasi_clocks_system_clock_get_resolution +wasi_clocks_system_clock_now wasip3_backpressure_dec wasip3_backpressure_inc -wasip3_backpressure_set -wasip3_context_get -wasip3_context_set +wasip3_context_get_0 +wasip3_context_set_0 wasip3_list_string_free wasip3_list_tuple2_string_string_free wasip3_list_u8_free wasip3_option_string_free wasip3_string_dup +wasip3_string_dup_n wasip3_string_free wasip3_string_set wasip3_subtask_cancel wasip3_subtask_drop wasip3_task_cancel +wasip3_thread_yield wasip3_tuple2_string_string_free wasip3_waitable_join wasip3_waitable_set_drop wasip3_waitable_set_new wasip3_waitable_set_poll wasip3_waitable_set_wait -wasip3_yield -wasip3_yield_cancellable wcpcpy wcpncpy wcrtomb diff --git a/expected/wasm32-wasip3/predefined-macros.txt b/expected/wasm32-wasip3/predefined-macros.txt index 8f6bc4aa3..8e2f62089 100644 --- a/expected/wasm32-wasip3/predefined-macros.txt +++ b/expected/wasm32-wasip3/predefined-macros.txt @@ -2206,7 +2206,6 @@ #define UTIME_NOW (-1) #define UTIME_OMIT (-2) #define WASIP3_CALLBACK_CODE_EXIT 0 -#define WASIP3_CALLBACK_CODE_POLL(set) (3 | (set << 4)) #define WASIP3_CALLBACK_CODE_WAIT(set) (2 | (set << 4)) #define WASIP3_CALLBACK_CODE_YIELD 1 #define WASIP3_SUBTASK_HANDLE(status) ((wasip3_subtask_t) ((status) >> 4)) diff --git a/expected/wasm32-wasip3/undefined-symbols.txt b/expected/wasm32-wasip3/undefined-symbols.txt index ec4a54a33..71c91f823 100644 --- a/expected/wasm32-wasip3/undefined-symbols.txt +++ b/expected/wasm32-wasip3/undefined-symbols.txt @@ -1,9 +1,8 @@ __addtf3 __backpressure_dec __backpressure_inc -__backpressure_set -__context_get -__context_set +__context_get_0 +__context_set_0 __data_end __divtf3 __eqtf2 @@ -28,7 +27,6 @@ __subtask_drop __subtf3 __task_cancel __thread_yield -__thread_yield_cancellable __trunctfdf2 __trunctfsf2 __unordtf2 @@ -129,8 +127,8 @@ __wasm_import_terminal_output_terminal_output_drop __wasm_import_terminal_stderr_get_terminal_stderr __wasm_import_terminal_stdin_get_terminal_stdin __wasm_import_terminal_stdout_get_terminal_stdout -__wasm_import_wall_clock_get_resolution -__wasm_import_wall_clock_now +__wasm_import_wasi_clocks_system_clock_get_resolution +__wasm_import_wasi_clocks_system_clock_now filesystem_future_result_void_error_code__cancel_read filesystem_future_result_void_error_code__cancel_write filesystem_future_result_void_error_code__drop_readable From 4655c5dad2e600b73cdd4e619ea007bf37214854 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 17:15:47 +0000 Subject: [PATCH 34/41] Bump wasmtime --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b337b55ac..8815b9bcd 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -284,7 +284,7 @@ jobs: - name: Setup `wasmtime` uses: bytecodealliance/actions/wasmtime/setup@v1 with: - version: "38.0.3" + version: "40.0.2" - name: Setup wasi-libc run: | cmake -S . -B build -G Ninja \ From c92167eff2948ce5314d114a71c8f97c00d3d872 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 17:21:04 +0000 Subject: [PATCH 35/41] Attempt to fix windows --- cmake/ba-download.cmake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmake/ba-download.cmake b/cmake/ba-download.cmake index 58797cfaf..b4207a827 100644 --- a/cmake/ba-download.cmake +++ b/cmake/ba-download.cmake @@ -57,9 +57,7 @@ function(ba_download target repo version) if (target STREQUAL wkg) # wkg ships a binary rather than an archive - if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - set(chmod_cmd "") - else() + if (NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") set(chmod_cmd chmod +x ) endif() ExternalProject_Add( From 69eb82cd6ba34e4e104d5799509176de6ef40e09 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Thu, 15 Jan 2026 17:26:46 +0000 Subject: [PATCH 36/41] Change to file download --- cmake/ba-download.cmake | 31 +++++++++++++++++++------------ cmake/bindings.cmake | 23 +++++++++++++++-------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/cmake/ba-download.cmake b/cmake/ba-download.cmake index b4207a827..7e35fb298 100644 --- a/cmake/ba-download.cmake +++ b/cmake/ba-download.cmake @@ -56,19 +56,26 @@ function(ba_download target repo version) message(STATUS "Using ${target} ${version} for ${arch}-${os} from ${repo}") if (target STREQUAL wkg) - # wkg ships a binary rather than an archive - if (NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - set(chmod_cmd chmod +x ) + # wkg ships a single binary rather than an archive + set(download_path "${CMAKE_CURRENT_BINARY_DIR}/${target}") + set(url "${repo}/releases/download/${tag}/${target}-${arch}-${os}") + + if (NOT EXISTS "${download_path}") + message(STATUS "Downloading ${target} from ${url}") + file(DOWNLOAD "${url}" "${download_path}" STATUS download_status) + list(GET download_status 0 status_code) + if (NOT status_code EQUAL 0) + list(GET download_status 1 error_message) + message(FATAL_ERROR "Failed to download ${target}: ${error_message}") + endif() + + if (NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + execute_process(COMMAND chmod +x "${download_path}") + endif() endif() - ExternalProject_Add( - ${target} - EXCLUDE_FROM_ALL ON - URL "${repo}/releases/download/${tag}/${target}-${arch}-${os}" - DOWNLOAD_NO_EXTRACT ON - CONFIGURE_COMMAND ${chmod_cmd} - BUILD_COMMAND "" - INSTALL_COMMAND "" - ) + + add_custom_target(${target}) + set(${target}_bin "${download_path}" PARENT_SCOPE) else() ExternalProject_Add( ${target} diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index 7e055fce0..e82a0b77b 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -61,8 +61,7 @@ if (NOT WKG_EXECUTABLE) "https://github.com/bytecodealliance/wasm-pkg-tools" "0.13.0" ) - ExternalProject_Get_Property(wkg DOWNLOADED_FILE) - set(wkg_bin "${DOWNLOADED_FILE}") + # wkg_bin is set by ba_download else() add_custom_target(wkg) set(wkg_bin ${WKG_EXECUTABLE}) @@ -74,12 +73,16 @@ set(wasip2_wit_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi/p2/wit) set(wasip2-version 0.2.0) file(MAKE_DIRECTORY ${wasip2_wit_dir}) configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip2.wit.in ${wasip2_wit_dir}/wasi-libc-wasip2.wit) -add_custom_target( - wasip2-wits +set(wasip2_stamp ${CMAKE_CURRENT_BINARY_DIR}/wasi/p2/.wit-fetch-stamp) +add_custom_command( + OUTPUT ${wasip2_stamp} COMMAND ${wkg_bin} wit fetch + COMMAND ${CMAKE_COMMAND} -E touch ${wasip2_stamp} WORKING_DIRECTORY ${wasip2_wit_dir}/.. - DEPENDS wkg + DEPENDS wkg ${wasip2_wit_dir}/wasi-libc-wasip2.wit + COMMENT "Fetching WASI P2 dependencies" ) +add_custom_target(wasip2-wits DEPENDS ${wasip2_stamp}) add_custom_target( bindings-p2 COMMAND @@ -126,12 +129,16 @@ set(wasip3_wit_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi/p3/wit) set(wasip3-version 0.3.0-rc-2026-01-06) file(MAKE_DIRECTORY ${wasip3_wit_dir}) configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip3.wit.in ${wasip3_wit_dir}/wasi-libc-wasip3.wit) -add_custom_target( - wasip3-wits +set(wasip3_stamp ${CMAKE_CURRENT_BINARY_DIR}/wasi/p3/.wit-fetch-stamp) +add_custom_command( + OUTPUT ${wasip3_stamp} COMMAND ${wkg_bin} wit fetch + COMMAND ${CMAKE_COMMAND} -E touch ${wasip3_stamp} WORKING_DIRECTORY ${wasip3_wit_dir}/.. - DEPENDS wkg + DEPENDS wkg ${wasip3_wit_dir}/wasi-libc-wasip3.wit + COMMENT "Fetching WASI P3 dependencies" ) +add_custom_target(wasip3-wits DEPENDS ${wasip3_stamp}) add_custom_target( bindings-p3 COMMAND From c164b41d26aa5055de38dbcfc5d1c033a59fc899 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Fri, 16 Jan 2026 10:17:14 +0000 Subject: [PATCH 37/41] Add overflow checks --- libc-bottom-half/cloudlibc/src/common/time.h | 21 ++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/common/time.h b/libc-bottom-half/cloudlibc/src/common/time.h index 9c5ae4877..a59bc344b 100644 --- a/libc-bottom-half/cloudlibc/src/common/time.h +++ b/libc-bottom-half/cloudlibc/src/common/time.h @@ -33,15 +33,17 @@ static inline bool timespec_to_timestamp_exact( if (timespec->tv_nsec < 0 || timespec->tv_nsec >= NSEC_PER_SEC) return false; + #if defined(__wasip1__) || defined(__wasip2__) // Timestamps before the Epoch are not supported. if (timespec->tv_sec < 0) return false; + #endif #if defined(__wasip1__) // Make sure our timestamp does not overflow. return !__builtin_mul_overflow(timespec->tv_sec, NSEC_PER_SEC, timestamp) && !__builtin_add_overflow(*timestamp, timespec->tv_nsec, timestamp); -#elif defined(__wasip2__) || defined(__wasip3__) +#elif defined(__wasip2__) | defined(__wasip3__) timestamp->seconds = timespec->tv_sec; timestamp->nanoseconds = timespec->tv_nsec; return true; @@ -65,7 +67,7 @@ static inline bool timespec_to_timestamp_clamp( // Make sure our timestamp does not overflow. *timestamp = NUMERIC_MAX(__wasi_timestamp_t); } -#elif defined(__wasip2__) || defined(__wasip3__) +#elif defined(__wasip2__) if (timespec->tv_sec < 0) { // Timestamps before the Epoch are not supported. timestamp->seconds = 0; @@ -74,6 +76,9 @@ static inline bool timespec_to_timestamp_clamp( timestamp->seconds = timespec->tv_sec; timestamp->nanoseconds = timespec->tv_nsec; } +#elif defined(__wasip3__) + timestamp->seconds = timespec->tv_sec; + timestamp->nanoseconds = timespec->tv_nsec; #else # error "Unknown WASI version" #endif @@ -99,6 +104,12 @@ static inline struct timeval timestamp_to_timeval( static inline struct timespec timestamp_to_timespec( wasilibc_timestamp_t *timestamp) { +#if defined(__wasip2__) + // Check for overflow when converting unsigned to signed + if (timestamp->seconds > INT64_MAX) { + return (struct timespec){.tv_sec = INT64_MAX, .tv_nsec = NSEC_PER_SEC - 1}; + } +#endif return (struct timespec){.tv_sec = timestamp->seconds, .tv_nsec = timestamp->nanoseconds}; } @@ -159,6 +170,12 @@ static inline bool timeval_to_duration( static inline struct timeval timestamp_to_timeval( wasilibc_timestamp_t *timestamp) { + #if defined(__wasip2__) + // Check for overflow when converting unsigned to signed + if (timestamp->seconds > INT64_MAX) { + return (struct timeval){.tv_sec = INT64_MAX, .tv_usec = USEC_PER_SEC - 1}; + } + #endif return (struct timeval){.tv_sec = timestamp->seconds, .tv_usec = timestamp->nanoseconds / 1000}; } From 772668a55898d5b882fc5a24f53260a8f553bd21 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Fri, 16 Jan 2026 10:37:56 +0000 Subject: [PATCH 38/41] More CMake and clocks fixes --- cmake/ba-download.cmake | 30 ++++++++----------- cmake/bindings.cmake | 17 ++++++----- .../src/libc/sys/time/gettimeofday.c | 4 +-- .../cloudlibc/src/libc/time/clock_gettime.c | 2 +- .../cloudlibc/src/libc/time/time.c | 4 +-- .../headers/public/wasi/__generated_wasip3.h | 12 ++++---- libc-bottom-half/sources/wasip3.c | 14 ++++----- 7 files changed, 40 insertions(+), 43 deletions(-) diff --git a/cmake/ba-download.cmake b/cmake/ba-download.cmake index 7e35fb298..789d638f7 100644 --- a/cmake/ba-download.cmake +++ b/cmake/ba-download.cmake @@ -57,25 +57,21 @@ function(ba_download target repo version) if (target STREQUAL wkg) # wkg ships a single binary rather than an archive - set(download_path "${CMAKE_CURRENT_BINARY_DIR}/${target}") - set(url "${repo}/releases/download/${tag}/${target}-${arch}-${os}") - - if (NOT EXISTS "${download_path}") - message(STATUS "Downloading ${target} from ${url}") - file(DOWNLOAD "${url}" "${download_path}" STATUS download_status) - list(GET download_status 0 status_code) - if (NOT status_code EQUAL 0) - list(GET download_status 1 error_message) - message(FATAL_ERROR "Failed to download ${target}: ${error_message}") - endif() - - if (NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - execute_process(COMMAND chmod +x "${download_path}") - endif() + if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + set(chmod_cmd "") + else() + set(chmod_cmd COMMAND chmod +x ) endif() - add_custom_target(${target}) - set(${target}_bin "${download_path}" PARENT_SCOPE) + ExternalProject_Add( + ${target} + EXCLUDE_FROM_ALL ON + URL "${repo}/releases/download/${tag}/${target}-${arch}-${os}" + DOWNLOAD_NO_EXTRACT ON + CONFIGURE_COMMAND "" + BUILD_COMMAND ${chmod_cmd} + INSTALL_COMMAND "" + ) else() ExternalProject_Add( ${target} diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index e82a0b77b..40909288d 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -61,7 +61,8 @@ if (NOT WKG_EXECUTABLE) "https://github.com/bytecodealliance/wasm-pkg-tools" "0.13.0" ) - # wkg_bin is set by ba_download + ExternalProject_Get_Property(wkg DOWNLOADED_FILE) + set(wkg_bin ${DOWNLOADED_FILE}) else() add_custom_target(wkg) set(wkg_bin ${WKG_EXECUTABLE}) @@ -148,7 +149,7 @@ add_custom_target( --type-section-suffix __wasi_libc --world wasi:cli/imports@${wasip3-version} --rename wasi:clocks/monotonic-clock@${wasip3-version}=monotonic_clock - --rename wasi:clocks/wall-clock@${wasip3-version}=wall_clock + --rename wasi:clocks/system-clock@${wasip3-version}=system_clock --rename wasi:filesystem/preopens@${wasip3-version}=filesystem_preopens --rename wasi:filesystem/types@${wasip3-version}=filesystem --rename wasi:random/insecure-seed@${wasip3-version}=random_insecure_seed @@ -175,18 +176,18 @@ add_custom_target( add_custom_target(bindings DEPENDS bindings-p2 bindings-p3) -if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") - set(SED_INPLACE_FLAG "''") +if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + set(SED_INPLACE_ARGS -i '') else() - set(SED_INPLACE_FLAG "") + set(SED_INPLACE_ARGS -i) endif() function(wit_bindgen_edit p) add_custom_target( bindings-${p}-edit - COMMAND sed -i ${SED_INPLACE_FLAG} "'s_#include .wasi${p}\.h._#include \"wasi/wasi${p}.h\"_'" ${bottom_half}/sources/wasi${p}.c - COMMAND sed -i ${SED_INPLACE_FLAG} "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/__generated_wasi${p}.h - COMMAND sed -i ${SED_INPLACE_FLAG} "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasi${p}.c + COMMAND sed ${SED_INPLACE_ARGS} "'s_#include .wasi${p}\.h._#include \"wasi/wasi${p}.h\"_'" ${bottom_half}/sources/wasi${p}.c + COMMAND sed ${SED_INPLACE_ARGS} "s/extern void exit_exit/_Noreturn extern void exit_exit/" ${bottom_half}/headers/public/wasi/__generated_wasi${p}.h + COMMAND sed ${SED_INPLACE_ARGS} "s/extern void __wasm_import_exit_exit/_Noreturn extern void __wasm_import_exit_exit/" ${bottom_half}/sources/wasi${p}.c DEPENDS bindings-${p} ) add_dependencies(bindings bindings-${p}-edit) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c b/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c index 3c27aa93a..97801a666 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c @@ -17,8 +17,8 @@ int gettimeofday(struct timeval *restrict tp, void *tz) { wall_clock_now(&time_result); *tp = timestamp_to_timeval(&time_result); #elif defined(__wasip3__) - wasi_clocks_system_clock_instant_t time_result; - wasi_clocks_system_clock_now(&time_result); + system_clock_instant_t time_result; + system_clock_now(&time_result); *tp = timestamp_to_timeval(&time_result); #else # error "Unsupported WASI version" diff --git a/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c b/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c index ae8eef0fe..48445bdec 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c @@ -29,7 +29,7 @@ int __clock_gettime(clockid_t clock_id, struct timespec *tp) { #ifdef __wasip2__ wall_clock_now(&time_result); #else - wasi_clocks_system_clock_now(&time_result); + system_clock_now(&time_result); #endif *tp = timestamp_to_timespec(&time_result); } else { diff --git a/libc-bottom-half/cloudlibc/src/libc/time/time.c b/libc-bottom-half/cloudlibc/src/libc/time/time.c index d3fceb5c2..fbdb4b602 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/time.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/time.c @@ -16,8 +16,8 @@ time_t time(time_t *tloc) { uint64_t ts = (res.seconds * NSEC_PER_SEC) + res.nanoseconds; #elif defined(__wasip3__) wasilibc_timestamp_t res; - wasi_clocks_system_clock_now(&res); - uint64_t ts = (res.seconds * NSEC_PER_SEC) + res.nanoseconds; + system_clock_now(&res); + time_t ts = (res.seconds * NSEC_PER_SEC) + res.nanoseconds; #else # error "Unsupported WASI version" #endif diff --git a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h index 232b69b8c..f9f04db25 100644 --- a/libc-bottom-half/headers/public/wasi/__generated_wasip3.h +++ b/libc-bottom-half/headers/public/wasi/__generated_wasip3.h @@ -197,7 +197,7 @@ typedef wasi_clocks_types_duration_t monotonic_clock_duration_t; // the same monotonic-clock. typedef uint64_t monotonic_clock_mark_t; -typedef wasi_clocks_types_duration_t wasi_clocks_system_clock_duration_t; +typedef wasi_clocks_types_duration_t system_clock_duration_t; // An "instant", or "exact time", is a point in time without regard to any // time zone: just the time since a particular external reference point, @@ -215,12 +215,12 @@ typedef wasi_clocks_types_duration_t wasi_clocks_system_clock_duration_t; // // [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 // [Unix Time]: https://en.wikipedia.org/wiki/Unix_time -typedef struct wasi_clocks_system_clock_instant_t { +typedef struct system_clock_instant_t { int64_t seconds; uint32_t nanoseconds; -} wasi_clocks_system_clock_instant_t; +} system_clock_instant_t; -typedef wasi_clocks_system_clock_instant_t filesystem_instant_t; +typedef system_clock_instant_t filesystem_instant_t; // File size or length of a region within a file. typedef uint64_t filesystem_filesize_t; @@ -1009,10 +1009,10 @@ extern wasip3_subtask_status_t monotonic_clock_wait_for(monotonic_clock_duration // will not necessarily produce a sequence of non-decreasing values. // // The nanoseconds field of the output is always less than 1000000000. -extern void wasi_clocks_system_clock_now(wasi_clocks_system_clock_instant_t *ret); +extern void system_clock_now(system_clock_instant_t *ret); // Query the resolution of the clock. Returns the smallest duration of time // that the implementation permits distinguishing. -extern wasi_clocks_system_clock_duration_t wasi_clocks_system_clock_get_resolution(void); +extern system_clock_duration_t system_clock_get_resolution(void); // Imported Functions from `wasi:filesystem/types@0.3.0-rc-2026-01-06` // Return a stream for reading from a file. diff --git a/libc-bottom-half/sources/wasip3.c b/libc-bottom-half/sources/wasip3.c index f37ac874f..26b92a86a 100644 --- a/libc-bottom-half/sources/wasip3.c +++ b/libc-bottom-half/sources/wasip3.c @@ -66,10 +66,10 @@ extern int32_t __wasm_import_monotonic_clock_wait_for(int64_t); // Imported Functions from `wasi:clocks/system-clock@0.3.0-rc-2026-01-06` __attribute__((__import_module__("wasi:clocks/system-clock@0.3.0-rc-2026-01-06"), __import_name__("now"))) -extern void __wasm_import_wasi_clocks_system_clock_now(uint8_t *); +extern void __wasm_import_system_clock_now(uint8_t *); __attribute__((__import_module__("wasi:clocks/system-clock@0.3.0-rc-2026-01-06"), __import_name__("get-resolution"))) -extern int64_t __wasm_import_wasi_clocks_system_clock_get_resolution(void); +extern int64_t __wasm_import_system_clock_get_resolution(void); // Imported Functions from `wasi:filesystem/types@0.3.0-rc-2026-01-06` @@ -1292,19 +1292,19 @@ wasip3_subtask_status_t monotonic_clock_wait_for(monotonic_clock_duration_t how_ return __wasm_import_monotonic_clock_wait_for((int64_t) (how_long)); } -void wasi_clocks_system_clock_now(wasi_clocks_system_clock_instant_t *ret) { +void system_clock_now(system_clock_instant_t *ret) { __attribute__((__aligned__(8))) uint8_t ret_area[16]; uint8_t *ptr = (uint8_t *) &ret_area; - __wasm_import_wasi_clocks_system_clock_now(ptr); - *ret = (wasi_clocks_system_clock_instant_t) { + __wasm_import_system_clock_now(ptr); + *ret = (system_clock_instant_t) { (int64_t) *((int64_t*) (ptr + 0)), (uint32_t) (uint32_t) (*((int32_t*) (ptr + 8))), }; } -wasi_clocks_system_clock_duration_t wasi_clocks_system_clock_get_resolution(void) { - int64_t ret = __wasm_import_wasi_clocks_system_clock_get_resolution(); +system_clock_duration_t system_clock_get_resolution(void) { + int64_t ret = __wasm_import_system_clock_get_resolution(); return (uint64_t) (ret); } From 11c49eae863326c75c7b7aba52e4d4ca6462ad00 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Fri, 16 Jan 2026 10:45:08 +0000 Subject: [PATCH 39/41] Try to fix windows --- cmake/ba-download.cmake | 4 ++-- cmake/bindings.cmake | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cmake/ba-download.cmake b/cmake/ba-download.cmake index 789d638f7..c1591932b 100644 --- a/cmake/ba-download.cmake +++ b/cmake/ba-download.cmake @@ -58,9 +58,9 @@ function(ba_download target repo version) if (target STREQUAL wkg) # wkg ships a single binary rather than an archive if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - set(chmod_cmd "") + set(chmod_cmd ${CMAKE_COMMAND} -E true) else() - set(chmod_cmd COMMAND chmod +x ) + set(chmod_cmd chmod +x ) endif() ExternalProject_Add( diff --git a/cmake/bindings.cmake b/cmake/bindings.cmake index 40909288d..0ddec3d59 100644 --- a/cmake/bindings.cmake +++ b/cmake/bindings.cmake @@ -77,6 +77,7 @@ configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip2.wit.in ${wasip2_wit_dir set(wasip2_stamp ${CMAKE_CURRENT_BINARY_DIR}/wasi/p2/.wit-fetch-stamp) add_custom_command( OUTPUT ${wasip2_stamp} + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/wasi/p2 COMMAND ${wkg_bin} wit fetch COMMAND ${CMAKE_COMMAND} -E touch ${wasip2_stamp} WORKING_DIRECTORY ${wasip2_wit_dir}/.. @@ -133,6 +134,7 @@ configure_file(${CMAKE_SOURCE_DIR}/wasi/wasi-libc-wasip3.wit.in ${wasip3_wit_dir set(wasip3_stamp ${CMAKE_CURRENT_BINARY_DIR}/wasi/p3/.wit-fetch-stamp) add_custom_command( OUTPUT ${wasip3_stamp} + COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/wasi/p3 COMMAND ${wkg_bin} wit fetch COMMAND ${CMAKE_COMMAND} -E touch ${wasip3_stamp} WORKING_DIRECTORY ${wasip3_wit_dir}/.. From e70507c9bf7b97bd56584e436c37386dfee62e14 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Fri, 16 Jan 2026 11:01:20 +0000 Subject: [PATCH 40/41] Another try at fixing windows --- cmake/ba-download.cmake | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmake/ba-download.cmake b/cmake/ba-download.cmake index c1591932b..2baba8337 100644 --- a/cmake/ba-download.cmake +++ b/cmake/ba-download.cmake @@ -58,20 +58,30 @@ function(ba_download target repo version) if (target STREQUAL wkg) # wkg ships a single binary rather than an archive if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") - set(chmod_cmd ${CMAKE_COMMAND} -E true) + set(download_name "${target}-${arch}-${os}.exe") else() - set(chmod_cmd chmod +x ) + set(download_name "${target}-${arch}-${os}") endif() - ExternalProject_Add( ${target} EXCLUDE_FROM_ALL ON URL "${repo}/releases/download/${tag}/${target}-${arch}-${os}" DOWNLOAD_NO_EXTRACT ON + DOWNLOAD_NAME ${download_name} CONFIGURE_COMMAND "" - BUILD_COMMAND ${chmod_cmd} + BUILD_COMMAND "" INSTALL_COMMAND "" ) + + # Make the binary executable on Unix-like systems + if (NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") + ExternalProject_Add_Step( + ${target} chmod-executable + COMMAND chmod +x + DEPENDEES download + DEPENDERS build + ) + endif() else() ExternalProject_Add( ${target} From ff9c6a365179711799ad904f48c7c8212b07c073 Mon Sep 17 00:00:00 2001 From: Sy Brand Date: Fri, 16 Jan 2026 15:21:53 +0000 Subject: [PATCH 41/41] More pthreads --- libc-top-half/musl/src/env/__init_tls.c | 5 ++++- libc-top-half/musl/src/thread/pthread_join.c | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/libc-top-half/musl/src/env/__init_tls.c b/libc-top-half/musl/src/env/__init_tls.c index 46c0cfa47..10566f5c6 100644 --- a/libc-top-half/musl/src/env/__init_tls.c +++ b/libc-top-half/musl/src/env/__init_tls.c @@ -113,7 +113,10 @@ int __init_tp(void *p) td->stack = bounds.base; td->stack_size = bounds.size; td->guard_size = 0; -#ifdef _REENTRANT +#if defined(__wasip3__) + td->detach_state = DT_JOINABLE; + td->tid = wasip3_thread_index(); +#elif defined(_REENTRANT) td->detach_state = DT_JOINABLE; /* * Initialize the TID to a value which doesn't conflict with diff --git a/libc-top-half/musl/src/thread/pthread_join.c b/libc-top-half/musl/src/thread/pthread_join.c index de194d8fa..65fe3d273 100644 --- a/libc-top-half/musl/src/thread/pthread_join.c +++ b/libc-top-half/musl/src/thread/pthread_join.c @@ -35,7 +35,7 @@ int __pthread_join(pthread_t t, void **res) { #ifdef __wasip3__ if (t->detach_state != DT_EXITED) { - t->joining_tid = __pthread_self()->tid; + t->joining_tid = wasip3_thread_index(); wasip3_thread_switch_to(t->tid); } if (res) *res = t->result;