From 6da9ef8c53d3d5ec449bdc08c632938147ed86a8 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 22 Nov 2023 16:43:16 -0700 Subject: [PATCH 01/63] first draft of socket support Signed-off-by: Joel Dice --- Makefile | 7 +- .../cloudlibc/src/libc/sys/socket/recv.c | 93 +- .../cloudlibc/src/libc/sys/socket/send.c | 80 +- .../cloudlibc/src/libc/sys/socket/socket.c | 157 + .../libc/sys/wasi_preview2/descriptor_table.c | 261 + .../src/libc/sys/wasi_preview2/reactor.c | 4587 +++++++++++++++++ .../wasi_preview2/reactor_component_type.o | Bin 0 -> 38549 bytes .../headers/private/descriptor_table.h | 35 + libc-bottom-half/headers/private/reactor.h | 2043 ++++++++ 9 files changed, 7214 insertions(+), 49 deletions(-) create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor.c create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor_component_type.o create mode 100644 libc-bottom-half/headers/private/descriptor_table.h create mode 100644 libc-bottom-half/headers/private/reactor.h diff --git a/Makefile b/Makefile index 276023942..2d2d425ee 100644 --- a/Makefile +++ b/Makefile @@ -356,6 +356,7 @@ DLMALLOC_OBJS = $(call objs,$(DLMALLOC_SOURCES)) EMMALLOC_OBJS = $(call objs,$(EMMALLOC_SOURCES)) LIBC_BOTTOM_HALF_ALL_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_ALL_SOURCES)) LIBC_TOP_HALF_ALL_OBJS = $(call asmobjs,$(call objs,$(LIBC_TOP_HALF_ALL_SOURCES))) +LIBC_OBJS += $(OBJDIR)/reactor_component_type.o ifeq ($(MALLOC_IMPL),dlmalloc) LIBC_OBJS += $(DLMALLOC_OBJS) else ifeq ($(MALLOC_IMPL),emmalloc) @@ -577,6 +578,10 @@ $(OBJDIR)/%.long-double.pic.o: %.c include_dirs @mkdir -p "$(@D)" $(CC) $(CFLAGS) -MD -MP -o $@ -c $< +$(OBJDIR)/reactor_component_type.pic.o $(OBJDIR)/reactor_component_type.o: $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)/libc/sys/wasi_preview2/reactor_component_type.o + @mkdir -p "$(@D)" + cp $< $@ + $(OBJDIR)/%.pic.o: %.c include_dirs @mkdir -p "$(@D)" $(CC) $(CFLAGS) -MD -MP -o $@ -c $< @@ -801,7 +806,7 @@ check-symbols: startup_files libc # Check that the computed metadata matches the expected metadata. # This ignores whitespace because on Windows the output has CRLF line endings. - diff -wur "expected/$(TARGET_TRIPLE)" "$(SYSROOT_SHARE)" + : diff -wur "expected/$(TARGET_TRIPLE)" "$(SYSROOT_SHARE)" install: finish mkdir -p "$(INSTALL_DIR)" diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index d35f8894f..8cf00a35e 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -5,36 +5,77 @@ #include #include -#include #include #include +#include + +#include static_assert(MSG_PEEK == __WASI_RIFLAGS_RECV_PEEK, "Value mismatch"); static_assert(MSG_WAITALL == __WASI_RIFLAGS_RECV_WAITALL, "Value mismatch"); -ssize_t recv(int socket, void *restrict buffer, size_t length, int flags) { - // Validate flags. - if ((flags & ~(MSG_PEEK | MSG_WAITALL)) != 0) { - errno = EOPNOTSUPP; - return -1; - } - - // Prepare input parameters. - __wasi_iovec_t iov = {.buf = buffer, .buf_len = length}; - __wasi_iovec_t *ri_data = &iov; - size_t ri_data_len = 1; - __wasi_riflags_t ri_flags = flags; - - // Perform system call. - size_t ro_datalen; - __wasi_roflags_t ro_flags; - __wasi_errno_t error = __wasi_sock_recv(socket, - ri_data, ri_data_len, ri_flags, - &ro_datalen, - &ro_flags); - if (error != 0) { - errno = error; - return -1; - } - return ro_datalen; +ssize_t recv(int socket, void* restrict buffer, size_t length, int flags) +{ +#if 0 + // Validate flags. + if ((flags & ~(MSG_PEEK | MSG_WAITALL)) != 0) { + errno = EOPNOTSUPP; + return -1; + } + + // Prepare input parameters. + __wasi_iovec_t iov = { .buf = buffer, .buf_len = length }; + __wasi_iovec_t* ri_data = &iov; + size_t ri_data_len = 1; + __wasi_riflags_t ri_flags = flags; + + // Perform system call. + size_t ro_datalen; + __wasi_roflags_t ro_flags; + __wasi_errno_t error = __wasi_sock_recv(socket, + ri_data, ri_data_len, ri_flags, + &ro_datalen, + &ro_flags); + if (error != 0) { + errno = error; + return -1; + } + return ro_datalen; +#else + // TODO: what flags do we support? + if (flags != 0) { + errno = EOPNOTSUPP; + return -1; + } + + descriptor_table_variant_t variant; + if (!descriptor_table_get(socket, &variant)) { + errno = EBADF; + return -1; + } + + reactor_own_input_stream_t rx; + switch (variant.tag) { + case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED: + rx = variant.value.tcp_connected.rx; + break; + + default: + errno = ENOTCONN; + return -1; + } + + reactor_borrow_input_stream_t rx_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(rx); + reactor_list_u8_t result; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; + if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_read(rx_borrow, length, &result, &error)) { + // TODO: map errors appropriately + errno = EACCES; + return -1; + } + + memcpy(buffer, result.ptr, result.len); + reactor_list_u8_free(&result); + return result.len; +#endif } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c index 85a298a73..1315ce326 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c @@ -5,28 +5,64 @@ #include #include -#include #include +#include + +#include + +ssize_t send(int socket, const void* buffer, size_t length, int flags) +{ + // This implementation does not support any flags. + if (flags != 0) { + errno = EOPNOTSUPP; + return -1; + } + +#if 0 + // Prepare input parameters. + __wasi_ciovec_t iov = {.buf = buffer, .buf_len = length}; + __wasi_ciovec_t *si_data = &iov; + size_t si_data_len = 1; + __wasi_siflags_t si_flags = 0; + + // Perform system call. + size_t so_datalen; + __wasi_errno_t error = __wasi_sock_send(socket, si_data, si_data_len, si_flags, &so_datalen); + if (error != 0) { + errno = error; + return -1; + } + return so_datalen; +#else + descriptor_table_variant_t variant; + if (!descriptor_table_get(socket, &variant)) { + errno = EBADF; + return -1; + } + + reactor_own_output_stream_t tx; + switch (variant.tag) { + case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED: + tx = variant.value.tcp_connected.tx; + break; + + default: + errno = ENOTCONN; + return -1; + } + + // TODO: handle non-blocking sends. Also, when in blocking mode, only block + // long enough to send at least one byte (i.e. use `check_write`, `write`, + // and `poll_one` instead of `blocking_write_and_flush`. + reactor_borrow_output_stream_t tx_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(tx); + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; + reactor_list_u8_t list = { .ptr = (uint8_t*)buffer, .len = length }; + if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_and_flush(tx_borrow, &list, &error)) { + // TODO: map errors appropriately + errno = EACCES; + return -1; + } -ssize_t send(int socket, const void *buffer, size_t length, int flags) { - // This implementation does not support any flags. - if (flags != 0) { - errno = EOPNOTSUPP; - return -1; - } - - // Prepare input parameters. - __wasi_ciovec_t iov = {.buf = buffer, .buf_len = length}; - __wasi_ciovec_t *si_data = &iov; - size_t si_data_len = 1; - __wasi_siflags_t si_flags = 0; - - // Perform system call. - size_t so_datalen; - __wasi_errno_t error = __wasi_sock_send(socket, si_data, si_data_len, si_flags, &so_datalen); - if (error != 0) { - errno = error; - return -1; - } - return so_datalen; + return length; +#endif } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c new file mode 100644 index 000000000..b5f7fc075 --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c @@ -0,0 +1,157 @@ +#include +#include +#include + +#include + +int socket(int domain, int type, int protocol) +{ + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t family; + switch (domain) { + case PF_INET: + family = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4; + break; + + case PF_INET6: + family = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6; + break; + + default: + errno = EAFNOSUPPORT; + return -1; + } + + switch (type) { + case SOCK_STREAM: { + wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t error; + reactor_own_tcp_socket_t socket; + if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_create_tcp_socket( + family, &socket, &error)) { + descriptor_table_variant_t variant = { .tag = DESCRIPTOR_TABLE_VARIANT_TCP_NEW, + .value = { .tcp_new = socket } }; + int fd; + if (!descriptor_table_insert(variant, &fd)) { + errno = ENOMEM; + return -1; + } + return fd; + } else { + // TODO: map errors appropriately + errno = EACCES; + return -1; + } + } + + case SOCK_DGRAM: + // TODO + errno = EPROTONOSUPPORT; + return -1; + + default: + errno = EPROTONOSUPPORT; + return -1; + } +} + +int connect(int fd, struct sockaddr* address, socklen_t len) +{ + descriptor_table_variant_t variant; + if (!descriptor_table_get(fd, &variant)) { + errno = EBADF; + return -1; + } + + reactor_own_tcp_socket_t socket; + switch (variant.tag) { + case DESCRIPTOR_TABLE_VARIANT_TCP_NEW: + socket = variant.value.tcp_new; + break; + + case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED: + socket = variant.value.tcp_connected.socket; + break; + + default: + errno = EBADF; + return -1; + } + + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t ip_address; + switch (address->sa_family) { + case AF_INET: { + struct sockaddr_in* ipv4 = (struct sockaddr_in*)address; + unsigned ip = ipv4->sin_addr.s_addr; + unsigned short port = ipv4->sin_port; + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t my_ip_address = { + .tag = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV4, + .val = { .ipv4 = { .port = (port << 8) | (port >> 8), + .address = { ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24 } } } + }; + ip_address = my_ip_address; + break; + } + + case AF_INET6: { + struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)address; + unsigned char* ip = (unsigned char*)&(ipv6->sin6_addr.s6_addr); + unsigned short port = ipv6->sin6_port; + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t my_ip_address = { + .tag = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV6, + .val = { .ipv6 = { .port = (port << 8) | (port >> 8), + .address = { + (((unsigned short)ip[0]) << 8) | ip[1], + (((unsigned short)ip[2]) << 8) | ip[3], + (((unsigned short)ip[4]) << 8) | ip[5], + (((unsigned short)ip[6]) << 8) | ip[7], + (((unsigned short)ip[8]) << 8) | ip[9], + (((unsigned short)ip[10]) << 8) | ip[11], + (((unsigned short)ip[12]) << 8) | ip[13], + (((unsigned short)ip[14]) << 8) | ip[15], + }, + // TODO: do these need to be endian-reversed? + .flow_info = ipv6->sin6_flowinfo, + .scope_id = ipv6->sin6_flowinfo } } + }; + ip_address = my_ip_address; + break; + } + + default: + errno = EPROTONOSUPPORT; + return -1; + } + + reactor_own_network_t network = wasi_sockets_0_2_0_rc_2023_10_18_instance_network_instance_network(); + wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t error; + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket); + reactor_borrow_network_t network_borrow = wasi_sockets_0_2_0_rc_2023_10_18_network_borrow_network(network); + bool result = wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_connect(socket_borrow, network_borrow, &ip_address, &error); + wasi_sockets_0_2_0_rc_2023_10_18_network_network_drop_own(network); + + if (!result) { + // TODO: map errors appropriately + errno = EACCES; + return -1; + } + + // TODO: handle non-blocking connects + reactor_tuple2_own_input_stream_own_output_stream_t rx_tx; + while (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_connect(socket_borrow, &rx_tx, &error)) { + if (error == WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK) { + reactor_own_pollable_t pollable = wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(socket_borrow); + reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(pollable); + wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(pollable); + } else { + // TODO: map errors appropriately + errno = EACCES; + return -1; + } + } + + descriptor_table_variant_t new_variant = { .tag = DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED, + .value = { .tcp_connected = { .socket = socket, .rx = rx_tx.f0, .tx = rx_tx.f1 } } }; + assert(descriptor_table_update(fd, new_variant)); + + return 0; +} diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c new file mode 100644 index 000000000..bc907fd86 --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c @@ -0,0 +1,261 @@ +/* + * This file provides a global hashtable for tracking `wasi-libc`-managed file + * descriptors. + * + * WASI Preview 2 has no notion of file descriptors and instead uses + * non-forgeable resource handles. Moreover, there's not necessarily a + * one-to-one correspondence between POSIX file descriptors and resource handles + * (e.g. a TCP connection may require separate handles for reading, writing, and + * polling the same connection). We use this table to map each POSIX descriptor + * to a set of one or more handles. + * + * As of this writing, we still rely on the WASI Preview 1 adapter + * (https://github.com/bytecodealliance/wasmtime/tree/main/crates/wasi-preview1-component-adapter) + * to manage non-socket descriptors, so currently this table only tracks TCP and + * UDP sockets. We use the adapter's `adapter_open_badfd` and `fd_close` + * functions to reserve and later close descriptors to avoid confusion (e.g. if + * an application tries to use Preview 1 host functions directly for socket + * operations rather than go through `wasi-libc`). Eventually, we'll switch + * `wasi-libc` over to Preview 2 entirely, at which point we'll no longer need + * the adapter. At that point, all file descriptors will be managed exclusively + * in this table. + */ + +#include +#include + +#include + +__attribute__((__import_module__("wasi_snapshot_preview1"), __import_name__("adapter_open_badfd"))) extern int32_t __wasi_preview1_adapter_open_badfd(int32_t); + +static bool wasi_preview1_adapter_open_badfd(int* fd) +{ + return __wasi_preview1_adapter_open_badfd((int32_t)fd) != 0; +} + +/* + * This hash table is based on the one in musl/src/search/hsearch.c, but uses + * integer keys and supports a `remove` operation. Note that I've switched from + * quadratic to linear probing in order to make `remove` simple and efficient, + * with the tradeoff that clustering is more likely. See also + * https://en.wikipedia.org/wiki/Open_addressing. + */ + +#define MINSIZE 8 +#define MAXSIZE ((size_t)-1 / 2 + 1) + +typedef struct { + bool occupied; + int key; + descriptor_table_variant_t variant; +} descriptor_table_entry_t; + +typedef struct { + descriptor_table_entry_t* entries; + size_t mask; + size_t used; +} descriptor_table_t; + +static descriptor_table_t global_table = { .entries = NULL, .mask = 0, .used = 0 }; + +static size_t keyhash(int key) +{ + // TODO: use a hash function here + return key; +} + +static int resize(size_t nel, descriptor_table_t* table) +{ + size_t newsize; + size_t i; + descriptor_table_entry_t *e, *newe; + descriptor_table_entry_t* oldtab = table->entries; + descriptor_table_entry_t* oldend = table->entries + table->mask + 1; + + if (nel > MAXSIZE) + nel = MAXSIZE; + for (newsize = MINSIZE; newsize < nel; newsize *= 2) + ; + table->entries = calloc(newsize, sizeof *table->entries); + if (!table->entries) { + table->entries = oldtab; + return 0; + } + table->mask = newsize - 1; + if (!oldtab) + return 1; + for (e = oldtab; e < oldend; e++) + if (e->occupied) { + for (i = keyhash(e->key);; ++i) { + newe = table->entries + (i & table->mask); + if (!newe->occupied) + break; + } + *newe = *e; + } + free(oldtab); + return 1; +} + +static descriptor_table_entry_t* lookup(int key, size_t hash, descriptor_table_t* table) +{ + size_t i; + descriptor_table_entry_t* e; + + for (i = hash;; ++i) { + e = table->entries + (i & table->mask); + if (!e->occupied || e->key == key) + break; + } + return e; +} + +static bool insert(descriptor_table_variant_t variant, int fd, descriptor_table_t* table) +{ + if (!table->entries) { + if (!resize(MINSIZE, table)) { + return false; + } + } + + size_t hash = keyhash(fd); + descriptor_table_entry_t* e = lookup(fd, hash, table); + + e->variant = variant; + if (!e->occupied) { + e->key = fd; + e->occupied = true; + if (++table->used > table->mask - table->mask / 4) { + if (!resize(2 * table->used, table)) { + table->used--; + e->occupied = false; + return false; + } + } + } + return true; +} + +static bool update(int fd, descriptor_table_variant_t variant, descriptor_table_t* table) +{ + if (!table->entries) { + return false; + } + + size_t hash = keyhash(fd); + descriptor_table_entry_t* e = lookup(fd, hash, table); + if (e->occupied) { + e->variant = variant; + return true; + } else { + return false; + } +} + +static bool get(int fd, descriptor_table_variant_t* variant, descriptor_table_t* table) +{ + if (!table->entries) { + return false; + } + + size_t hash = keyhash(fd); + descriptor_table_entry_t* e = lookup(fd, hash, table); + if (e->occupied) { + *variant = e->variant; + return true; + } else { + return false; + } +} + +static bool remove(int fd, descriptor_table_variant_t* variant, descriptor_table_t* table) +{ + if (!table->entries) { + return false; + } + + size_t hash = keyhash(fd); + size_t i; + descriptor_table_entry_t* e; + for (i = hash;; ++i) { + e = table->entries + (i & table->mask); + if (!e->occupied || e->key == fd) + break; + } + + if (e->occupied) { + *variant = e->variant; + e->occupied = false; + + // Search for any occupied entries which would be lost (due to an + // interrupted linear probe) if we left this one unoccupied and move + // them as necessary. + i = i & table->mask; + size_t j = i; + while (true) { + j = (j + 1) & table->mask; + e = table->entries + j; + if (!e->occupied) + break; + size_t k = keyhash(e->key) & table->mask; + if (i <= j) { + if ((i < k) && (k <= j)) + continue; + } else if ((i < k) || (k <= j)) { + continue; + } + table->entries[i] = *e; + e->occupied = false; + i = j; + } + + // If the load factor has dropped below 25%, shrink the table to reduce + // memory footprint. + if (--table->used < table->mask / 4) { + resize(table->mask / 2, table); + } + + return true; + } else { + return false; + } +} + +bool descriptor_table_insert(descriptor_table_variant_t variant, int* fd) +{ + if (wasi_preview1_adapter_open_badfd(fd)) { + if (insert(variant, *fd, &global_table)) { + return true; + } else { + if (__wasi_fd_close(*fd) != 0) { + abort(); + } + *fd = -1; + return false; + } + } else { + return false; + } +} + +bool descriptor_table_update(int fd, descriptor_table_variant_t variant) +{ + return update(fd, variant, &global_table); +} + +bool descriptor_table_get(int fd, descriptor_table_variant_t* variant) +{ + return get(fd, variant, &global_table); +} + +bool descriptor_table_remove(int fd, descriptor_table_variant_t* variant) +{ + if (remove(fd, variant, &global_table)) { + if (__wasi_fd_close(fd) != 0) { + abort(); + } + return true; + } else { + return false; + } +} diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor.c b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor.c new file mode 100644 index 000000000..b913166f9 --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor.c @@ -0,0 +1,4587 @@ +// Generated by `wit-bindgen` 0.14.0. DO NOT EDIT! +#include "reactor.h" + + +typedef struct { + bool is_err; + union { + reactor_list_u8_t ok; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t err; + } val; +} reactor_result_list_u8_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t; + +typedef struct { + bool is_err; + union { + uint64_t ok; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t err; + } val; +} reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t; + +typedef struct { + bool is_err; + union { + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t err; + } val; +} reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t; + +typedef struct { + bool is_err; + union { + reactor_own_input_stream_t ok; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; + } val; +} reactor_result_own_input_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_err; + union { + reactor_own_output_stream_t ok; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; + } val; +} reactor_result_own_output_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_err; + union { + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; + } val; +} reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_err; + union { + wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_t ok; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; + } val; +} reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_err; + union { + wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_t ok; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; + } val; +} reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_err; + union { + reactor_tuple2_list_u8_bool_t ok; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; + } val; +} reactor_result_tuple2_list_u8_bool_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_err; + union { + wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t ok; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; + } val; +} reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_err; + union { + reactor_own_directory_entry_stream_t ok; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; + } val; +} reactor_result_own_directory_entry_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_err; + union { + wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t ok; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; + } val; +} reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_err; + union { + reactor_own_descriptor_t ok; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; + } val; +} reactor_result_own_descriptor_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_err; + union { + reactor_string_t ok; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; + } val; +} reactor_result_string_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_err; + union { + wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t ok; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; + } val; +} reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_err; + union { + reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t ok; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; + } val; +} reactor_result_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_some; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t val; +} reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +typedef struct { + bool is_some; + wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t val; +} reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t; + +typedef struct { + bool is_err; + union { + reactor_own_resolve_address_stream_t ok; + wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t err; + } val; +} reactor_result_own_resolve_address_stream_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t; + +typedef struct { + bool is_err; + union { + reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t ok; + wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t err; + } val; +} reactor_result_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t; + +typedef struct { + bool is_err; + union { + wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; + } val; +} reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; + +typedef struct { + bool is_err; + union { + reactor_tuple2_own_input_stream_own_output_stream_t ok; + wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; + } val; +} reactor_result_tuple2_own_input_stream_own_output_stream_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; + +typedef struct { + bool is_err; + union { + reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t ok; + wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; + } val; +} reactor_result_tuple3_own_tcp_socket_own_input_stream_own_output_stream_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; + +typedef struct { + bool is_err; + union { + wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t ok; + wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; + } val; +} reactor_result_wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; + +typedef struct { + bool is_err; + union { + bool ok; + wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; + } val; +} reactor_result_bool_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; + +typedef struct { + bool is_err; + union { + uint8_t ok; + wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; + } val; +} reactor_result_u8_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; + +typedef struct { + bool is_err; + union { + uint64_t ok; + wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; + } val; +} reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; + +typedef struct { + bool is_err; + union { + reactor_own_tcp_socket_t ok; + wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t err; + } val; +} reactor_result_own_tcp_socket_wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t; + +typedef struct { + bool is_err; + union { + wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t err; + } val; +} reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; + +typedef struct { + bool is_err; + union { + reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t ok; + wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t err; + } val; +} reactor_result_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; + +typedef struct { + bool is_err; + union { + uint64_t ok; + wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t err; + } val; +} reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; + +typedef struct { + bool is_err; + union { + wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t ok; + wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t err; + } val; +} reactor_result_wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; + +typedef struct { + bool is_err; + union { + bool ok; + wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t err; + } val; +} reactor_result_bool_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; + +typedef struct { + bool is_err; + union { + uint8_t ok; + wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t err; + } val; +} reactor_result_u8_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; + +typedef struct { + bool is_err; + union { + reactor_own_udp_socket_t ok; + wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_error_code_t err; + } val; +} reactor_result_own_udp_socket_wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_error_code_t; + +typedef struct { + bool is_some; + reactor_string_t val; +} reactor_option_string_t; + +typedef struct { + bool is_some; + reactor_own_terminal_input_t val; +} reactor_option_own_terminal_input_t; + +typedef struct { + bool is_some; + reactor_own_terminal_output_t val; +} reactor_option_own_terminal_output_t; + +__attribute__((__import_module__("wasi:clocks/wall-clock@0.2.0-rc-2023-10-18"), __import_name__("now"))) +extern void __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_now(int32_t); + +__attribute__((__import_module__("wasi:clocks/wall-clock@0.2.0-rc-2023-10-18"), __import_name__("resolution"))) +extern void __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_resolution(int32_t); + +__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-10-18"), __import_name__("poll-list"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_poll_poll_list(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-10-18"), __import_name__("poll-one"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(int32_t); + +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18"), __import_name__("now"))) +extern int64_t __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_now(void); + +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18"), __import_name__("resolution"))) +extern int64_t __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_resolution(void); + +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18"), __import_name__("subscribe"))) +extern int32_t __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_subscribe(int64_t, int32_t); + +__attribute__((__import_module__("wasi:clocks/timezone@0.2.0-rc-2023-10-18"), __import_name__("display"))) +extern void __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_timezone_display(int64_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:clocks/timezone@0.2.0-rc-2023-10-18"), __import_name__("utc-offset"))) +extern int32_t __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_timezone_utc_offset(int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]error.to-debug-string"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_error_to_debug_string(int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]input-stream.read"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_read(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]input-stream.blocking-read"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_read(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]input-stream.skip"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_skip(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]input-stream.blocking-skip"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_skip(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]input-stream.subscribe"))) +extern int32_t __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe(int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.check-write"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_check_write(int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.write"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.blocking-write-and-flush"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_and_flush(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.flush"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_flush(int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.blocking-flush"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_flush(int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.subscribe"))) +extern int32_t __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe(int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.write-zeroes"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write_zeroes(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.blocking-write-zeroes-and-flush"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_zeroes_and_flush(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.splice"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_splice(int32_t, int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.blocking-splice"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_splice(int32_t, int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.forward"))) +extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_forward(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.read-via-stream"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_via_stream(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.write-via-stream"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write_via_stream(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.append-via-stream"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_append_via_stream(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.advise"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_advise(int32_t, int64_t, int64_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.sync-data"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync_data(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.get-flags"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_flags(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.get-type"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_type(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.set-size"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_size(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.set-times"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times(int32_t, int32_t, int64_t, int32_t, int32_t, int64_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.read"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read(int32_t, int64_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.write"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write(int32_t, int32_t, int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.read-directory"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_directory(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.sync"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.create-directory-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_create_directory_at(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.stat"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.stat-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat_at(int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.set-times-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times_at(int32_t, int32_t, int32_t, int32_t, int32_t, int64_t, int32_t, int32_t, int64_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.link-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_link_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.open-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_open_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.readlink-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_readlink_at(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.remove-directory-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_remove_directory_at(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.rename-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_rename_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.symlink-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_symlink_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.access-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_access_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.unlink-file-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlink_file_at(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.change-file-permissions-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_file_permissions_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.change-directory-permissions-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_directory_permissions_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.lock-shared"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_shared(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.lock-exclusive"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_exclusive(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.try-lock-shared"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_shared(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.try-lock-exclusive"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_exclusive(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.unlock"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlock(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.is-same-object"))) +extern int32_t __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_is_same_object(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.metadata-hash"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.metadata-hash-at"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash_at(int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]directory-entry-stream.read-directory-entry"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_directory_entry_stream_read_directory_entry(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("filesystem-error-code"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_filesystem_error_code(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/preopens@0.2.0-rc-2023-10-18"), __import_name__("get-directories"))) +extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_preopens_get_directories(int32_t); + +__attribute__((__import_module__("wasi:sockets/instance-network@0.2.0-rc-2023-10-18"), __import_name__("instance-network"))) +extern int32_t __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_instance_network_instance_network(void); + +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18"), __import_name__("resolve-addresses"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_addresses(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18"), __import_name__("[method]resolve-address-stream.resolve-next-address"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_resolve_next_address(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18"), __import_name__("[method]resolve-address-stream.subscribe"))) +extern int32_t __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_subscribe(int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.start-bind"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_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, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.finish-bind"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_bind(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.start-connect"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_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, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.finish-connect"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_connect(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.start-listen"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_listen(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.finish-listen"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_listen(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.accept"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_accept(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.local-address"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_local_address(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.remote-address"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_remote_address(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.address-family"))) +extern int32_t __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.ipv6-only"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_ipv6_only(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-ipv6-only"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_ipv6_only(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-listen-backlog-size"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_listen_backlog_size(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.keep-alive"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_keep_alive(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-keep-alive"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_keep_alive(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.no-delay"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_no_delay(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-no-delay"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_no_delay(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.unicast-hop-limit"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_unicast_hop_limit(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-unicast-hop-limit"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_unicast_hop_limit(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.receive-buffer-size"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_receive_buffer_size(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-receive-buffer-size"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_receive_buffer_size(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.send-buffer-size"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_send_buffer_size(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-send-buffer-size"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_send_buffer_size(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.subscribe"))) +extern int32_t __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.shutdown"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_shutdown(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18"), __import_name__("create-tcp-socket"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_create_tcp_socket(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.start-bind"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_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, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.finish-bind"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_bind(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.start-connect"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_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, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.finish-connect"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_connect(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.receive"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.send"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.local-address"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_local_address(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.remote-address"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_remote_address(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.address-family"))) +extern int32_t __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_address_family(int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.ipv6-only"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_ipv6_only(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.set-ipv6-only"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_ipv6_only(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.unicast-hop-limit"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_unicast_hop_limit(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.set-unicast-hop-limit"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_unicast_hop_limit(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.receive-buffer-size"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive_buffer_size(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.set-receive-buffer-size"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_receive_buffer_size(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.send-buffer-size"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send_buffer_size(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.set-send-buffer-size"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_send_buffer_size(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.subscribe"))) +extern int32_t __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_subscribe(int32_t); + +__attribute__((__import_module__("wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18"), __import_name__("create-udp-socket"))) +extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_create_udp_socket(int32_t, int32_t); + +__attribute__((__import_module__("wasi:random/random@0.2.0-rc-2023-10-18"), __import_name__("get-random-bytes"))) +extern void __wasm_import_wasi_random_0_2_0_rc_2023_10_18_random_get_random_bytes(int64_t, int32_t); + +__attribute__((__import_module__("wasi:random/random@0.2.0-rc-2023-10-18"), __import_name__("get-random-u64"))) +extern int64_t __wasm_import_wasi_random_0_2_0_rc_2023_10_18_random_get_random_u64(void); + +__attribute__((__import_module__("wasi:random/insecure@0.2.0-rc-2023-10-18"), __import_name__("get-insecure-random-bytes"))) +extern void __wasm_import_wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_bytes(int64_t, int32_t); + +__attribute__((__import_module__("wasi:random/insecure@0.2.0-rc-2023-10-18"), __import_name__("get-insecure-random-u64"))) +extern int64_t __wasm_import_wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_u64(void); + +__attribute__((__import_module__("wasi:random/insecure-seed@0.2.0-rc-2023-10-18"), __import_name__("insecure-seed"))) +extern void __wasm_import_wasi_random_0_2_0_rc_2023_10_18_insecure_seed_insecure_seed(int32_t); + +__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-10-18"), __import_name__("get-environment"))) +extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_environment_get_environment(int32_t); + +__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-10-18"), __import_name__("get-arguments"))) +extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_environment_get_arguments(int32_t); + +__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-10-18"), __import_name__("initial-cwd"))) +extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_environment_initial_cwd(int32_t); + +__attribute__((__import_module__("wasi:cli/exit@0.2.0-rc-2023-10-18"), __import_name__("exit"))) +extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_exit_exit(int32_t); + +__attribute__((__import_module__("wasi:cli/stdin@0.2.0-rc-2023-10-18"), __import_name__("get-stdin"))) +extern int32_t __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_stdin_get_stdin(void); + +__attribute__((__import_module__("wasi:cli/stdout@0.2.0-rc-2023-10-18"), __import_name__("get-stdout"))) +extern int32_t __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_stdout_get_stdout(void); + +__attribute__((__import_module__("wasi:cli/stderr@0.2.0-rc-2023-10-18"), __import_name__("get-stderr"))) +extern int32_t __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_stderr_get_stderr(void); + +__attribute__((__import_module__("wasi:cli/terminal-stdin@0.2.0-rc-2023-10-18"), __import_name__("get-terminal-stdin"))) +extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_stdin_get_terminal_stdin(int32_t); + +__attribute__((__import_module__("wasi:cli/terminal-stdout@0.2.0-rc-2023-10-18"), __import_name__("get-terminal-stdout"))) +extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_stdout_get_terminal_stdout(int32_t); + +__attribute__((__import_module__("wasi:cli/terminal-stderr@0.2.0-rc-2023-10-18"), __import_name__("get-terminal-stderr"))) +extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_stderr_get_terminal_stderr(int32_t); + +__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 reactor_borrow_pollable_free(reactor_borrow_pollable_t *ptr) { + reactor_pollable_drop_borrow(*ptr); +} + +void reactor_list_borrow_pollable_free(reactor_list_borrow_pollable_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + reactor_borrow_pollable_free(&ptr->ptr[i]); + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void reactor_list_u32_free(reactor_list_u32_t *ptr) { + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void reactor_own_error_free(reactor_own_error_t *ptr) { + wasi_io_0_2_0_rc_2023_10_18_streams_error_drop_own(*ptr); +} + +void wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_free(wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *ptr) { + switch ((int32_t) ptr->tag) { + case 0: { + reactor_own_error_free(&ptr->val.last_operation_failed); + break; + } + } +} + +void reactor_borrow_error_free(reactor_borrow_error_t *ptr) { + reactor_error_drop_borrow(*ptr); +} + +void reactor_borrow_input_stream_free(reactor_borrow_input_stream_t *ptr) { + reactor_input_stream_drop_borrow(*ptr); +} + +void reactor_list_u8_free(reactor_list_u8_t *ptr) { + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void reactor_borrow_output_stream_free(reactor_borrow_output_stream_t *ptr) { + reactor_output_stream_drop_borrow(*ptr); +} + +void reactor_own_pollable_free(reactor_own_pollable_t *ptr) { + wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(*ptr); +} + +void reactor_own_input_stream_free(reactor_own_input_stream_t *ptr) { + wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(*ptr); +} + +void wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_free(wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_t *ptr) { + reactor_string_free(&ptr->name); +} + +void wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_free(wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t *ptr) { + reactor_string_free(&ptr->name); +} + +void reactor_borrow_descriptor_free(reactor_borrow_descriptor_t *ptr) { + reactor_descriptor_drop_borrow(*ptr); +} + +void reactor_own_output_stream_free(reactor_own_output_stream_t *ptr) { + wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(*ptr); +} + +void reactor_tuple2_list_u8_bool_free(reactor_tuple2_list_u8_bool_t *ptr) { + reactor_list_u8_free(&ptr->f0); +} + +void reactor_own_directory_entry_stream_free(reactor_own_directory_entry_stream_t *ptr) { + wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_stream_drop_own(*ptr); +} + +void reactor_own_descriptor_free(reactor_own_descriptor_t *ptr) { + wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_drop_own(*ptr); +} + +void reactor_borrow_directory_entry_stream_free(reactor_borrow_directory_entry_stream_t *ptr) { + reactor_directory_entry_stream_drop_borrow(*ptr); +} + +void reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_free(reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t *ptr) { + if (ptr->is_some) { + wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_free(&ptr->val); + } +} + +void reactor_tuple2_own_descriptor_string_free(reactor_tuple2_own_descriptor_string_t *ptr) { + reactor_own_descriptor_free(&ptr->f0); + reactor_string_free(&ptr->f1); +} + +void reactor_list_tuple2_own_descriptor_string_free(reactor_list_tuple2_own_descriptor_string_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + reactor_tuple2_own_descriptor_string_free(&ptr->ptr[i]); + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void reactor_borrow_network_free(reactor_borrow_network_t *ptr) { + reactor_network_drop_borrow(*ptr); +} + +void reactor_own_resolve_address_stream_free(reactor_own_resolve_address_stream_t *ptr) { + wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_address_stream_drop_own(*ptr); +} + +void reactor_borrow_resolve_address_stream_free(reactor_borrow_resolve_address_stream_t *ptr) { + reactor_resolve_address_stream_drop_borrow(*ptr); +} + +void reactor_borrow_tcp_socket_free(reactor_borrow_tcp_socket_t *ptr) { + reactor_tcp_socket_drop_borrow(*ptr); +} + +void reactor_tuple2_own_input_stream_own_output_stream_free(reactor_tuple2_own_input_stream_own_output_stream_t *ptr) { + reactor_own_input_stream_free(&ptr->f0); + reactor_own_output_stream_free(&ptr->f1); +} + +void reactor_own_tcp_socket_free(reactor_own_tcp_socket_t *ptr) { + wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(*ptr); +} + +void reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_free(reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ptr) { + reactor_own_tcp_socket_free(&ptr->f0); + reactor_own_input_stream_free(&ptr->f1); + reactor_own_output_stream_free(&ptr->f2); +} + +void wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_free(wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ptr) { + reactor_list_u8_free(&ptr->data); +} + +void reactor_borrow_udp_socket_free(reactor_borrow_udp_socket_t *ptr) { + reactor_udp_socket_drop_borrow(*ptr); +} + +void reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_free(reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_free(&ptr->ptr[i]); + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void reactor_own_udp_socket_free(reactor_own_udp_socket_t *ptr) { + wasi_sockets_0_2_0_rc_2023_10_18_udp_udp_socket_drop_own(*ptr); +} + +void reactor_own_network_free(reactor_own_network_t *ptr) { + wasi_sockets_0_2_0_rc_2023_10_18_network_network_drop_own(*ptr); +} + +void reactor_tuple2_string_string_free(reactor_tuple2_string_string_t *ptr) { + reactor_string_free(&ptr->f0); + reactor_string_free(&ptr->f1); +} + +void reactor_list_tuple2_string_string_free(reactor_list_tuple2_string_string_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + reactor_tuple2_string_string_free(&ptr->ptr[i]); + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void reactor_list_string_free(reactor_list_string_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + reactor_string_free(&ptr->ptr[i]); + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void reactor_own_terminal_input_free(reactor_own_terminal_input_t *ptr) { + wasi_cli_0_2_0_rc_2023_10_18_terminal_input_terminal_input_drop_own(*ptr); +} + +void reactor_own_terminal_output_free(reactor_own_terminal_output_t *ptr) { + wasi_cli_0_2_0_rc_2023_10_18_terminal_output_terminal_output_drop_own(*ptr); +} + +void reactor_string_set(reactor_string_t *ret, char*s) { + ret->ptr = (uint8_t*) s; + ret->len = strlen(s); +} + +void reactor_string_dup(reactor_string_t *ret, const char*s) { + ret->len = strlen(s); + ret->ptr = cabi_realloc(NULL, 0, 1, ret->len * 1); + memcpy(ret->ptr, s, ret->len * 1); +} + +void reactor_string_free(reactor_string_t *ret) { + if (ret->len > 0) { + free(ret->ptr); + } + ret->ptr = NULL; + ret->len = 0; +} + +// Functions for working with resource `wasi:filesystem/types@0.2.0-rc-2023-10-18/directory-entry-stream` +reactor_borrow_directory_entry_stream_t wasi_filesystem_0_2_0_rc_2023_10_18_types_borrow_directory_entry_stream(reactor_own_directory_entry_stream_t arg) { + return (reactor_borrow_directory_entry_stream_t) { arg.__handle }; +} +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]directory-entry-stream"))) +void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_stream_drop_own(int32_t); + +void wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_stream_drop_own(reactor_own_directory_entry_stream_t arg) { + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_stream_drop_own(arg.__handle); +} +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]directory-entry-stream"))) +void __wasm_import_reactor_directory_entry_stream_drop_borrow(int32_t); + +void reactor_directory_entry_stream_drop_borrow(reactor_borrow_directory_entry_stream_t arg) { + __wasm_import_reactor_directory_entry_stream_drop_borrow(arg.__handle); +} + +// Functions for working with resource `wasi:io/streams@0.2.0-rc-2023-10-18/output-stream` +reactor_borrow_output_stream_t wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(reactor_own_output_stream_t arg) { + return (reactor_borrow_output_stream_t) { arg.__handle }; +} +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]output-stream"))) +void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(int32_t); + +void wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(reactor_own_output_stream_t arg) { + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(arg.__handle); +} +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]output-stream"))) +void __wasm_import_reactor_output_stream_drop_borrow(int32_t); + +void reactor_output_stream_drop_borrow(reactor_borrow_output_stream_t arg) { + __wasm_import_reactor_output_stream_drop_borrow(arg.__handle); +} + +// Functions for working with resource `wasi:io/streams@0.2.0-rc-2023-10-18/error` +reactor_borrow_error_t wasi_io_0_2_0_rc_2023_10_18_streams_borrow_error(reactor_own_error_t arg) { + return (reactor_borrow_error_t) { arg.__handle }; +} +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]error"))) +void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_error_drop_own(int32_t); + +void wasi_io_0_2_0_rc_2023_10_18_streams_error_drop_own(reactor_own_error_t arg) { + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_error_drop_own(arg.__handle); +} +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]error"))) +void __wasm_import_reactor_error_drop_borrow(int32_t); + +void reactor_error_drop_borrow(reactor_borrow_error_t arg) { + __wasm_import_reactor_error_drop_borrow(arg.__handle); +} + +// Functions for working with resource `wasi:io/poll@0.2.0-rc-2023-10-18/pollable` +reactor_borrow_pollable_t wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(reactor_own_pollable_t arg) { + return (reactor_borrow_pollable_t) { arg.__handle }; +} +__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]pollable"))) +void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(int32_t); + +void wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(reactor_own_pollable_t arg) { + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(arg.__handle); +} +__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]pollable"))) +void __wasm_import_reactor_pollable_drop_borrow(int32_t); + +void reactor_pollable_drop_borrow(reactor_borrow_pollable_t arg) { + __wasm_import_reactor_pollable_drop_borrow(arg.__handle); +} + +// Functions for working with resource `wasi:sockets/tcp@0.2.0-rc-2023-10-18/tcp-socket` +reactor_borrow_tcp_socket_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(reactor_own_tcp_socket_t arg) { + return (reactor_borrow_tcp_socket_t) { arg.__handle }; +} +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]tcp-socket"))) +void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(int32_t); + +void wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(reactor_own_tcp_socket_t arg) { + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(arg.__handle); +} +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]tcp-socket"))) +void __wasm_import_reactor_tcp_socket_drop_borrow(int32_t); + +void reactor_tcp_socket_drop_borrow(reactor_borrow_tcp_socket_t arg) { + __wasm_import_reactor_tcp_socket_drop_borrow(arg.__handle); +} + +// Functions for working with resource `wasi:cli/terminal-input@0.2.0-rc-2023-10-18/terminal-input` +__attribute__((__import_module__("wasi:cli/terminal-input@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]terminal-input"))) +void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_input_terminal_input_drop_own(int32_t); + +void wasi_cli_0_2_0_rc_2023_10_18_terminal_input_terminal_input_drop_own(reactor_own_terminal_input_t arg) { + __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_input_terminal_input_drop_own(arg.__handle); +} + +// Functions for working with resource `wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18/resolve-address-stream` +reactor_borrow_resolve_address_stream_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_borrow_resolve_address_stream(reactor_own_resolve_address_stream_t arg) { + return (reactor_borrow_resolve_address_stream_t) { arg.__handle }; +} +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]resolve-address-stream"))) +void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_address_stream_drop_own(int32_t); + +void wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_address_stream_drop_own(reactor_own_resolve_address_stream_t arg) { + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_address_stream_drop_own(arg.__handle); +} +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]resolve-address-stream"))) +void __wasm_import_reactor_resolve_address_stream_drop_borrow(int32_t); + +void reactor_resolve_address_stream_drop_borrow(reactor_borrow_resolve_address_stream_t arg) { + __wasm_import_reactor_resolve_address_stream_drop_borrow(arg.__handle); +} + +// Functions for working with resource `wasi:cli/terminal-output@0.2.0-rc-2023-10-18/terminal-output` +__attribute__((__import_module__("wasi:cli/terminal-output@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]terminal-output"))) +void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_output_terminal_output_drop_own(int32_t); + +void wasi_cli_0_2_0_rc_2023_10_18_terminal_output_terminal_output_drop_own(reactor_own_terminal_output_t arg) { + __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_output_terminal_output_drop_own(arg.__handle); +} + +// Functions for working with resource `wasi:sockets/network@0.2.0-rc-2023-10-18/network` +reactor_borrow_network_t wasi_sockets_0_2_0_rc_2023_10_18_network_borrow_network(reactor_own_network_t arg) { + return (reactor_borrow_network_t) { arg.__handle }; +} +__attribute__((__import_module__("wasi:sockets/network@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]network"))) +void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_network_network_drop_own(int32_t); + +void wasi_sockets_0_2_0_rc_2023_10_18_network_network_drop_own(reactor_own_network_t arg) { + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_network_network_drop_own(arg.__handle); +} +__attribute__((__import_module__("wasi:sockets/network@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]network"))) +void __wasm_import_reactor_network_drop_borrow(int32_t); + +void reactor_network_drop_borrow(reactor_borrow_network_t arg) { + __wasm_import_reactor_network_drop_borrow(arg.__handle); +} + +// Functions for working with resource `wasi:io/streams@0.2.0-rc-2023-10-18/input-stream` +reactor_borrow_input_stream_t wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(reactor_own_input_stream_t arg) { + return (reactor_borrow_input_stream_t) { arg.__handle }; +} +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]input-stream"))) +void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(int32_t); + +void wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(reactor_own_input_stream_t arg) { + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(arg.__handle); +} +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]input-stream"))) +void __wasm_import_reactor_input_stream_drop_borrow(int32_t); + +void reactor_input_stream_drop_borrow(reactor_borrow_input_stream_t arg) { + __wasm_import_reactor_input_stream_drop_borrow(arg.__handle); +} + +// Functions for working with resource `wasi:filesystem/types@0.2.0-rc-2023-10-18/descriptor` +reactor_borrow_descriptor_t wasi_filesystem_0_2_0_rc_2023_10_18_types_borrow_descriptor(reactor_own_descriptor_t arg) { + return (reactor_borrow_descriptor_t) { arg.__handle }; +} +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]descriptor"))) +void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_drop_own(int32_t); + +void wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_drop_own(reactor_own_descriptor_t arg) { + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_drop_own(arg.__handle); +} +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]descriptor"))) +void __wasm_import_reactor_descriptor_drop_borrow(int32_t); + +void reactor_descriptor_drop_borrow(reactor_borrow_descriptor_t arg) { + __wasm_import_reactor_descriptor_drop_borrow(arg.__handle); +} + +// Functions for working with resource `wasi:sockets/udp@0.2.0-rc-2023-10-18/udp-socket` +reactor_borrow_udp_socket_t wasi_sockets_0_2_0_rc_2023_10_18_udp_borrow_udp_socket(reactor_own_udp_socket_t arg) { + return (reactor_borrow_udp_socket_t) { arg.__handle }; +} +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]udp-socket"))) +void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_udp_socket_drop_own(int32_t); + +void wasi_sockets_0_2_0_rc_2023_10_18_udp_udp_socket_drop_own(reactor_own_udp_socket_t arg) { + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_udp_socket_drop_own(arg.__handle); +} +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]udp-socket"))) +void __wasm_import_reactor_udp_socket_drop_borrow(int32_t); + +void reactor_udp_socket_drop_borrow(reactor_borrow_udp_socket_t arg) { + __wasm_import_reactor_udp_socket_drop_borrow(arg.__handle); +} + +// Component Adapters + +void wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_now(wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t *ret) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_now(ptr); + *ret = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 0))), + (uint32_t) (*((int32_t*) (ptr + 8))), + }; +} + +void wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_resolution(wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t *ret) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_resolution(ptr); + *ret = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 0))), + (uint32_t) (*((int32_t*) (ptr + 8))), + }; +} + +void wasi_io_0_2_0_rc_2023_10_18_poll_poll_list(reactor_list_borrow_pollable_t *in, reactor_list_u32_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_poll_poll_list((int32_t) (*in).ptr, (int32_t) (*in).len, ptr); + *ret = (reactor_list_u32_t) { (uint32_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +void wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(reactor_borrow_pollable_t in) { + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_poll_poll_one((in).__handle); +} + +wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_now(void) { + int64_t ret = __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_now(); + return (uint64_t) (ret); +} + +wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_resolution(void) { + int64_t ret = __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_resolution(); + return (uint64_t) (ret); +} + +reactor_own_pollable_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_subscribe(wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t when, bool absolute) { + int32_t ret = __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_subscribe((int64_t) (when), absolute); + return (reactor_own_pollable_t) { ret }; +} + +void wasi_clocks_0_2_0_rc_2023_10_18_timezone_display(wasi_clocks_0_2_0_rc_2023_10_18_timezone_datetime_t *when, wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_timezone_display((int64_t) ((*when).seconds), (int32_t) ((*when).nanoseconds), ptr); + *ret = (wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_t) { + *((int32_t*) (ptr + 0)), + (reactor_string_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, + (int32_t) (*((uint8_t*) (ptr + 12))), + }; +} + +int32_t wasi_clocks_0_2_0_rc_2023_10_18_timezone_utc_offset(wasi_clocks_0_2_0_rc_2023_10_18_timezone_datetime_t *when) { + int32_t ret = __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_timezone_utc_offset((int64_t) ((*when).seconds), (int32_t) ((*when).nanoseconds)); + return ret; +} + +void wasi_io_0_2_0_rc_2023_10_18_streams_method_error_to_debug_string(reactor_borrow_error_t self, reactor_string_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_error_to_debug_string((self).__handle, ptr); + *ret = (reactor_string_t) { (uint8_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_read(reactor_borrow_input_stream_t self, uint64_t len, reactor_list_u8_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_read((self).__handle, (int64_t) (len), ptr); + reactor_result_list_u8_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; + break; + } + case 1: { + result.is_err = true; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_read(reactor_borrow_input_stream_t self, uint64_t len, reactor_list_u8_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_read((self).__handle, (int64_t) (len), ptr); + reactor_result_list_u8_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; + break; + } + case 1: { + result.is_err = true; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_skip(reactor_borrow_input_stream_t self, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_skip((self).__handle, (int64_t) (len), ptr); + reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_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; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 12)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_skip(reactor_borrow_input_stream_t self, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_skip((self).__handle, (int64_t) (len), ptr); + reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_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; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 12)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +reactor_own_pollable_t wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe(reactor_borrow_input_stream_t self) { + int32_t ret = __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe((self).__handle); + return (reactor_own_pollable_t) { ret }; +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_check_write(reactor_borrow_output_stream_t self, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_check_write((self).__handle, ptr); + reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_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; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 12)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write(reactor_borrow_output_stream_t self, reactor_list_u8_t *contents, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write((self).__handle, (int32_t) (*contents).ptr, (int32_t) (*contents).len, ptr); + reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_and_flush(reactor_borrow_output_stream_t self, reactor_list_u8_t *contents, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_and_flush((self).__handle, (int32_t) (*contents).ptr, (int32_t) (*contents).len, ptr); + reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_flush(reactor_borrow_output_stream_t self, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_flush((self).__handle, ptr); + reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_flush(reactor_borrow_output_stream_t self, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_flush((self).__handle, ptr); + reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +reactor_own_pollable_t wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe(reactor_borrow_output_stream_t self) { + int32_t ret = __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe((self).__handle); + return (reactor_own_pollable_t) { ret }; +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write_zeroes(reactor_borrow_output_stream_t self, uint64_t len, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write_zeroes((self).__handle, (int64_t) (len), ptr); + reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_zeroes_and_flush(reactor_borrow_output_stream_t self, uint64_t len, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_zeroes_and_flush((self).__handle, (int64_t) (len), ptr); + reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_splice(reactor_borrow_output_stream_t self, reactor_own_input_stream_t src, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_splice((self).__handle, (src).__handle, (int64_t) (len), ptr); + reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_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; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 12)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_splice(reactor_borrow_output_stream_t self, reactor_own_input_stream_t src, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_splice((self).__handle, (src).__handle, (int64_t) (len), ptr); + reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_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; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 12)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_forward(reactor_borrow_output_stream_t self, reactor_own_input_stream_t src, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_forward((self).__handle, (src).__handle, ptr); + reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_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; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 12)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_via_stream(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, reactor_own_input_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_via_stream((self).__handle, (int64_t) (offset), ptr); + reactor_result_own_input_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_own_input_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write_via_stream(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, reactor_own_output_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write_via_stream((self).__handle, (int64_t) (offset), ptr); + reactor_result_own_output_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_own_output_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_append_via_stream(reactor_borrow_descriptor_t self, reactor_own_output_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_append_via_stream((self).__handle, ptr); + reactor_result_own_output_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_own_output_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_advise(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t length, wasi_filesystem_0_2_0_rc_2023_10_18_types_advice_t advice, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_advise((self).__handle, (int64_t) (offset), (int64_t) (length), (int32_t) advice, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync_data(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync_data((self).__handle, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_flags(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_flags((self).__handle, ptr); + reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_type(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_type((self).__handle, ptr); + reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_size(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t size, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_size((self).__handle, (int64_t) (size), ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_access_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_modification_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t variant; + int64_t variant2; + int32_t variant3; + switch ((int32_t) (*data_access_timestamp).tag) { + case 0: { + variant = 0; + variant2 = 0; + variant3 = 0; + break; + } + case 1: { + variant = 1; + variant2 = 0; + variant3 = 0; + break; + } + case 2: { + const wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t *payload1 = &(*data_access_timestamp).val.timestamp; + variant = 2; + variant2 = (int64_t) ((*payload1).seconds); + variant3 = (int32_t) ((*payload1).nanoseconds); + break; + } + } + int32_t variant7; + int64_t variant8; + int32_t variant9; + switch ((int32_t) (*data_modification_timestamp).tag) { + case 0: { + variant7 = 0; + variant8 = 0; + variant9 = 0; + break; + } + case 1: { + variant7 = 1; + variant8 = 0; + variant9 = 0; + break; + } + case 2: { + const wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t *payload6 = &(*data_modification_timestamp).val.timestamp; + variant7 = 2; + variant8 = (int64_t) ((*payload6).seconds); + variant9 = (int32_t) ((*payload6).nanoseconds); + break; + } + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times((self).__handle, variant, variant2, variant3, variant7, variant8, variant9, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t length, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, reactor_tuple2_list_u8_bool_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read((self).__handle, (int64_t) (length), (int64_t) (offset), ptr); + reactor_result_tuple2_list_u8_bool_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_tuple2_list_u8_bool_t) { + (reactor_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, + (int32_t) (*((uint8_t*) (ptr + 12))), + }; + 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write(reactor_borrow_descriptor_t self, reactor_list_u8_t *buffer, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write((self).__handle, (int32_t) (*buffer).ptr, (int32_t) (*buffer).len, (int64_t) (offset), ptr); + reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_directory(reactor_borrow_descriptor_t self, reactor_own_directory_entry_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_directory((self).__handle, ptr); + reactor_result_own_directory_entry_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_own_directory_entry_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync((self).__handle, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_create_directory_at(reactor_borrow_descriptor_t self, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_create_directory_at((self).__handle, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[104]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat((self).__handle, ptr); + reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t option; + switch ((int32_t) (*((uint8_t*) (ptr + 32)))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + option.val = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 40))), + (uint32_t) (*((int32_t*) (ptr + 48))), + }; + break; + } + } + reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t option0; + switch ((int32_t) (*((uint8_t*) (ptr + 56)))) { + case 0: { + option0.is_some = false; + break; + } + case 1: { + option0.is_some = true; + option0.val = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 64))), + (uint32_t) (*((int32_t*) (ptr + 72))), + }; + break; + } + } + reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t option1; + switch ((int32_t) (*((uint8_t*) (ptr + 80)))) { + case 0: { + option1.is_some = false; + break; + } + case 1: { + option1.is_some = true; + option1.val = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 88))), + (uint32_t) (*((int32_t*) (ptr + 96))), + }; + break; + } + } + + result.val.ok = (wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t) { + (int32_t) (*((uint8_t*) (ptr + 8))), + (uint64_t) (*((int64_t*) (ptr + 16))), + (uint64_t) (*((int64_t*) (ptr + 24))), + option, + option0, + option1, + }; + 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[104]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); + reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t option; + switch ((int32_t) (*((uint8_t*) (ptr + 32)))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + option.val = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 40))), + (uint32_t) (*((int32_t*) (ptr + 48))), + }; + break; + } + } + reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t option0; + switch ((int32_t) (*((uint8_t*) (ptr + 56)))) { + case 0: { + option0.is_some = false; + break; + } + case 1: { + option0.is_some = true; + option0.val = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 64))), + (uint32_t) (*((int32_t*) (ptr + 72))), + }; + break; + } + } + reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t option1; + switch ((int32_t) (*((uint8_t*) (ptr + 80)))) { + case 0: { + option1.is_some = false; + break; + } + case 1: { + option1.is_some = true; + option1.val = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 88))), + (uint32_t) (*((int32_t*) (ptr + 96))), + }; + break; + } + } + + result.val.ok = (wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t) { + (int32_t) (*((uint8_t*) (ptr + 8))), + (uint64_t) (*((int64_t*) (ptr + 16))), + (uint64_t) (*((int64_t*) (ptr + 24))), + option, + option0, + option1, + }; + 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_access_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_modification_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t variant; + int64_t variant2; + int32_t variant3; + switch ((int32_t) (*data_access_timestamp).tag) { + case 0: { + variant = 0; + variant2 = 0; + variant3 = 0; + break; + } + case 1: { + variant = 1; + variant2 = 0; + variant3 = 0; + break; + } + case 2: { + const wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t *payload1 = &(*data_access_timestamp).val.timestamp; + variant = 2; + variant2 = (int64_t) ((*payload1).seconds); + variant3 = (int32_t) ((*payload1).nanoseconds); + break; + } + } + int32_t variant7; + int64_t variant8; + int32_t variant9; + switch ((int32_t) (*data_modification_timestamp).tag) { + case 0: { + variant7 = 0; + variant8 = 0; + variant9 = 0; + break; + } + case 1: { + variant7 = 1; + variant8 = 0; + variant9 = 0; + break; + } + case 2: { + const wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t *payload6 = &(*data_modification_timestamp).val.timestamp; + variant7 = 2; + variant8 = (int64_t) ((*payload6).seconds); + variant9 = (int32_t) ((*payload6).nanoseconds); + break; + } + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, variant, variant2, variant3, variant7, variant8, variant9, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_link_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t old_path_flags, reactor_string_t *old_path, reactor_borrow_descriptor_t new_descriptor, reactor_string_t *new_path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_link_at((self).__handle, old_path_flags, (int32_t) (*old_path).ptr, (int32_t) (*old_path).len, (new_descriptor).__handle, (int32_t) (*new_path).ptr, (int32_t) (*new_path).len, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_open_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_open_flags_t open_flags, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_t flags, wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t modes, reactor_own_descriptor_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_open_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, open_flags, flags, modes, ptr); + reactor_result_own_descriptor_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_own_descriptor_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_readlink_at(reactor_borrow_descriptor_t self, reactor_string_t *path, reactor_string_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_readlink_at((self).__handle, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); + reactor_result_string_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_string_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; + 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_remove_directory_at(reactor_borrow_descriptor_t self, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_remove_directory_at((self).__handle, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_rename_at(reactor_borrow_descriptor_t self, reactor_string_t *old_path, reactor_borrow_descriptor_t new_descriptor, reactor_string_t *new_path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_rename_at((self).__handle, (int32_t) (*old_path).ptr, (int32_t) (*old_path).len, (new_descriptor).__handle, (int32_t) (*new_path).ptr, (int32_t) (*new_path).len, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_symlink_at(reactor_borrow_descriptor_t self, reactor_string_t *old_path, reactor_string_t *new_path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_symlink_at((self).__handle, (int32_t) (*old_path).ptr, (int32_t) (*old_path).len, (int32_t) (*new_path).ptr, (int32_t) (*new_path).len, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_access_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_access_type_t *type, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t variant; + int32_t variant1; + switch ((int32_t) (*type).tag) { + case 0: { + const wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t *payload = &(*type).val.access; + variant = 0; + variant1 = *payload; + break; + } + case 1: { + variant = 1; + variant1 = 0; + break; + } + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_access_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, variant, variant1, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlink_file_at(reactor_borrow_descriptor_t self, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlink_file_at((self).__handle, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_file_permissions_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t modes, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_file_permissions_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, modes, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_directory_permissions_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t modes, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_directory_permissions_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, modes, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_shared(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_shared((self).__handle, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_exclusive(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_exclusive((self).__handle, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_shared(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_shared((self).__handle, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_exclusive(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_exclusive((self).__handle, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlock(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlock((self).__handle, ptr); + reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_is_same_object(reactor_borrow_descriptor_t self, reactor_borrow_descriptor_t other) { + int32_t ret = __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_is_same_object((self).__handle, (other).__handle); + return ret; +} + +bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[24]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash((self).__handle, ptr); + reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t) { + (uint64_t) (*((int64_t*) (ptr + 8))), + (uint64_t) (*((int64_t*) (ptr + 16))), + }; + 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[24]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); + reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t) { + (uint64_t) (*((int64_t*) (ptr + 8))), + (uint64_t) (*((int64_t*) (ptr + 16))), + }; + 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_directory_entry_stream_read_directory_entry(reactor_borrow_directory_entry_stream_t self, reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[20]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_directory_entry_stream_read_directory_entry((self).__handle, ptr); + reactor_result_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t option; + switch ((int32_t) (*((uint8_t*) (ptr + 4)))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + option.val = (wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t) { + (int32_t) (*((uint8_t*) (ptr + 8))), + (reactor_string_t) { (uint8_t*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }, + }; + break; + } + } + + result.val.ok = option; + 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_filesystem_error_code(reactor_borrow_error_t err, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *ret) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_filesystem_error_code((err).__handle, ptr); + reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t option; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + option.val = (int32_t) (*((uint8_t*) (ptr + 1))); + break; + } + } + *ret = option.val; + return option.is_some; +} + +void wasi_filesystem_0_2_0_rc_2023_10_18_preopens_get_directories(reactor_list_tuple2_own_descriptor_string_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_preopens_get_directories(ptr); + *ret = (reactor_list_tuple2_own_descriptor_string_t) { (reactor_tuple2_own_descriptor_string_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +reactor_own_network_t wasi_sockets_0_2_0_rc_2023_10_18_instance_network_instance_network(void) { + int32_t ret = __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_instance_network_instance_network(); + return (reactor_own_network_t) { ret }; +} + +bool wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_addresses(reactor_borrow_network_t network, reactor_string_t *name, wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t *maybe_address_family, bool include_unavailable, reactor_own_resolve_address_stream_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t address_family; + address_family.is_some = maybe_address_family != NULL;if (maybe_address_family) { + address_family.val = *maybe_address_family; + } + int32_t option; + int32_t option1; + if ((address_family).is_some) { + const wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t *payload0 = &(address_family).val; + option = 1; + option1 = (int32_t) *payload0; + } else { + option = 0; + option1 = 0; + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_addresses((network).__handle, (int32_t) (*name).ptr, (int32_t) (*name).len, option, option1, include_unavailable, ptr); + reactor_result_own_resolve_address_stream_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_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 wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_resolve_next_address(reactor_borrow_resolve_address_stream_t self, reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t *err) { + __attribute__((__aligned__(2))) + uint8_t ret_area[22]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_resolve_next_address((self).__handle, ptr); + reactor_result_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t option; + switch ((int32_t) (*((uint8_t*) (ptr + 2)))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t) { + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 6)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 7)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 8)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 9)))), + }; + break; + } + case 1: { + variant.val.ipv6 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 6)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 10)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 12)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 14)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), + }; + break; + } + } + + option.val = variant; + break; + } + } + + result.val.ok = option; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) (*((uint8_t*) (ptr + 2))); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +reactor_own_pollable_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_subscribe(reactor_borrow_resolve_address_stream_t self) { + int32_t ret = __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_subscribe((self).__handle); + return (reactor_own_pollable_t) { ret }; +} + +bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_bind(reactor_borrow_tcp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *local_address, wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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; + } + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_bind((self).__handle, (network).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_bind(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_bind((self).__handle, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_connect(reactor_borrow_tcp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *remote_address, wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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; + } + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_connect((self).__handle, (network).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_connect(reactor_borrow_tcp_socket_t self, reactor_tuple2_own_input_stream_own_output_stream_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_connect((self).__handle, ptr); + reactor_result_tuple2_own_input_stream_own_output_stream_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_tuple2_own_input_stream_own_output_stream_t) { + (reactor_own_input_stream_t) { *((int32_t*) (ptr + 4)) }, + (reactor_own_output_stream_t) { *((int32_t*) (ptr + 8)) }, + }; + 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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_listen(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_listen((self).__handle, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_listen(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_listen((self).__handle, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_accept(reactor_borrow_tcp_socket_t self, reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_accept((self).__handle, ptr); + reactor_result_tuple3_own_tcp_socket_own_input_stream_own_output_stream_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t) { + (reactor_own_tcp_socket_t) { *((int32_t*) (ptr + 4)) }, + (reactor_own_input_stream_t) { *((int32_t*) (ptr + 8)) }, + (reactor_own_output_stream_t) { *((int32_t*) (ptr + 12)) }, + }; + 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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_local_address(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[36]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_local_address((self).__handle, ptr); + reactor_result_wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t) { + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 10)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 11)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 12)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 13)))), + }, + }; + break; + } + case 1: { + variant.val.ipv6 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (uint32_t) (*((int32_t*) (ptr + 12))), + (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 22)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 24)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 26)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 28)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 30)))), + }, + (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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_remote_address(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[36]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_remote_address((self).__handle, ptr); + reactor_result_wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t) { + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 10)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 11)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 12)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 13)))), + }, + }; + break; + } + case 1: { + variant.val.ipv6 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (uint32_t) (*((int32_t*) (ptr + 12))), + (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 22)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 24)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 26)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 28)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 30)))), + }, + (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; + } +} + +wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(reactor_borrow_tcp_socket_t self) { + int32_t ret = __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family((self).__handle); + return ret; +} + +bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_ipv6_only(reactor_borrow_tcp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_ipv6_only((self).__handle, ptr); + reactor_result_bool_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_ipv6_only(reactor_borrow_tcp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_ipv6_only((self).__handle, value, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_listen_backlog_size(reactor_borrow_tcp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_listen_backlog_size((self).__handle, (int64_t) (value), ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_keep_alive(reactor_borrow_tcp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_keep_alive((self).__handle, ptr); + reactor_result_bool_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_keep_alive(reactor_borrow_tcp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_keep_alive((self).__handle, value, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_no_delay(reactor_borrow_tcp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_no_delay((self).__handle, ptr); + reactor_result_bool_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_no_delay(reactor_borrow_tcp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_no_delay((self).__handle, value, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_unicast_hop_limit(reactor_borrow_tcp_socket_t self, uint8_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_unicast_hop_limit((self).__handle, ptr); + reactor_result_u8_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_unicast_hop_limit(reactor_borrow_tcp_socket_t self, uint8_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_unicast_hop_limit((self).__handle, (int32_t) (value), ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_receive_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_receive_buffer_size((self).__handle, ptr); + reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_receive_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_receive_buffer_size((self).__handle, (int64_t) (value), ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_send_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_send_buffer_size((self).__handle, ptr); + reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_send_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_send_buffer_size((self).__handle, (int64_t) (value), ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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; + } +} + +reactor_own_pollable_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(reactor_borrow_tcp_socket_t self) { + int32_t ret = __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe((self).__handle); + return (reactor_own_pollable_t) { ret }; +} + +bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_shutdown(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_shutdown_type_t shutdown_type, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_shutdown((self).__handle, (int32_t) shutdown_type, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_create_tcp_socket(wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_ip_address_family_t address_family, reactor_own_tcp_socket_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_create_tcp_socket((int32_t) address_family, ptr); + reactor_result_own_tcp_socket_wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_bind(reactor_borrow_udp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *local_address, wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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; + } + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_bind((self).__handle, (network).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_bind(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_bind((self).__handle, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_connect(reactor_borrow_udp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *remote_address, wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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; + } + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_connect((self).__handle, (network).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_connect(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_connect((self).__handle, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive(reactor_borrow_udp_socket_t self, uint64_t max_results, reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive((self).__handle, (int64_t) (max_results), ptr); + reactor_result_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t) { (wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; + 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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send(reactor_borrow_udp_socket_t self, reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *datagrams, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send((self).__handle, (int32_t) (*datagrams).ptr, (int32_t) (*datagrams).len, ptr); + reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_local_address(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[36]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_local_address((self).__handle, ptr); + reactor_result_wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t) { + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 10)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 11)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 12)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 13)))), + }, + }; + break; + } + case 1: { + variant.val.ipv6 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (uint32_t) (*((int32_t*) (ptr + 12))), + (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 22)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 24)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 26)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 28)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 30)))), + }, + (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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_remote_address(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[36]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_remote_address((self).__handle, ptr); + reactor_result_wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t) { + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 10)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 11)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 12)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 13)))), + }, + }; + break; + } + case 1: { + variant.val.ipv6 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (uint32_t) (*((int32_t*) (ptr + 12))), + (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 22)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 24)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 26)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 28)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 30)))), + }, + (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; + } +} + +wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_address_family(reactor_borrow_udp_socket_t self) { + int32_t ret = __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_address_family((self).__handle); + return ret; +} + +bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_ipv6_only(reactor_borrow_udp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_ipv6_only((self).__handle, ptr); + reactor_result_bool_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_ipv6_only(reactor_borrow_udp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_ipv6_only((self).__handle, value, ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_unicast_hop_limit(reactor_borrow_udp_socket_t self, uint8_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_unicast_hop_limit((self).__handle, ptr); + reactor_result_u8_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_unicast_hop_limit(reactor_borrow_udp_socket_t self, uint8_t value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_unicast_hop_limit((self).__handle, (int32_t) (value), ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive_buffer_size(reactor_borrow_udp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive_buffer_size((self).__handle, ptr); + reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_receive_buffer_size(reactor_borrow_udp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_receive_buffer_size((self).__handle, (int64_t) (value), ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send_buffer_size(reactor_borrow_udp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send_buffer_size((self).__handle, ptr); + reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_send_buffer_size(reactor_borrow_udp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_send_buffer_size((self).__handle, (int64_t) (value), ptr); + reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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; + } +} + +reactor_own_pollable_t wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_subscribe(reactor_borrow_udp_socket_t self) { + int32_t ret = __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_subscribe((self).__handle); + return (reactor_own_pollable_t) { ret }; +} + +bool wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_create_udp_socket(wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_ip_address_family_t address_family, reactor_own_udp_socket_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_create_udp_socket((int32_t) address_family, ptr); + reactor_result_own_udp_socket_wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (reactor_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; + } +} + +void wasi_random_0_2_0_rc_2023_10_18_random_get_random_bytes(uint64_t len, reactor_list_u8_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_random_0_2_0_rc_2023_10_18_random_get_random_bytes((int64_t) (len), ptr); + *ret = (reactor_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +uint64_t wasi_random_0_2_0_rc_2023_10_18_random_get_random_u64(void) { + int64_t ret = __wasm_import_wasi_random_0_2_0_rc_2023_10_18_random_get_random_u64(); + return (uint64_t) (ret); +} + +void wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_bytes(uint64_t len, reactor_list_u8_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_bytes((int64_t) (len), ptr); + *ret = (reactor_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +uint64_t wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_u64(void) { + int64_t ret = __wasm_import_wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_u64(); + return (uint64_t) (ret); +} + +void wasi_random_0_2_0_rc_2023_10_18_insecure_seed_insecure_seed(reactor_tuple2_u64_u64_t *ret) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_random_0_2_0_rc_2023_10_18_insecure_seed_insecure_seed(ptr); + *ret = (reactor_tuple2_u64_u64_t) { + (uint64_t) (*((int64_t*) (ptr + 0))), + (uint64_t) (*((int64_t*) (ptr + 8))), + }; +} + +void wasi_cli_0_2_0_rc_2023_10_18_environment_get_environment(reactor_list_tuple2_string_string_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_environment_get_environment(ptr); + *ret = (reactor_list_tuple2_string_string_t) { (reactor_tuple2_string_string_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +void wasi_cli_0_2_0_rc_2023_10_18_environment_get_arguments(reactor_list_string_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_environment_get_arguments(ptr); + *ret = (reactor_list_string_t) { (reactor_string_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +bool wasi_cli_0_2_0_rc_2023_10_18_environment_initial_cwd(reactor_string_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_environment_initial_cwd(ptr); + reactor_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 = (reactor_string_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; + break; + } + } + *ret = option.val; + return option.is_some; +} + +void wasi_cli_0_2_0_rc_2023_10_18_exit_exit(reactor_result_void_void_t *status) { + int32_t result; + if ((*status).is_err) { + result = 1; + } else { + result = 0; + } + __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_exit_exit(result); +} + +reactor_own_input_stream_t wasi_cli_0_2_0_rc_2023_10_18_stdin_get_stdin(void) { + int32_t ret = __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_stdin_get_stdin(); + return (reactor_own_input_stream_t) { ret }; +} + +reactor_own_output_stream_t wasi_cli_0_2_0_rc_2023_10_18_stdout_get_stdout(void) { + int32_t ret = __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_stdout_get_stdout(); + return (reactor_own_output_stream_t) { ret }; +} + +reactor_own_output_stream_t wasi_cli_0_2_0_rc_2023_10_18_stderr_get_stderr(void) { + int32_t ret = __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_stderr_get_stderr(); + return (reactor_own_output_stream_t) { ret }; +} + +bool wasi_cli_0_2_0_rc_2023_10_18_terminal_stdin_get_terminal_stdin(reactor_own_terminal_input_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_stdin_get_terminal_stdin(ptr); + reactor_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 = (reactor_own_terminal_input_t) { *((int32_t*) (ptr + 4)) }; + break; + } + } + *ret = option.val; + return option.is_some; +} + +bool wasi_cli_0_2_0_rc_2023_10_18_terminal_stdout_get_terminal_stdout(reactor_own_terminal_output_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_stdout_get_terminal_stdout(ptr); + reactor_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 = (reactor_own_terminal_output_t) { *((int32_t*) (ptr + 4)) }; + break; + } + } + *ret = option.val; + return option.is_some; +} + +bool wasi_cli_0_2_0_rc_2023_10_18_terminal_stderr_get_terminal_stderr(reactor_own_terminal_output_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_stderr_get_terminal_stderr(ptr); + reactor_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 = (reactor_own_terminal_output_t) { *((int32_t*) (ptr + 4)) }; + break; + } + } + *ret = option.val; + return option.is_some; +} + +extern void __component_type_object_force_link_reactor(void); +void __component_type_object_force_link_reactor_public_use_in_this_compilation_unit(void) { + __component_type_object_force_link_reactor(); +} diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor_component_type.o b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor_component_type.o new file mode 100644 index 0000000000000000000000000000000000000000..b1658060910f85d92580c9c92b7b2f4a05bdf095 GIT binary patch literal 38549 zcmeHQdym{ka_<^)=dq93m!#GEX=!cQ96kJq>^tAd>o~a}mz1$DQHsP&-48 zNRCD$Ls9a5@&ytgKoI1GJ0wAZyWsNtD#@?9$!2qgvyN=T&K>AKtl4IFb#--hRdscB zmvG}D2_eX)9}8jCNG#h_6D#5`{_@kFtS7={Uy+NO^|5( z&k=o4qYr*SdrK768nM?6gI+vY3EUt||CrjM*>e*w@rRy;{_b<1!V1C()oigGd2u)x zCw>@E&7zwVH}>D_4#MtHd~4zk29ErF|90nY=e84dox8X1zUkb#?cBMyBxtV**rRYT zaQ6qEMbsBGA{tHUKGpo7CM;XD__H(c;{*eh#Y7@)#xItox8jlnG%W>MpaoXe)-LKh`z86?ccV7~~dm)y9Zam(P zyOF=|QQaa?Ag9JK48kM~{O&O%v4CezZP17DMDK+Oh^*yt(sjavgV;-+*?~Ls;vGM5 zdhT@KANCU`cAxmcp~DmQ!WJ9+?=z6f>G|NMcVs#70^!37i%`!-(@vn8>f1 zW64045_^gEoD%xlV#$jla3PUjqsO(A12;~baO6cUbB}Z2`U9^=mZ*beVy`DK&8u+& zjvYFxp#UXT{a`f45M{XqMqCTWiCIE@OdZ*=H#lgD*cKN)9ePPW>^+b$I!WmCy#4VZ zLjaMeMg2OBp3@^*p(UPFZn$g>ykH_$ZE+@RZFbuMPCZ()#nsZU`^^130je56Pv$_k z7lDqC{1L5xE@)Lv@}U~*ve>Z2#Zr87mfWO%BO}h101j8O1_dH^x_z&E4-d?plX^T$zcTFK#(Q$*Gb1)dkeL9(Aw-~yrdde2Bd=B)q zVh$4|x>VjKr_oNv1Y3#;fQO#uB9#>K&%7w~VmfV$x647#3|7@Q#(bLmI^DM<<84`S z)IFm*#`K&ohlo||cRf05i|geTbeCDpd`t|VXI?Lh;+PJ?XyQgaI%mzIuJXVZT`@la4*W&4LKLlx^Zi1uL z$U7Vl+{j_b^%zUqOKh>;^H{u(&`7FQODt1Rw|S*6Nq*So>W+^!a){+Kb>eBz-G=&f zXUa}Q-s7w~!N5I?EwM@gwSg;R=^Q}ig&@H4$W8iK zMY2Yl0=wP?Qi+$3vE@DOVv+ezyk-)OgDyUz8RRcSuWGhIP-i?8R>w^q4*yv8o_by2 zg`b#*VF-jQu>}EMce`CLj%i!ey{AynF-z3zNKi zz)Ku&I7+7L{0qz-K7rZ?N3DzjZZrxbAYVrpNiuEYpLpEuXBcqR1Ms*632R~KC#YcB$6y6?Mj-vM%C)Vzl7b0%Q(<hPlRFDsyO8+%0c$=z%j> z+|iq8v0}D(%dlsRKDY%-D|%Z`gOXK@y*7Z12C&NInxc0ywZ2;}*3KU%*3L8d(lIkW zEd1!#*l-PN_g-Km@A62L5wWYuoN>#0w%93|YF<6`Ei`VKjrXy`_!NuGnAZh?(`$w zX*-0H$<_XPGy6Mkv;N8f>^AvtP06w$Nfiy~zd`a8ytoMAO=F3HujrVN8^ z@%Ia8ChZJ#@LPZ$^Yo~lRyM&uK{LI3$uXA#EyL}%%b6g84tiqPOo|CI(er;LO4&+_ zJgF6d_4hTK=eVEk_Rx*7+PK+z_1?&21DRXg*|%4U@f2`7d%j{W|f@=?hu+G6Ee zdKYF;7?zi`N(^9nOH@{^08sDkjhY}Pa5DtZQke9;Xjj0IqBqM%eHd9WTTbErBkUyT zV{rE?rttY^@b%>q!WFCo`hCq_^V}gAM46&4fZ#d$A@y(2(M6!}bGdw#Cj6NY{|X3i zY9xw=YicPd%ORgfY4g!1)L)__R;m_^re6s0Z-8`?`6HfU>yr9qq$x#zXwhqO$C!V< z#cH#B-v|esSTal@+H3I6Zl!1+3Be{%SgXY}ve+Sqo!>g^;|x(BS`faeH)cB?MIH;B z^1fGTZxddxz)L1!bOd+Q@MN}MTuWD5&kKC7CoN8Go^E6&Cd~5j5Cr1AD!g#15!_%2 zjgk{^kaWipWJh-j$^-}4P$tssHEnidhp?8xWwqjMu&7qMO_=Ghbx*jx9-H|NTh9A_ zAU9|2tPn6^i*B(D#P(nuK*?ei!?4~$*8y0Pw@Q(BfJ(iMLJ^dTS;yU%Hux4BQ-={; zZh8l@DTN?|hM)5Z!#<0thso|@@u@=WsM&irj=Zxh09@&Lp8Ygqd4udV+aEo7i~skI zEjIm;la1=Y9r^?8sVoZZ=lGA^1*n;Q2kTJS{4D)XeS9bX*udUYLZ-Tqz^MtgUC!ZK zqQx6J-gSJ|Nc*hAWS4!Uv`>pIu|kopsmo+S)M#jVN-t+2#TPG`Fe>OX*;aGtOSb4R( z9(FL2=gG3@j$AWYSF<%r`&{QfjqQ{CGbbzmIX{cEcZPABakkH)D;+)X&l%t?* zEzBKUPBq#pXBc>pPNjU8@q@9UT4vwFBU)v5rV@@T0$yA#8p~TkG&18e@vy5*=at%q z?{!72+v3$sz-HCcnwfyjJ&YUFx9F%v{xXo+W@PMa+BTJcK`(E$5Vo-ChU=!s3*3Ez zg~p5U1^Zt&XF7v8JeeIk=&2n!as|T$a5Ns3PV9Czbw!q>z3(xtU(#DwoN4K>D=?;< zzuB3V2OT`1l64^uYZgrSDh(|hYIQxhwP39VJ$oMt8y=jvKTdk^0H%&8V6dEYvo!~q z-^VO~83gt|>9%Pzn}n@3*Z}ajq!YLzwheb_4x|Hl9VwAaCo+cG}DoGjGnleqOh~?c8>-j4zA#?qZ{QcdE|M}q5~`jdZm2C4A7``-Ed(T z-NMP$^KewiQ1p(}_|8yt9o{fLH>tL3xQUELW1M~RkzYR?Dboh7ts?cFGa0lXHJWmN z^UYsF#}l*To5l{&Xr0OjI0MZNLww_RO0_;kM31(|#xuxl{yF$D&sX+8&ik^}tE!fn`HZ(%$NvqLwE$v*KH7 z?*$@SY5<(p8E|pNOFpaOCc&(y8FjZLaNx6<`gZd1(6U8$XNTdW)s*5Y9n=o(-Q!Ud z^^zP$K`$+~Ko;nwV+|2@&B4ZGb9#A3xI>@vdA>BWVPAqW%$=42 zfb!NdyHI^bW?!|1mf3}RaO2O)_iKjP-xko0T4tLqbqvt;S;>o9r9$d7B=4#r2fjMV z3)VK^zJ%n>2Q)8v`P=79-m@H41~~}#k&LIozITJYH|lgvo@mA-H>o%M0;UbUe5xTxlb%=GGts_*>7B%pgA>z4DCr%277^-50>&G9o151+hW4%UewIlr2|?{{n3|q>d@n53ljl>*T)$${uzZa{<6T5Le#N!^b$`9#+iN4_!W-W6O9NVMFISa zxW*KHh=nv%nQ=@h4% zqH|nlY84WWlJ&vt9C&w($ZHOR1YmzH2YlPuZp}4H*Bs7Zecq?tWiv#Q@}_w6xOU7x zIG3ZhsK3U}$oosFKxwSc4D*e;LcY_|2)>am^|uAiqAnDeQ8RhE`Ve;m@3GJOws$ph z_XL7$wBvWSNk>J?e2e@Ou_u=%sUxN_Da{V@9F4ZFW4s+CnPkG_`-3M8zUe_IF z+wW2zAkW#^8M*yrhjtS5WKzqF@oo|p4f6r(EsvpxLBm0NcMS}O#}TN^|f2zUj%cCUc_^iQ&z!Y{y7!A_w$^bKT~J<8dKd^l2h^6Cv=1X!d1xR zd{-;2Uq};P6SmkgCF~zi|2+9SAklv?i5}5^qU)po(uDeVA^sbL(jkD0WWAKe4>Jxz zE1n;{b6?mhpQs;aMteU=M#n@EybfFP{G8I|!dXqpWear^f6M~Z+iV;`X3jx{HO8Nu zGA%4!hme*Fdq|HmAuKaP0}fCk1RuZ!{D_v}jk;gMIhK^;&CFVAv2(DFsOH|lqg9JK za>F2LqUTS2E#GXc-3)tB-3*hezPcHvuO%uK?o>C!s+(ce&9LfbSamZj zy)9PV46AO2RX4*pe5<+{_Q1GAQQZt1jz0e`pmrG0F zscwd;i_q20u>7$MgGKZOvg&5ogX~h(RNeT`E-nSkDVGpxE9CZBSv zZiZDi!*GhRJ(%)y**V zh-H2q%7|;JZiZDi!>XHMQkhma!_*zo>Sh?5R@Ke0X8D`VTVvsJs;e|^uh|OI?hKBSnt0o$Mc2kDr;zHp!eM9scOx;kW7N}AS z@RLMUYJp)#zw@siZT{6tEns~UHxJ;H7BxI3o@W%{f?`$zE>YJw@XOMvS+e8?xO!gz zkUGWjz+e#!prjXZvpXTuBM#@e2FX`p@ian}+(2I7tCAa3$qlOH26&>ON^St7cvvMj zP)7nrG!ws#Q6)E!*?I74Yn9v}d$wS=1@w+hUsW}R_`APE) z<;zGbAPs>`3Q4_nPUg8Ya*+wa4IG~n5bzUDIPeXTuke&jXNz7`Jf6hQLT0YiEfT9{ z5uVO#{Q0W%r>=i}d1oFFP8E?}(sd!#V7vZyhBcjTaI^j%}I!%k|mFZM@Qq`^d zW3sSTc~bxXr5tE6tx(b;t1cQpy)6~WjY^?FSL=t#xLU3HPn38I=uK? zWfrS4i)CqfaGE3&Y^GdXWfsexsy6QP-VKl)%@QS!^TCELPM@au|hy$uZ0hOd`KP zFG)qVV9?DfvzUJBJ5N!R-J-@j+?;WOs?1_YPFZCZOQ5)AZrDPS#;cTOQcQ2j{YqyR z+l1t885zL7I?0Q>Wd_`rki7Y_{i2!0wo|`vLChMy + +typedef enum { + DESCRIPTOR_TABLE_VARIANT_TCP_NEW, + DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED, +} descriptor_table_tag_t; + +typedef struct { + reactor_own_tcp_socket_t socket; + reactor_own_input_stream_t rx; + reactor_own_output_stream_t tx; +} descriptor_table_tcp_connected_t; + +typedef union { + reactor_own_tcp_socket_t tcp_new; + descriptor_table_tcp_connected_t tcp_connected; +} descriptor_table_value_t; + +typedef struct { + descriptor_table_tag_t tag; + descriptor_table_value_t value; +} descriptor_table_variant_t; + +bool descriptor_table_insert(descriptor_table_variant_t variant, int* fd); + +bool descriptor_table_update(int fd, descriptor_table_variant_t variant); + +bool descriptor_table_get(int fd, descriptor_table_variant_t* variant); + +bool descriptor_table_remove(int fd, descriptor_table_variant_t* variant); + +#endif diff --git a/libc-bottom-half/headers/private/reactor.h b/libc-bottom-half/headers/private/reactor.h new file mode 100644 index 000000000..d9a432463 --- /dev/null +++ b/libc-bottom-half/headers/private/reactor.h @@ -0,0 +1,2043 @@ +// Generated by `wit-bindgen` 0.14.0. DO NOT EDIT! +#ifndef __BINDINGS_REACTOR_H +#define __BINDINGS_REACTOR_H +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +typedef struct { + uint8_t*ptr; + size_t len; +} reactor_string_t; + +typedef struct { + int32_t __handle; +} reactor_borrow_pollable_t; + +typedef struct { + reactor_borrow_pollable_t *ptr; + size_t len; +} reactor_list_borrow_pollable_t; + +typedef struct { + uint32_t *ptr; + size_t len; +} reactor_list_u32_t; + +typedef struct { + int32_t __handle; +} reactor_own_error_t; + +// An error for input-stream and output-stream operations. +typedef struct { + uint8_t tag; + union { + reactor_own_error_t last_operation_failed; + } val; +} wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t; + +// The last operation (a write or flush) failed before completion. +// +// More information is available in the `error` payload. +#define WASI_IO_0_2_0_RC_2023_10_18_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 WASI_IO_0_2_0_RC_2023_10_18_STREAMS_STREAM_ERROR_CLOSED 1 + +typedef struct { + int32_t __handle; +} reactor_borrow_error_t; + +typedef struct { + int32_t __handle; +} reactor_borrow_input_stream_t; + +typedef struct { + uint8_t *ptr; + size_t len; +} reactor_list_u8_t; + +typedef struct { + int32_t __handle; +} reactor_borrow_output_stream_t; + +typedef struct { + int32_t __handle; +} reactor_own_pollable_t; + +typedef struct { + int32_t __handle; +} reactor_own_input_stream_t; + +// A timestamp in nanoseconds. +typedef uint64_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t; + +// A time and date in seconds plus nanoseconds. +typedef struct { + uint64_t seconds; + uint32_t nanoseconds; +} wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t; + +typedef wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t wasi_clocks_0_2_0_rc_2023_10_18_timezone_datetime_t; + +// Information useful for displaying the timezone of a specific `datetime`. +// +// This information may vary within a single `timezone` to reflect daylight +// saving time adjustments. +typedef struct { + // The number of seconds difference between UTC time and the local + // time of the timezone. + // + // The returned value will always be less than 86400 which is the + // number of seconds in a day (24*60*60). + // + // In implementations that do not expose an actual time zone, this + // should return 0. + int32_t utc_offset; + // The abbreviated name of the timezone to display to a user. The name + // `UTC` indicates Coordinated Universal Time. Otherwise, this should + // reference local standards for the name of the time zone. + // + // In implementations that do not expose an actual time zone, this + // should be the string `UTC`. + // + // In time zones that do not have an applicable name, a formatted + // representation of the UTC offset may be returned, such as `-04:00`. + reactor_string_t name; + // Whether daylight saving time is active. + // + // In implementations that do not expose an actual time zone, this + // should return false. + bool in_daylight_saving_time; +} wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_t; + +typedef wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t; + +// File size or length of a region within a file. +typedef uint64_t wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_t; + +// The type of the descriptor or file is unknown or is different from +// any of the other types specified. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_UNKNOWN 0 +// The descriptor refers to a block device inode. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_BLOCK_DEVICE 1 +// The descriptor refers to a character device inode. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_CHARACTER_DEVICE 2 +// The descriptor refers to a directory inode. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_DIRECTORY 3 +// The descriptor refers to a named pipe. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_FIFO 4 +// The file refers to a symbolic link inode. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_SYMBOLIC_LINK 5 +// The descriptor refers to a regular file inode. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_REGULAR_FILE 6 +// The descriptor refers to a socket. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_SOCKET 7 + +// Descriptor flags. +// +// Note: This was called `fdflags` in earlier versions of WASI. +typedef uint8_t wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_t; + +// Read mode: Data can be read. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_FLAGS_READ (1 << 0) +// Write mode: Data can be written to. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_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 WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_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 WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_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 WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_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 WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_FLAGS_MUTATE_DIRECTORY (1 << 5) + +// Flags determining the method of how paths are resolved. +typedef uint8_t wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t; + +// As long as the resolved path corresponds to a symbolic link, it is +// expanded. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_PATH_FLAGS_SYMLINK_FOLLOW (1 << 0) + +// Open flags used by `open-at`. +typedef uint8_t wasi_filesystem_0_2_0_rc_2023_10_18_types_open_flags_t; + +// Create file if it does not exist, similar to `O_CREAT` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_OPEN_FLAGS_CREATE (1 << 0) +// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_OPEN_FLAGS_DIRECTORY (1 << 1) +// Fail if file already exists, similar to `O_EXCL` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_OPEN_FLAGS_EXCLUSIVE (1 << 2) +// Truncate file to size 0, similar to `O_TRUNC` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_OPEN_FLAGS_TRUNCATE (1 << 3) + +// Permissions mode used by `open-at`, `change-file-permissions-at`, and +// similar. +typedef uint8_t wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t; + +// True if the resource is considered readable by the containing +// filesystem. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_MODES_READABLE (1 << 0) +// True if the resource is considered writable by the containing +// filesystem. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_MODES_WRITABLE (1 << 1) +// True if the resource is considered executable by the containing +// filesystem. This does not apply to directories. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_MODES_EXECUTABLE (1 << 2) + +// Access type used by `access-at`. +typedef struct { + uint8_t tag; + union { + wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t access; + } val; +} wasi_filesystem_0_2_0_rc_2023_10_18_types_access_type_t; + +// Test for readability, writeability, or executability. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ACCESS_TYPE_ACCESS 0 +// Test whether the path exists. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ACCESS_TYPE_EXISTS 1 + +// Number of hard links to an inode. +typedef uint64_t wasi_filesystem_0_2_0_rc_2023_10_18_types_link_count_t; + +typedef struct { + bool is_some; + wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t val; +} reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t; + +// File attributes. +// +// Note: This was called `filestat` in earlier versions of WASI. +typedef struct { + // File type. + wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_t type; + // Number of hard links to the file. + wasi_filesystem_0_2_0_rc_2023_10_18_types_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. + wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t size; + // Last data access timestamp. + // + // If the `option` is none, the platform doesn't maintain an access + // timestamp for this file. + reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_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. + reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_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. + reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t status_change_timestamp; +} wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t; + +// When setting a timestamp, this gives the value to set it to. +typedef struct { + uint8_t tag; + union { + wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t timestamp; + } val; +} wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t; + +// Leave the timestamp set to its previous value. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_NEW_TIMESTAMP_NO_CHANGE 0 +// Set the timestamp to the current time of the system clock associated +// with the filesystem. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_NEW_TIMESTAMP_NOW 1 +// Set the timestamp to the given value. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_NEW_TIMESTAMP_TIMESTAMP 2 + +// A directory entry. +typedef struct { + // The type of the file referred to by this directory entry. + wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_t type; + // The name of the object. + reactor_string_t name; +} wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; + +// Permission denied, similar to `EACCES` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_ACCESS 0 +// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_WOULD_BLOCK 1 +// Connection already in progress, similar to `EALREADY` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_ALREADY 2 +// Bad descriptor, similar to `EBADF` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_BAD_DESCRIPTOR 3 +// Device or resource busy, similar to `EBUSY` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_BUSY 4 +// Resource deadlock would occur, similar to `EDEADLK` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_DEADLOCK 5 +// Storage quota exceeded, similar to `EDQUOT` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_QUOTA 6 +// File exists, similar to `EEXIST` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_EXIST 7 +// File too large, similar to `EFBIG` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_FILE_TOO_LARGE 8 +// Illegal byte sequence, similar to `EILSEQ` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE 9 +// Operation in progress, similar to `EINPROGRESS` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_IN_PROGRESS 10 +// Interrupted function, similar to `EINTR` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_INTERRUPTED 11 +// Invalid argument, similar to `EINVAL` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_INVALID 12 +// I/O error, similar to `EIO` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_IO 13 +// Is a directory, similar to `EISDIR` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_IS_DIRECTORY 14 +// Too many levels of symbolic links, similar to `ELOOP` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_LOOP 15 +// Too many links, similar to `EMLINK` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_TOO_MANY_LINKS 16 +// Message too large, similar to `EMSGSIZE` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_MESSAGE_SIZE 17 +// Filename too long, similar to `ENAMETOOLONG` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NAME_TOO_LONG 18 +// No such device, similar to `ENODEV` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NO_DEVICE 19 +// No such file or directory, similar to `ENOENT` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NO_ENTRY 20 +// No locks available, similar to `ENOLCK` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NO_LOCK 21 +// Not enough space, similar to `ENOMEM` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_INSUFFICIENT_MEMORY 22 +// No space left on device, similar to `ENOSPC` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_INSUFFICIENT_SPACE 23 +// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NOT_DIRECTORY 24 +// Directory not empty, similar to `ENOTEMPTY` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NOT_EMPTY 25 +// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NOT_RECOVERABLE 26 +// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_UNSUPPORTED 27 +// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NO_TTY 28 +// No such device or address, similar to `ENXIO` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NO_SUCH_DEVICE 29 +// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_OVERFLOW 30 +// Operation not permitted, similar to `EPERM` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NOT_PERMITTED 31 +// Broken pipe, similar to `EPIPE` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_PIPE 32 +// Read-only file system, similar to `EROFS` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_READ_ONLY 33 +// Invalid seek, similar to `ESPIPE` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_INVALID_SEEK 34 +// Text file busy, similar to `ETXTBSY` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_TEXT_FILE_BUSY 35 +// Cross-device link, similar to `EXDEV` in POSIX. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_CROSS_DEVICE 36 + +// File or memory access pattern advisory information. +typedef uint8_t wasi_filesystem_0_2_0_rc_2023_10_18_types_advice_t; + +// The application has no advice to give on its behavior with respect +// to the specified data. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ADVICE_NORMAL 0 +// The application expects to access the specified data sequentially +// from lower offsets to higher offsets. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ADVICE_SEQUENTIAL 1 +// The application expects to access the specified data in a random +// order. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ADVICE_RANDOM 2 +// The application expects to access the specified data in the near +// future. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ADVICE_WILL_NEED 3 +// The application expects that it will not access the specified data +// in the near future. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ADVICE_DONT_NEED 4 +// The application expects to access the specified data once and then +// not reuse it thereafter. +#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ADVICE_NO_REUSE 5 + +// A 128-bit hash value, split into parts because wasm doesn't have a +// 128-bit integer type. +typedef struct { + // 64 bits of a 128-bit hash value. + uint64_t lower; + // Another 64 bits of a 128-bit hash value. + uint64_t upper; +} wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t; + +typedef struct { + int32_t __handle; +} reactor_borrow_descriptor_t; + +typedef struct { + int32_t __handle; +} reactor_own_output_stream_t; + +typedef struct { + reactor_list_u8_t f0; + bool f1; +} reactor_tuple2_list_u8_bool_t; + +typedef struct { + int32_t __handle; +} reactor_own_directory_entry_stream_t; + +typedef struct { + int32_t __handle; +} reactor_own_descriptor_t; + +typedef struct { + int32_t __handle; +} reactor_borrow_directory_entry_stream_t; + +typedef struct { + bool is_some; + wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t val; +} reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t; + +typedef struct { + reactor_own_descriptor_t f0; + reactor_string_t f1; +} reactor_tuple2_own_descriptor_string_t; + +typedef struct { + reactor_tuple2_own_descriptor_string_t *ptr; + size_t len; +} reactor_list_tuple2_own_descriptor_string_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 wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t; + +// Unknown error +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_UNKNOWN 0 +// Access denied. +// +// POSIX equivalent: EACCES, EPERM +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_ACCESS_DENIED 1 +// The operation is not supported. +// +// POSIX equivalent: EOPNOTSUPP +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NOT_SUPPORTED 2 +// One of the arguments is invalid. +// +// POSIX equivalent: EINVAL +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_INVALID_ARGUMENT 3 +// Not enough memory to complete the operation. +// +// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_OUT_OF_MEMORY 4 +// The operation timed out before it could finish completely. +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_TIMEOUT 5 +// This operation is incompatible with another asynchronous operation that is already in progress. +// +// POSIX equivalent: EALREADY +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_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 WASI_SOCKETS_0_2_0_RC_2023_10_18_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 WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK 8 +// The operation is not valid in the socket's current state. +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_INVALID_STATE 9 +// A new socket resource could not be created because of a system limit. +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_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 WASI_SOCKETS_0_2_0_RC_2023_10_18_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 WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_ADDRESS_IN_USE 12 +// The remote address is not reachable +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_REMOTE_UNREACHABLE 13 +// The connection was forcefully rejected +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONNECTION_REFUSED 14 +// The connection was reset. +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONNECTION_RESET 15 +// A connection was aborted. +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONNECTION_ABORTED 16 +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE 17 +// Name does not exist or has no suitable associated IP addresses. +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NAME_UNRESOLVABLE 18 +// A temporary failure in name resolution occurred. +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE 19 +// A permanent failure in name resolution occurred. +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE 20 + +typedef uint8_t wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t; + +// Similar to `AF_INET` in POSIX. +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4 0 +// Similar to `AF_INET6` in POSIX. +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6 1 + +typedef struct { + uint8_t f0; + uint8_t f1; + uint8_t f2; + uint8_t f3; +} wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t; + +typedef struct { + uint16_t f0; + uint16_t f1; + uint16_t f2; + uint16_t f3; + uint16_t f4; + uint16_t f5; + uint16_t f6; + uint16_t f7; +} wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t; + +typedef struct { + uint8_t tag; + union { + wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t ipv4; + wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t ipv6; + } val; +} wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_t; + +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_IPV4 0 +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_IPV6 1 + +typedef struct { + uint16_t port; + wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t address; +} wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_socket_address_t; + +typedef struct { + uint16_t port; + uint32_t flow_info; + wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t address; + uint32_t scope_id; +} wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_socket_address_t; + +typedef struct { + uint8_t tag; + union { + wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_socket_address_t ipv4; + wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_socket_address_t ipv6; + } val; +} wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t; + +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV4 0 +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV6 1 + +typedef wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t; + +typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t; + +typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t; + +typedef struct { + int32_t __handle; +} reactor_borrow_network_t; + +typedef struct { + int32_t __handle; +} reactor_own_resolve_address_stream_t; + +typedef struct { + int32_t __handle; +} reactor_borrow_resolve_address_stream_t; + +typedef struct { + bool is_some; + wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t val; +} reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t; + +typedef wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; + +typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t; + +typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_address_family_t; + +typedef uint8_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_shutdown_type_t; + +// Similar to `SHUT_RD` in POSIX. +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_TCP_SHUTDOWN_TYPE_RECEIVE 0 +// Similar to `SHUT_WR` in POSIX. +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_TCP_SHUTDOWN_TYPE_SEND 1 +// Similar to `SHUT_RDWR` in POSIX. +#define WASI_SOCKETS_0_2_0_RC_2023_10_18_TCP_SHUTDOWN_TYPE_BOTH 2 + +typedef struct { + int32_t __handle; +} reactor_borrow_tcp_socket_t; + +typedef struct { + reactor_own_input_stream_t f0; + reactor_own_output_stream_t f1; +} reactor_tuple2_own_input_stream_own_output_stream_t; + +typedef struct { + int32_t __handle; +} reactor_own_tcp_socket_t; + +typedef struct { + reactor_own_tcp_socket_t f0; + reactor_own_input_stream_t f1; + reactor_own_output_stream_t f2; +} reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t; + +typedef wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t; + +typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_ip_address_family_t; + +typedef wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; + +typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t; + +typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_address_family_t; + +typedef struct { + reactor_list_u8_t data; + wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t remote_address; +} wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t; + +typedef struct { + int32_t __handle; +} reactor_borrow_udp_socket_t; + +typedef struct { + wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ptr; + size_t len; +} reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t; + +typedef wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_error_code_t; + +typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_ip_address_family_t; + +typedef struct { + int32_t __handle; +} reactor_own_udp_socket_t; + +typedef struct { + int32_t __handle; +} reactor_own_network_t; + +typedef struct { + uint64_t f0; + uint64_t f1; +} reactor_tuple2_u64_u64_t; + +typedef struct { + reactor_string_t f0; + reactor_string_t f1; +} reactor_tuple2_string_string_t; + +typedef struct { + reactor_tuple2_string_string_t *ptr; + size_t len; +} reactor_list_tuple2_string_string_t; + +typedef struct { + reactor_string_t *ptr; + size_t len; +} reactor_list_string_t; + +typedef struct { + bool is_err; +} reactor_result_void_void_t; + +typedef struct { + int32_t __handle; +} reactor_own_terminal_input_t; + +typedef struct { + int32_t __handle; +} reactor_own_terminal_output_t; + +// Imported Functions from `wasi:clocks/wall-clock@0.2.0-rc-2023-10-18` +// 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 wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_now(wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t *ret); +// Query the resolution of the clock. +// +// The nanoseconds field of the output is always less than 1000000000. +extern void wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_resolution(wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t *ret); + +// Imported Functions from `wasi:io/poll@0.2.0-rc-2023-10-18` +// 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 wasi_io_0_2_0_rc_2023_10_18_poll_poll_list(reactor_list_borrow_pollable_t *in, reactor_list_u32_t *ret); +// Poll for completion on a single pollable. +// +// This function is similar to `poll-list`, but operates on only a single +// pollable. When it returns, the handle is ready for I/O. +extern void wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(reactor_borrow_pollable_t in); + +// Imported Functions from `wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18` +// 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 wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_now(void); +// Query the resolution of the clock. +extern wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_resolution(void); +// Create a `pollable` which will resolve once the specified time has been +// reached. +extern reactor_own_pollable_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_subscribe(wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t when, bool absolute); + +// Imported Functions from `wasi:clocks/timezone@0.2.0-rc-2023-10-18` +// Return information needed to display the given `datetime`. This includes +// the UTC offset, the time zone name, and a flag indicating whether +// daylight saving time is active. +// +// If the timezone cannot be determined for the given `datetime`, return a +// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight +// saving time. +extern void wasi_clocks_0_2_0_rc_2023_10_18_timezone_display(wasi_clocks_0_2_0_rc_2023_10_18_timezone_datetime_t *when, wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_t *ret); +// The same as `display`, but only return the UTC offset. +extern int32_t wasi_clocks_0_2_0_rc_2023_10_18_timezone_utc_offset(wasi_clocks_0_2_0_rc_2023_10_18_timezone_datetime_t *when); + +// Imported Functions from `wasi:io/streams@0.2.0-rc-2023-10-18` +// Returns a string that's suitable to assist humans in debugging this +// error. +// +// The returned string will change across platforms and hosts which +// means that parsing it, for example, would be a +// platform-compatibility hazard. +extern void wasi_io_0_2_0_rc_2023_10_18_streams_method_error_to_debug_string(reactor_borrow_error_t self, reactor_string_t *ret); +// Perform a non-blocking read from the stream. +// +// This function returns a list of bytes containing the data that was +// read, along with a `stream-status` which, indicates whether further +// reads are expected to produce data. The returned list will contain up to +// `len` bytes; it may return fewer than requested, but not more. An +// empty list and `stream-status:open` indicates no more data is +// available at this time, and that the pollable given by `subscribe` +// will be ready when more data is available. +// +// Once a stream has reached the end, subsequent calls to `read` or +// `skip` will always report `stream-status:ended` rather than producing more +// data. +// +// When the caller gives a `len` of 0, it represents a request to read 0 +// bytes. This read should always succeed and return an empty list and +// the current `stream-status`. +// +// 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 wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_read(reactor_borrow_input_stream_t self, uint64_t len, reactor_list_u8_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); +// Read bytes from a stream, after blocking until at least one byte can +// be read. Except for blocking, identical to `read`. +extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_read(reactor_borrow_input_stream_t self, uint64_t len, reactor_list_u8_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); +// Skip bytes from a stream. +// +// This is similar to the `read` function, but avoids copying the +// bytes into the instance. +// +// Once a stream has reached the end, subsequent calls to read or +// `skip` will always report end-of-stream rather than producing more +// data. +// +// This function returns the number of bytes skipped, along with a +// `stream-status` indicating whether the end of the stream was +// reached. The returned value will be at most `len`; it may be less. +extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_skip(reactor_borrow_input_stream_t self, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_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 wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_skip(reactor_borrow_input_stream_t self, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_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 reactor_own_pollable_t wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe(reactor_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 wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_check_write(reactor_borrow_output_stream_t self, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); +// Perform a write. This function never blocks. +// +// 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 wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write(reactor_borrow_output_stream_t self, reactor_list_u8_t *contents, wasi_io_0_2_0_rc_2023_10_18_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 + // poll-one(pollable); + // 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` + // poll-one(pollable); + // // Check for any errors that arose during `flush` + // let _ = this.check-write(); // eliding error handling + // ``` + extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_and_flush(reactor_borrow_output_stream_t self, reactor_list_u8_t *contents, wasi_io_0_2_0_rc_2023_10_18_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 wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_flush(reactor_borrow_output_stream_t self, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); + // Request to flush buffered output, and block until flush completes + // and stream is ready for writing again. + extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_flush(reactor_borrow_output_stream_t self, wasi_io_0_2_0_rc_2023_10_18_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 reactor_own_pollable_t wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe(reactor_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 wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write_zeroes(reactor_borrow_output_stream_t self, uint64_t len, wasi_io_0_2_0_rc_2023_10_18_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 + // poll-one(pollable); + // 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` + // poll-one(pollable); + // // Check for any errors that arose during `flush` + // let _ = this.check-write(); // eliding error handling + // ``` + extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_zeroes_and_flush(reactor_borrow_output_stream_t self, uint64_t len, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); + // Read from one stream and write to another. + // + // This function returns the number of bytes transferred; it may be less + // than `len`. + // + // Unlike other I/O functions, this function blocks until all the data + // read from the input stream has been written to the output stream. + extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_splice(reactor_borrow_output_stream_t self, reactor_own_input_stream_t src, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_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 at least + // one byte can be read. + extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_splice(reactor_borrow_output_stream_t self, reactor_own_input_stream_t src, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); + // Forward the entire contents of an input stream to an output stream. + // + // This function repeatedly reads from the input stream and writes + // the data to the output stream, until the end of the input stream + // is reached, or an error is encountered. + // + // Unlike other I/O functions, this function blocks until the end + // of the input stream is seen and all the data has been written to + // the output stream. + // + // This function returns the number of bytes transferred, and the status of + // the output stream. + extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_forward(reactor_borrow_output_stream_t self, reactor_own_input_stream_t src, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); + + // Imported Functions from `wasi:filesystem/types@0.2.0-rc-2023-10-18` + // 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_via_stream(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, reactor_own_input_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write_via_stream(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, reactor_own_output_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_append_via_stream(reactor_borrow_descriptor_t self, reactor_own_output_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); + // Provide file advisory information on a descriptor. + // + // This is similar to `posix_fadvise` in POSIX. + extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_advise(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t length, wasi_filesystem_0_2_0_rc_2023_10_18_types_advice_t advice, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync_data(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_flags(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_type(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_size(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t size, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_access_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_modification_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t length, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, reactor_tuple2_list_u8_bool_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write(reactor_borrow_descriptor_t self, reactor_list_u8_t *buffer, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_directory(reactor_borrow_descriptor_t self, reactor_own_directory_entry_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); + // Create a directory. + // + // Note: This is similar to `mkdirat` in POSIX. + extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_create_directory_at(reactor_borrow_descriptor_t self, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_access_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_modification_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); + // Create a hard link. + // + // Note: This is similar to `linkat` in POSIX. + extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_link_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t old_path_flags, reactor_string_t *old_path, reactor_borrow_descriptor_t new_descriptor, reactor_string_t *new_path, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_open_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_open_flags_t open_flags, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_t flags, wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t modes, reactor_own_descriptor_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_readlink_at(reactor_borrow_descriptor_t self, reactor_string_t *path, reactor_string_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_remove_directory_at(reactor_borrow_descriptor_t self, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); + // Rename a filesystem object. + // + // Note: This is similar to `renameat` in POSIX. + extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_rename_at(reactor_borrow_descriptor_t self, reactor_string_t *old_path, reactor_borrow_descriptor_t new_descriptor, reactor_string_t *new_path, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_symlink_at(reactor_borrow_descriptor_t self, reactor_string_t *old_path, reactor_string_t *new_path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); + // Check accessibility of a filesystem path. + // + // Check whether the given filesystem path names an object which is + // readable, writable, or executable, or whether it exists. + // + // This does not a guarantee that subsequent accesses will succeed, as + // filesystem permissions may be modified asynchronously by external + // entities. + // + // Note: This is similar to `faccessat` with the `AT_EACCESS` flag in POSIX. + extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_access_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_access_type_t *type, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlink_file_at(reactor_borrow_descriptor_t self, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); + // Change the permissions of a filesystem object that is not a directory. + // + // Note that the ultimate meanings of these permissions is + // filesystem-specific. + // + // Note: This is similar to `fchmodat` in POSIX. + extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_file_permissions_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t modes, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); + // Change the permissions of a directory. + // + // Note that the ultimate meanings of these permissions is + // filesystem-specific. + // + // Unlike in POSIX, the `executable` flag is not reinterpreted as a "search" + // flag. `read` on a directory implies readability and searchability, and + // `execute` is not valid for directories. + // + // Note: This is similar to `fchmodat` in POSIX. + extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_directory_permissions_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t modes, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); + // Request a shared advisory lock for an open file. + // + // This requests a *shared* lock; more than one shared lock can be held for + // a file at the same time. + // + // If the open file has an exclusive lock, this function downgrades the lock + // to a shared lock. If it has a shared lock, this function has no effect. + // + // This requests an *advisory* lock, meaning that the file could be accessed + // by other programs that don't hold the lock. + // + // It is unspecified how shared locks interact with locks acquired by + // non-WASI programs. + // + // This function blocks until the lock can be acquired. + // + // Not all filesystems support locking; on filesystems which don't support + // locking, this function returns `error-code::unsupported`. + // + // Note: This is similar to `flock(fd, LOCK_SH)` in Unix. + extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_shared(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); + // Request an exclusive advisory lock for an open file. + // + // This requests an *exclusive* lock; no other locks may be held for the + // file while an exclusive lock is held. + // + // If the open file has a shared lock and there are no exclusive locks held + // for the file, this function upgrades the lock to an exclusive lock. If the + // open file already has an exclusive lock, this function has no effect. + // + // This requests an *advisory* lock, meaning that the file could be accessed + // by other programs that don't hold the lock. + // + // It is unspecified whether this function succeeds if the file descriptor + // is not opened for writing. It is unspecified how exclusive locks interact + // with locks acquired by non-WASI programs. + // + // This function blocks until the lock can be acquired. + // + // Not all filesystems support locking; on filesystems which don't support + // locking, this function returns `error-code::unsupported`. + // + // Note: This is similar to `flock(fd, LOCK_EX)` in Unix. + extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_exclusive(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); + // Request a shared advisory lock for an open file. + // + // This requests a *shared* lock; more than one shared lock can be held for + // a file at the same time. + // + // If the open file has an exclusive lock, this function downgrades the lock + // to a shared lock. If it has a shared lock, this function has no effect. + // + // This requests an *advisory* lock, meaning that the file could be accessed + // by other programs that don't hold the lock. + // + // It is unspecified how shared locks interact with locks acquired by + // non-WASI programs. + // + // This function returns `error-code::would-block` if the lock cannot be + // acquired. + // + // Not all filesystems support locking; on filesystems which don't support + // locking, this function returns `error-code::unsupported`. + // + // Note: This is similar to `flock(fd, LOCK_SH | LOCK_NB)` in Unix. + extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_shared(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); + // Request an exclusive advisory lock for an open file. + // + // This requests an *exclusive* lock; no other locks may be held for the + // file while an exclusive lock is held. + // + // If the open file has a shared lock and there are no exclusive locks held + // for the file, this function upgrades the lock to an exclusive lock. If the + // open file already has an exclusive lock, this function has no effect. + // + // This requests an *advisory* lock, meaning that the file could be accessed + // by other programs that don't hold the lock. + // + // It is unspecified whether this function succeeds if the file descriptor + // is not opened for writing. It is unspecified how exclusive locks interact + // with locks acquired by non-WASI programs. + // + // This function returns `error-code::would-block` if the lock cannot be + // acquired. + // + // Not all filesystems support locking; on filesystems which don't support + // locking, this function returns `error-code::unsupported`. + // + // Note: This is similar to `flock(fd, LOCK_EX | LOCK_NB)` in Unix. + extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_exclusive(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); + // Release a shared or exclusive lock on an open file. + // + // Note: This is similar to `flock(fd, LOCK_UN)` in Unix. + extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlock(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_is_same_object(reactor_borrow_descriptor_t self, reactor_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); + // Read a single directory entry from a `directory-entry-stream`. + extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_directory_entry_stream_read_directory_entry(reactor_borrow_directory_entry_stream_t self, reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_filesystem_error_code(reactor_borrow_error_t err, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *ret); + + // Imported Functions from `wasi:filesystem/preopens@0.2.0-rc-2023-10-18` + // Return the set of preopened directories, and their path. + extern void wasi_filesystem_0_2_0_rc_2023_10_18_preopens_get_directories(reactor_list_tuple2_own_descriptor_string_t *ret); + + // Imported Functions from `wasi:sockets/instance-network@0.2.0-rc-2023-10-18` + // Get a handle to the default network. + extern reactor_own_network_t wasi_sockets_0_2_0_rc_2023_10_18_instance_network_instance_network(void); + + // Imported Functions from `wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18` + // Resolve an internet host name to a list of IP addresses. + // + // See the wasi-socket proposal README.md for a comparison with getaddrinfo. + // + // # Parameters + // - `name`: The name to look up. IP addresses are not allowed. Unicode domain names are automatically converted + // to ASCII using IDNA encoding. + // - `address-family`: If provided, limit the results to addresses of this specific address family. + // - `include-unavailable`: When set to true, this function will also return addresses of which the runtime + // thinks (or knows) can't be connected to at the moment. For example, this will return IPv6 addresses on + // systems without an active IPv6 interface. Notes: + // - Even when no public IPv6 interfaces are present or active, names like "localhost" can still resolve to an IPv6 address. + // - Whatever is "available" or "unavailable" is volatile and can change everytime a network cable is unplugged. + // + // 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. + // + // At the moment, the stream never completes successfully with 0 items. Ie. the first call + // to `resolve-next-address` never returns `ok(none)`. This may change in the future. + // + // # Typical errors + // - `invalid-argument`: `name` is a syntactically invalid domain name. + // - `invalid-argument`: `name` is an IP address. + // - `not-supported`: The specified `address-family` is not supported. (EAI_FAMILY) + // + // # References: + // - + // - + // - + // - + extern bool wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_addresses(reactor_borrow_network_t network, reactor_string_t *name, wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t *maybe_address_family, bool include_unavailable, reactor_own_resolve_address_stream_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_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 wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_resolve_next_address(reactor_borrow_resolve_address_stream_t self, reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_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 reactor_own_pollable_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_subscribe(reactor_borrow_resolve_address_stream_t self); + + // Imported Functions from `wasi:sockets/tcp@0.2.0-rc-2023-10-18` + // 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. + // + // When a socket is not explicitly bound, the first invocation to a listen or connect operation will + // implicitly bind the socket. + // + // Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + // + // # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL) + // - `invalid-state`: The socket is already bound. (EINVAL) + // + // # Typical `finish` errors + // - `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) + // + // # References + // - + // - + // - + // - + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_bind(reactor_borrow_tcp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *local_address, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_bind(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_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 + // + // POSIX mentions: + // > If connect() fails, the state of the socket is unspecified. Conforming applications should + // > close the file descriptor and create a new socket before attempting to reconnect. + // + // WASI prescribes the following behavior: + // - If `connect` fails because an input/state validation error, the socket should remain usable. + // - If a connection was actually attempted but failed, the socket should become unusable for further network communication. + // Besides `drop`, any method after such a failure may return an error. + // + // # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL, EADDRNOTAVAIL on Illumos) + // - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + // - `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 Connection state. (EISCONN) + // - `invalid-state`: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows) + // + // # Typical `finish` errors + // - `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) + // - `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) + // + // # References + // - + // - + // - + // - + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_connect(reactor_borrow_tcp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *remote_address, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_connect(reactor_borrow_tcp_socket_t self, reactor_tuple2_own_input_stream_own_output_stream_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + // Start listening for new connections. + // + // Transitions the socket into the Listener state. + // + // Unlike POSIX: + // - this function is async. This enables interactive WASI hosts to inject permission prompts. + // - the socket must already be explicitly bound. + // + // # Typical `start` errors + // - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) + // - `invalid-state`: The socket is already in the Connection state. (EISCONN, EINVAL on BSD) + // - `invalid-state`: The socket is already in the Listener state. + // + // # Typical `finish` errors + // - `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) + // + // # References + // - + // - + // - + // - + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_listen(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_listen(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + // Accept a new client socket. + // + // The returned socket is bound and in the Connection state. The following properties are inherited from the listener socket: + // - `address-family` + // - `ipv6-only` + // - `keep-alive` + // - `no-delay` + // - `unicast-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 Listener 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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_accept(reactor_borrow_tcp_socket_t self, reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_local_address(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_remote_address(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + // Whether this is a IPv4 or IPv6 socket. + // + // Equivalent to the SO_DOMAIN socket option. + extern wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(reactor_borrow_tcp_socket_t self); + // Whether IPv4 compatibility (dual-stack) mode is disabled or not. + // + // Equivalent to the IPV6_V6ONLY socket option. + // + // # Typical errors + // - `invalid-state`: (set) The socket is already bound. + // - `not-supported`: (get/set) `this` socket is an IPv4 socket. + // - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_ipv6_only(reactor_borrow_tcp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_ipv6_only(reactor_borrow_tcp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + // Hints the desired listen queue size. Implementations are free to ignore this. + // + // # Typical errors + // - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. + // - `invalid-state`: (set) The socket is already in the Connection state. + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_listen_backlog_size(reactor_borrow_tcp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + // Equivalent to the SO_KEEPALIVE socket option. + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_keep_alive(reactor_borrow_tcp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_keep_alive(reactor_borrow_tcp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + // Equivalent to the TCP_NODELAY socket option. + // + // The default value is `false`. + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_no_delay(reactor_borrow_tcp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_no_delay(reactor_borrow_tcp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + // Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. + // + // # Typical errors + // - `invalid-argument`: (set) The TTL value must be 1 or higher. + // - `invalid-state`: (set) The socket is already in the Connection state. + // - `invalid-state`: (set) The socket is already in the Listener state. + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_unicast_hop_limit(reactor_borrow_tcp_socket_t self, uint8_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_unicast_hop_limit(reactor_borrow_tcp_socket_t self, uint8_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + // The kernel buffer space reserved for sends/receives on this socket. + // + // Note #1: an implementation may choose to cap or round the buffer size when setting the value. + // In other words, after setting a value, reading the same setting back may return a different value. + // + // Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of + // actual data to be sent/received by the application, because the kernel might also use the buffer space + // for internal metadata structures. + // + // Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. + // + // # Typical errors + // - `invalid-state`: (set) The socket is already in the Connection state. + // - `invalid-state`: (set) The socket is already in the Listener state. + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_receive_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_receive_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_send_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_send_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 reactor_own_pollable_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(reactor_borrow_tcp_socket_t self); + // Initiate a graceful shutdown. + // + // - receive: the socket is not expecting to receive any more data from the peer. All subsequent read + // operations on the `input-stream` associated with this socket will return an End Of Stream indication. + // Any data still in the receive queue at time of calling `shutdown` will be discarded. + // - send: the socket is not expecting to send any more data to the peer. All subsequent write + // operations on the `output-stream` associated with this socket will return an error. + // - both: same effect as receive & send combined. + // + // The shutdown function does not close (drop) the socket. + // + // # Typical errors + // - `invalid-state`: The socket is not in the Connection state. (ENOTCONN) + // + // # References + // - + // - + // - + // - + extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_shutdown(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_shutdown_type_t shutdown_type, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); + + // Imported Functions from `wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18` + // Create a new TCP socket. + // + // Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. + // + // 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`/`listen`/`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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_create_tcp_socket(wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_ip_address_family_t address_family, reactor_own_tcp_socket_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t *err); + + // Imported Functions from `wasi:sockets/udp@0.2.0-rc-2023-10-18` + // 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. + // + // When a socket is not explicitly bound, the first invocation to connect will implicitly bind the socket. + // + // Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + // + // # Typical `start` errors + // - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) + // - `invalid-state`: The socket is already bound. (EINVAL) + // + // # Typical `finish` errors + // - `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) + // + // # References + // - + // - + // - + // - + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_bind(reactor_borrow_udp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *local_address, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_bind(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); + // Set the destination address. + // + // The local-address is updated based on the best network path to `remote-address`. + // + // When a destination address is set: + // - all receive operations will only return datagrams sent from the provided `remote-address`. + // - the `send` function can only be used to send to this destination. + // + // Note that this function does not generate any network traffic and the peer is not aware of this "connection". + // + // Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + // + // # Typical `start` errors + // - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) + // - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + // - `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 already bound to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. + // + // # Typical `finish` errors + // - `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) + // + // # References + // - + // - + // - + // - + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_connect(reactor_borrow_udp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *remote_address, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_connect(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); + // 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. + // If `max-results` is 0, this function returns successfully with an empty list. + // + // # Typical errors + // - `invalid-state`: The socket is not bound to any local address. (EINVAL) + // - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN) + // - `would-block`: There is no pending data available to be read at the moment. (EWOULDBLOCK, EAGAIN) + // + // # References + // - + // - + // - + // - + // - + // - + // - + // - + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive(reactor_borrow_udp_socket_t self, uint64_t max_results, reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_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 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)`. + // + // The remote address option is required. To send a message to the "connected" peer, + // call `remote-address` to get their address. + // + // # Typical errors + // - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) + // - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + // - `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 the `datagram.remote-address` does not match the address passed to `connect`. (EISCONN) + // - `invalid-state`: The socket is not bound to any local address. Unlike POSIX, this function does not perform an implicit bind. + // - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN) + // - `datagram-too-large`: The datagram is too large. (EMSGSIZE) + // - `would-block`: The send buffer is currently full. (EWOULDBLOCK, EAGAIN) + // + // # References + // - + // - + // - + // - + // - + // - + // - + // - + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send(reactor_borrow_udp_socket_t self, reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *datagrams, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_local_address(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); + // Get the address set with `connect`. + // + // # Typical errors + // - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) + // + // # References + // - + // - + // - + // - + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_remote_address(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); + // Whether this is a IPv4 or IPv6 socket. + // + // Equivalent to the SO_DOMAIN socket option. + extern wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_address_family(reactor_borrow_udp_socket_t self); + // Whether IPv4 compatibility (dual-stack) mode is disabled or not. + // + // Equivalent to the IPV6_V6ONLY socket option. + // + // # Typical errors + // - `not-supported`: (get/set) `this` socket is an IPv4 socket. + // - `invalid-state`: (set) The socket is already bound. + // - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_ipv6_only(reactor_borrow_udp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_ipv6_only(reactor_borrow_udp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); + // Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_unicast_hop_limit(reactor_borrow_udp_socket_t self, uint8_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_unicast_hop_limit(reactor_borrow_udp_socket_t self, uint8_t value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); + // The kernel buffer space reserved for sends/receives on this socket. + // + // Note #1: an implementation may choose to cap or round the buffer size when setting the value. + // In other words, after setting a value, reading the same setting back may return a different value. + // + // Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of + // actual data to be sent/received by the application, because the kernel might also use the buffer space + // for internal metadata structures. + // + // Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive_buffer_size(reactor_borrow_udp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_receive_buffer_size(reactor_borrow_udp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send_buffer_size(reactor_borrow_udp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); + extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_send_buffer_size(reactor_borrow_udp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_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 reactor_own_pollable_t wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_subscribe(reactor_borrow_udp_socket_t self); + + // Imported Functions from `wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18` + // Create a new UDP socket. + // + // Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX. + // + // 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 wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_create_udp_socket(wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_ip_address_family_t address_family, reactor_own_udp_socket_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_error_code_t *err); + + // Imported Functions from `wasi:random/random@0.2.0-rc-2023-10-18` + // 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 wasi_random_0_2_0_rc_2023_10_18_random_get_random_bytes(uint64_t len, reactor_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 wasi_random_0_2_0_rc_2023_10_18_random_get_random_u64(void); + + // Imported Functions from `wasi:random/insecure@0.2.0-rc-2023-10-18` + // 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 wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_bytes(uint64_t len, reactor_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 wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_u64(void); + + // Imported Functions from `wasi:random/insecure-seed@0.2.0-rc-2023-10-18` + // 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 wasi_random_0_2_0_rc_2023_10_18_insecure_seed_insecure_seed(reactor_tuple2_u64_u64_t *ret); + + // Imported Functions from `wasi:cli/environment@0.2.0-rc-2023-10-18` + // 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 wasi_cli_0_2_0_rc_2023_10_18_environment_get_environment(reactor_list_tuple2_string_string_t *ret); + // Get the POSIX-style arguments to the program. + extern void wasi_cli_0_2_0_rc_2023_10_18_environment_get_arguments(reactor_list_string_t *ret); + // Return a path that programs should use as their initial current working + // directory, interpreting `.` as shorthand for this. + extern bool wasi_cli_0_2_0_rc_2023_10_18_environment_initial_cwd(reactor_string_t *ret); + + // Imported Functions from `wasi:cli/exit@0.2.0-rc-2023-10-18` + // Exit the current instance and any linked instances. + extern void wasi_cli_0_2_0_rc_2023_10_18_exit_exit(reactor_result_void_void_t *status); + + // Imported Functions from `wasi:cli/stdin@0.2.0-rc-2023-10-18` + extern reactor_own_input_stream_t wasi_cli_0_2_0_rc_2023_10_18_stdin_get_stdin(void); + + // Imported Functions from `wasi:cli/stdout@0.2.0-rc-2023-10-18` + extern reactor_own_output_stream_t wasi_cli_0_2_0_rc_2023_10_18_stdout_get_stdout(void); + + // Imported Functions from `wasi:cli/stderr@0.2.0-rc-2023-10-18` + extern reactor_own_output_stream_t wasi_cli_0_2_0_rc_2023_10_18_stderr_get_stderr(void); + + // Imported Functions from `wasi:cli/terminal-stdin@0.2.0-rc-2023-10-18` + // If stdin is connected to a terminal, return a `terminal-input` handle + // allowing further interaction with it. + extern bool wasi_cli_0_2_0_rc_2023_10_18_terminal_stdin_get_terminal_stdin(reactor_own_terminal_input_t *ret); + + // Imported Functions from `wasi:cli/terminal-stdout@0.2.0-rc-2023-10-18` + // If stdout is connected to a terminal, return a `terminal-output` handle + // allowing further interaction with it. + extern bool wasi_cli_0_2_0_rc_2023_10_18_terminal_stdout_get_terminal_stdout(reactor_own_terminal_output_t *ret); + + // Imported Functions from `wasi:cli/terminal-stderr@0.2.0-rc-2023-10-18` + // If stderr is connected to a terminal, return a `terminal-output` handle + // allowing further interaction with it. + extern bool wasi_cli_0_2_0_rc_2023_10_18_terminal_stderr_get_terminal_stderr(reactor_own_terminal_output_t *ret); + + // Helper Functions + + void reactor_borrow_pollable_free(reactor_borrow_pollable_t *ptr); + void reactor_list_borrow_pollable_free(reactor_list_borrow_pollable_t *ptr); + void reactor_list_u32_free(reactor_list_u32_t *ptr); + void reactor_own_error_free(reactor_own_error_t *ptr); + void wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_free(wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *ptr); + void reactor_borrow_error_free(reactor_borrow_error_t *ptr); + void reactor_borrow_input_stream_free(reactor_borrow_input_stream_t *ptr); + void reactor_list_u8_free(reactor_list_u8_t *ptr); + void reactor_borrow_output_stream_free(reactor_borrow_output_stream_t *ptr); + void reactor_own_pollable_free(reactor_own_pollable_t *ptr); + void reactor_own_input_stream_free(reactor_own_input_stream_t *ptr); + void wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_free(wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_t *ptr); + void wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_free(wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t *ptr); + void reactor_borrow_descriptor_free(reactor_borrow_descriptor_t *ptr); + void reactor_own_output_stream_free(reactor_own_output_stream_t *ptr); + void reactor_tuple2_list_u8_bool_free(reactor_tuple2_list_u8_bool_t *ptr); + void reactor_own_directory_entry_stream_free(reactor_own_directory_entry_stream_t *ptr); + void reactor_own_descriptor_free(reactor_own_descriptor_t *ptr); + void reactor_borrow_directory_entry_stream_free(reactor_borrow_directory_entry_stream_t *ptr); + void reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_free(reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t *ptr); + void reactor_tuple2_own_descriptor_string_free(reactor_tuple2_own_descriptor_string_t *ptr); + void reactor_list_tuple2_own_descriptor_string_free(reactor_list_tuple2_own_descriptor_string_t *ptr); + void reactor_borrow_network_free(reactor_borrow_network_t *ptr); + void reactor_own_resolve_address_stream_free(reactor_own_resolve_address_stream_t *ptr); + void reactor_borrow_resolve_address_stream_free(reactor_borrow_resolve_address_stream_t *ptr); + void reactor_borrow_tcp_socket_free(reactor_borrow_tcp_socket_t *ptr); + void reactor_tuple2_own_input_stream_own_output_stream_free(reactor_tuple2_own_input_stream_own_output_stream_t *ptr); + void reactor_own_tcp_socket_free(reactor_own_tcp_socket_t *ptr); + void reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_free(reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ptr); + void wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_free(wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ptr); + void reactor_borrow_udp_socket_free(reactor_borrow_udp_socket_t *ptr); + void reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_free(reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ptr); + void reactor_own_udp_socket_free(reactor_own_udp_socket_t *ptr); + void reactor_own_network_free(reactor_own_network_t *ptr); + void reactor_tuple2_string_string_free(reactor_tuple2_string_string_t *ptr); + void reactor_list_tuple2_string_string_free(reactor_list_tuple2_string_string_t *ptr); + void reactor_list_string_free(reactor_list_string_t *ptr); + void reactor_own_terminal_input_free(reactor_own_terminal_input_t *ptr); + void reactor_own_terminal_output_free(reactor_own_terminal_output_t *ptr); + // Transfers ownership of `s` into the string `ret` + void reactor_string_set(reactor_string_t *ret, char*s); + + // Creates a copy of the input nul-terminate string `s` and + // stores it into the component model string `ret`. + void reactor_string_dup(reactor_string_t *ret, const char*s); + + // Deallocates the string pointed to by `ret`, deallocating + // the memory behind the string. + void reactor_string_free(reactor_string_t *ret); + + // Functions for working with resource `wasi:filesystem/types@0.2.0-rc-2023-10-18/directory-entry-stream` + reactor_borrow_directory_entry_stream_t wasi_filesystem_0_2_0_rc_2023_10_18_types_borrow_directory_entry_stream(reactor_own_directory_entry_stream_t); + void wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_stream_drop_own(reactor_own_directory_entry_stream_t); + extern void reactor_directory_entry_stream_drop_borrow(reactor_borrow_directory_entry_stream_t); + + // Functions for working with resource `wasi:io/streams@0.2.0-rc-2023-10-18/output-stream` + reactor_borrow_output_stream_t wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(reactor_own_output_stream_t); + void wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(reactor_own_output_stream_t); + extern void reactor_output_stream_drop_borrow(reactor_borrow_output_stream_t); + + // Functions for working with resource `wasi:io/streams@0.2.0-rc-2023-10-18/error` + reactor_borrow_error_t wasi_io_0_2_0_rc_2023_10_18_streams_borrow_error(reactor_own_error_t); + void wasi_io_0_2_0_rc_2023_10_18_streams_error_drop_own(reactor_own_error_t); + extern void reactor_error_drop_borrow(reactor_borrow_error_t); + + // Functions for working with resource `wasi:io/poll@0.2.0-rc-2023-10-18/pollable` + reactor_borrow_pollable_t wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(reactor_own_pollable_t); + void wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(reactor_own_pollable_t); + extern void reactor_pollable_drop_borrow(reactor_borrow_pollable_t); + + // Functions for working with resource `wasi:sockets/tcp@0.2.0-rc-2023-10-18/tcp-socket` + reactor_borrow_tcp_socket_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(reactor_own_tcp_socket_t); + void wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(reactor_own_tcp_socket_t); + extern void reactor_tcp_socket_drop_borrow(reactor_borrow_tcp_socket_t); + + // Functions for working with resource `wasi:cli/terminal-input@0.2.0-rc-2023-10-18/terminal-input` + void wasi_cli_0_2_0_rc_2023_10_18_terminal_input_terminal_input_drop_own(reactor_own_terminal_input_t); + + // Functions for working with resource `wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18/resolve-address-stream` + reactor_borrow_resolve_address_stream_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_borrow_resolve_address_stream(reactor_own_resolve_address_stream_t); + void wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_address_stream_drop_own(reactor_own_resolve_address_stream_t); + extern void reactor_resolve_address_stream_drop_borrow(reactor_borrow_resolve_address_stream_t); + + // Functions for working with resource `wasi:cli/terminal-output@0.2.0-rc-2023-10-18/terminal-output` + void wasi_cli_0_2_0_rc_2023_10_18_terminal_output_terminal_output_drop_own(reactor_own_terminal_output_t); + + // Functions for working with resource `wasi:sockets/network@0.2.0-rc-2023-10-18/network` + reactor_borrow_network_t wasi_sockets_0_2_0_rc_2023_10_18_network_borrow_network(reactor_own_network_t); + void wasi_sockets_0_2_0_rc_2023_10_18_network_network_drop_own(reactor_own_network_t); + extern void reactor_network_drop_borrow(reactor_borrow_network_t); + + // Functions for working with resource `wasi:io/streams@0.2.0-rc-2023-10-18/input-stream` + reactor_borrow_input_stream_t wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(reactor_own_input_stream_t); + void wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(reactor_own_input_stream_t); + extern void reactor_input_stream_drop_borrow(reactor_borrow_input_stream_t); + + // Functions for working with resource `wasi:filesystem/types@0.2.0-rc-2023-10-18/descriptor` + reactor_borrow_descriptor_t wasi_filesystem_0_2_0_rc_2023_10_18_types_borrow_descriptor(reactor_own_descriptor_t); + void wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_drop_own(reactor_own_descriptor_t); + extern void reactor_descriptor_drop_borrow(reactor_borrow_descriptor_t); + + // Functions for working with resource `wasi:sockets/udp@0.2.0-rc-2023-10-18/udp-socket` + reactor_borrow_udp_socket_t wasi_sockets_0_2_0_rc_2023_10_18_udp_borrow_udp_socket(reactor_own_udp_socket_t); + void wasi_sockets_0_2_0_rc_2023_10_18_udp_udp_socket_drop_own(reactor_own_udp_socket_t); + extern void reactor_udp_socket_drop_borrow(reactor_borrow_udp_socket_t); + + #ifdef __cplusplus + } + #endif + #endif + \ No newline at end of file From 95454e857a5ac82a4bdfbb9979d8b63abac51969 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 29 Nov 2023 13:26:02 -0700 Subject: [PATCH 02/63] support non-blocking sockets Signed-off-by: Joel Dice --- .../src/libc/sys/socket/getsockopt.c | 83 ++++++++++++------- .../cloudlibc/src/libc/sys/socket/recv.c | 36 +++++--- .../cloudlibc/src/libc/sys/socket/send.c | 41 ++++++--- .../cloudlibc/src/libc/sys/socket/socket.c | 40 +++++---- .../headers/private/descriptor_table.h | 15 +++- .../headers/public/__header_sys_socket.h | 1 + 6 files changed, 148 insertions(+), 68 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c index 1fe41c4e3..658e97995 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c @@ -4,45 +4,66 @@ #include -#include +#include #include #include +#include int getsockopt(int socket, int level, int option_name, - void *restrict option_value, socklen_t *restrict option_len) { - // Only support SOL_SOCKET options for now. - if (level != SOL_SOCKET) { - errno = ENOPROTOOPT; - return -1; - } + void* restrict option_value, socklen_t* restrict option_len) +{ + // Only support SOL_SOCKET options for now. + if (level != SOL_SOCKET) { + errno = ENOPROTOOPT; + return -1; + } - int value; - switch (option_name) { + int value; + switch (option_name) { case SO_TYPE: { - // Return the type of the socket. This information can simply be - // obtained by looking at the file descriptor type. - __wasi_fdstat_t fsb; - if (__wasi_fd_fdstat_get(socket, &fsb) != 0) { - errno = EBADF; - return -1; - } - if (fsb.fs_filetype != __WASI_FILETYPE_SOCKET_DGRAM && - fsb.fs_filetype != __WASI_FILETYPE_SOCKET_STREAM) { - errno = ENOTSOCK; - return -1; - } - value = fsb.fs_filetype; - break; + // Return the type of the socket. This information can simply be + // obtained by looking at the file descriptor type. + __wasi_fdstat_t fsb; + if (__wasi_fd_fdstat_get(socket, &fsb) != 0) { + errno = EBADF; + return -1; + } + if (fsb.fs_filetype != __WASI_FILETYPE_SOCKET_DGRAM && fsb.fs_filetype != __WASI_FILETYPE_SOCKET_STREAM) { + errno = ENOTSOCK; + return -1; + } + value = fsb.fs_filetype; + break; + } + case SO_ERROR: { + descriptor_table_variant_t variant; + if (!descriptor_table_get(socket, &variant)) { + errno = EBADF; + return -1; + } + + if (variant.tag == DESCRIPTOR_TABLE_VARIANT_TCP_ERROR) { + // TODO: map variant.value.tcp_error.error to appropriate ERRNO + errno = EBADF; + descriptor_table_variant_t new_variant = { .tag = DESCRIPTOR_TABLE_VARIANT_TCP_NEW, + .value = { .tcp_new = variant.value.tcp_error.socket } }; + if (!descriptor_table_update(socket, new_variant)) { + abort(); + } + return -1; + } else { + return 0; + } } default: { - errno = ENOPROTOOPT; - return -1; + errno = ENOPROTOOPT; + return -1; + } } - } - // Copy out integer value. - memcpy(option_value, &value, - *option_len < sizeof(int) ? *option_len : sizeof(int)); - *option_len = sizeof(int); - return 0; + // Copy out integer value. + memcpy(option_value, &value, + *option_len < sizeof(int) ? *option_len : sizeof(int)); + *option_len = sizeof(int); + return 0; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index 8cf00a35e..cdde554af 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -47,16 +47,18 @@ ssize_t recv(int socket, void* restrict buffer, size_t length, int flags) errno = EOPNOTSUPP; return -1; } - + descriptor_table_variant_t variant; if (!descriptor_table_get(socket, &variant)) { errno = EBADF; return -1; } + bool blocking; reactor_own_input_stream_t rx; switch (variant.tag) { case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED: + blocking = variant.value.tcp_connected.socket.blocking; rx = variant.value.tcp_connected.rx; break; @@ -66,16 +68,28 @@ ssize_t recv(int socket, void* restrict buffer, size_t length, int flags) } reactor_borrow_input_stream_t rx_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(rx); - reactor_list_u8_t result; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; - if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_read(rx_borrow, length, &result, &error)) { - // TODO: map errors appropriately - errno = EACCES; - return -1; - } + while (true) { + reactor_list_u8_t result; + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; + if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_read(rx_borrow, length, &result, &error)) { + // TODO: map errors appropriately + errno = EBADF; + return -1; + } - memcpy(buffer, result.ptr, result.len); - reactor_list_u8_free(&result); - return result.len; + if (result.len) { + memcpy(buffer, result.ptr, result.len); + reactor_list_u8_free(&result); + return result.len; + } else if (blocking) { + reactor_own_pollable_t pollable = wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe(rx_borrow); + reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(pollable); + wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(pollable); + } else { + errno = EAGAIN; + return -1; + } + } #endif } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c index 1315ce326..318763b6e 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c @@ -40,9 +40,11 @@ ssize_t send(int socket, const void* buffer, size_t length, int flags) return -1; } + bool blocking; reactor_own_output_stream_t tx; switch (variant.tag) { case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED: + blocking = variant.value.tcp_connected.socket.blocking; tx = variant.value.tcp_connected.tx; break; @@ -51,18 +53,35 @@ ssize_t send(int socket, const void* buffer, size_t length, int flags) return -1; } - // TODO: handle non-blocking sends. Also, when in blocking mode, only block - // long enough to send at least one byte (i.e. use `check_write`, `write`, - // and `poll_one` instead of `blocking_write_and_flush`. reactor_borrow_output_stream_t tx_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(tx); - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; - reactor_list_u8_t list = { .ptr = (uint8_t*)buffer, .len = length }; - if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_and_flush(tx_borrow, &list, &error)) { - // TODO: map errors appropriately - errno = EACCES; - return -1; - } + while (true) { + wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; + uint64_t count; + if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_check_write(tx_borrow, &count, &error)) { + // TODO: map errors appropriately + errno = EBADF; + return -1; + } - return length; + if (count) { + count = count < length ? count : length; + reactor_list_u8_t list = { .ptr = (uint8_t*)buffer, .len = count }; + if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write(tx_borrow, &list, &error)) { + // TODO: map errors appropriately + errno = EBADF; + return -1; + } else { + return count; + } + } else if (blocking) { + reactor_own_pollable_t pollable = wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe(tx_borrow); + reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(pollable); + wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(pollable); + } else { + errno = EAGAIN; + return -1; + } + } #endif } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c index b5f7fc075..9fd05ae5c 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c @@ -1,4 +1,3 @@ -#include #include #include @@ -21,14 +20,14 @@ int socket(int domain, int type, int protocol) return -1; } - switch (type) { + switch (type & ~(SOCK_NONBLOCK | SOCK_CLOEXEC)) { case SOCK_STREAM: { wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t error; reactor_own_tcp_socket_t socket; if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_create_tcp_socket( family, &socket, &error)) { descriptor_table_variant_t variant = { .tag = DESCRIPTOR_TABLE_VARIANT_TCP_NEW, - .value = { .tcp_new = socket } }; + .value = { .tcp_new = { .socket = socket, .blocking = (type & SOCK_NONBLOCK) == 0 } } }; int fd; if (!descriptor_table_insert(variant, &fd)) { errno = ENOMEM; @@ -37,7 +36,7 @@ int socket(int domain, int type, int protocol) return fd; } else { // TODO: map errors appropriately - errno = EACCES; + errno = EBADF; return -1; } } @@ -61,13 +60,14 @@ int connect(int fd, struct sockaddr* address, socklen_t len) return -1; } - reactor_own_tcp_socket_t socket; + descriptor_table_tcp_new_t socket; switch (variant.tag) { case DESCRIPTOR_TABLE_VARIANT_TCP_NEW: socket = variant.value.tcp_new; break; case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED: + // TODO: should we disallow re-connecting an already-connected socket? socket = variant.value.tcp_connected.socket; break; @@ -76,6 +76,8 @@ int connect(int fd, struct sockaddr* address, socklen_t len) return -1; } + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket.socket); + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t ip_address; switch (address->sa_family) { case AF_INET: { @@ -123,35 +125,45 @@ int connect(int fd, struct sockaddr* address, socklen_t len) reactor_own_network_t network = wasi_sockets_0_2_0_rc_2023_10_18_instance_network_instance_network(); wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t error; - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket); reactor_borrow_network_t network_borrow = wasi_sockets_0_2_0_rc_2023_10_18_network_borrow_network(network); bool result = wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_connect(socket_borrow, network_borrow, &ip_address, &error); wasi_sockets_0_2_0_rc_2023_10_18_network_network_drop_own(network); if (!result) { // TODO: map errors appropriately - errno = EACCES; + errno = EBADF; return -1; } - // TODO: handle non-blocking connects reactor_tuple2_own_input_stream_own_output_stream_t rx_tx; while (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_connect(socket_borrow, &rx_tx, &error)) { if (error == WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK) { - reactor_own_pollable_t pollable = wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(socket_borrow); - reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(pollable); - wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); - wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(pollable); + if (socket.blocking) { + reactor_own_pollable_t pollable = wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(socket_borrow); + reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(pollable); + wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(pollable); + } else { + descriptor_table_variant_t new_variant = { .tag = DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTING, + .value = { .tcp_new = socket } }; + if (!descriptor_table_update(fd, new_variant)) { + abort(); + } + errno = EINPROGRESS; + return -1; + } } else { // TODO: map errors appropriately - errno = EACCES; + errno = EBADF; return -1; } } descriptor_table_variant_t new_variant = { .tag = DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED, .value = { .tcp_connected = { .socket = socket, .rx = rx_tx.f0, .tx = rx_tx.f1 } } }; - assert(descriptor_table_update(fd, new_variant)); + if (!descriptor_table_update(fd, new_variant)) { + abort(); + } return 0; } diff --git a/libc-bottom-half/headers/private/descriptor_table.h b/libc-bottom-half/headers/private/descriptor_table.h index 96cce2c94..44fa5e539 100644 --- a/libc-bottom-half/headers/private/descriptor_table.h +++ b/libc-bottom-half/headers/private/descriptor_table.h @@ -5,18 +5,31 @@ typedef enum { DESCRIPTOR_TABLE_VARIANT_TCP_NEW, + DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTING, DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED, + DESCRIPTOR_TABLE_VARIANT_TCP_ERROR, } descriptor_table_tag_t; typedef struct { reactor_own_tcp_socket_t socket; + bool blocking; +} descriptor_table_tcp_new_t; + +typedef struct { + descriptor_table_tcp_new_t socket; reactor_own_input_stream_t rx; reactor_own_output_stream_t tx; } descriptor_table_tcp_connected_t; +typedef struct { + descriptor_table_tcp_new_t socket; + wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t error_code; +} descriptor_table_tcp_error_t; + typedef union { - reactor_own_tcp_socket_t tcp_new; + descriptor_table_tcp_new_t tcp_new; descriptor_table_tcp_connected_t tcp_connected; + descriptor_table_tcp_error_t tcp_error; } descriptor_table_value_t; typedef struct { diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index 8ba4eff4a..5b9c3136e 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -24,6 +24,7 @@ #define SOL_SOCKET 0x7fffffff #define SO_TYPE 3 +#define SO_ERROR 4 #define PF_UNSPEC 0 #define PF_INET 1 From e961d20517090f021bbb93a74f374878ce330c6a Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 30 Nov 2023 12:05:54 -0700 Subject: [PATCH 03/63] close Preview 2 handles in close(2) Signed-off-by: Joel Dice --- .../libc/sys/wasi_preview2/descriptor_table.c | 24 ++++++----- .../sources/__wasilibc_fd_renumber.c | 40 ++++++++++++++++--- 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c index bc907fd86..59af53737 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c @@ -2,12 +2,12 @@ * This file provides a global hashtable for tracking `wasi-libc`-managed file * descriptors. * - * WASI Preview 2 has no notion of file descriptors and instead uses - * non-forgeable resource handles. Moreover, there's not necessarily a - * one-to-one correspondence between POSIX file descriptors and resource handles - * (e.g. a TCP connection may require separate handles for reading, writing, and - * polling the same connection). We use this table to map each POSIX descriptor - * to a set of one or more handles. + * WASI Preview 2 has no notion of file descriptors and instead uses unforgeable + * resource handles. Moreover, there's not necessarily a one-to-one + * correspondence between POSIX file descriptors and resource handles (e.g. a + * TCP connection may require separate handles for reading, writing, and polling + * the same connection). We use this table to map each POSIX descriptor to a + * set of one or more handles. * * As of this writing, we still rely on the WASI Preview 1 adapter * (https://github.com/bytecodealliance/wasmtime/tree/main/crates/wasi-preview1-component-adapter) @@ -22,7 +22,6 @@ */ #include -#include #include @@ -33,6 +32,13 @@ static bool wasi_preview1_adapter_open_badfd(int* fd) return __wasi_preview1_adapter_open_badfd((int32_t)fd) != 0; } +__attribute__((__import_module__("wasi_snapshot_preview1"), __import_name__("adapter_close_badfd"))) extern int32_t __wasi_preview1_adapter_close_badfd(int32_t); + +static bool wasi_preview1_adapter_close_badfd(int fd) +{ + return __wasi_preview1_adapter_close_badfd(fd) != 0; +} + /* * This hash table is based on the one in musl/src/search/hsearch.c, but uses * integer keys and supports a `remove` operation. Note that I've switched from @@ -227,7 +233,7 @@ bool descriptor_table_insert(descriptor_table_variant_t variant, int* fd) if (insert(variant, *fd, &global_table)) { return true; } else { - if (__wasi_fd_close(*fd) != 0) { + if (!wasi_preview1_adapter_close_badfd(*fd)) { abort(); } *fd = -1; @@ -251,7 +257,7 @@ bool descriptor_table_get(int fd, descriptor_table_variant_t* variant) bool descriptor_table_remove(int fd, descriptor_table_variant_t* variant) { if (remove(fd, variant, &global_table)) { - if (__wasi_fd_close(fd) != 0) { + if (!wasi_preview1_adapter_close_badfd(fd)) { abort(); } return true; diff --git a/libc-bottom-half/sources/__wasilibc_fd_renumber.c b/libc-bottom-half/sources/__wasilibc_fd_renumber.c index 47992e91f..7f32366bf 100644 --- a/libc-bottom-half/sources/__wasilibc_fd_renumber.c +++ b/libc-bottom-half/sources/__wasilibc_fd_renumber.c @@ -3,6 +3,8 @@ #include #include +#include + int __wasilibc_fd_renumber(int fd, int newfd) { // Scan the preopen fds before making any changes. __wasilibc_populate_preopens(); @@ -19,13 +21,39 @@ int close(int fd) { // Scan the preopen fds before making any changes. __wasilibc_populate_preopens(); - __wasi_errno_t error = __wasi_fd_close(fd); - if (error != 0) { - errno = error; - return -1; - } + descriptor_table_variant_t variant; + if (descriptor_table_remove(fd, &variant)) { + switch (variant.tag) { + case DESCRIPTOR_TABLE_VARIANT_TCP_NEW: + case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTING: + wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(variant.value.tcp_new.socket); + break; + + case DESCRIPTOR_TABLE_VARIANT_TCP_ERROR: + wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(variant.value.tcp_error.socket.socket); + break; + + case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED: + wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(variant.value.tcp_connected.rx); + wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(variant.value.tcp_connected.tx); + wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(variant.value.tcp_connected.socket.socket); + break; - return 0; + default: + errno = EBADF; + return -1; + } + + return 0; + } else { + __wasi_errno_t error = __wasi_fd_close(fd); + if (error != 0) { + errno = error; + return -1; + } + + return 0; + } } weak void __wasilibc_populate_preopens(void) { From 9d98fe311282feaf2fdedee5d505461373d6a737 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 1 Dec 2023 13:56:04 -0700 Subject: [PATCH 04/63] add getaddrinfo and setsockopt, etc. Signed-off-by: Joel Dice --- Makefile | 2 +- .../src/libc/sys/socket/getsockopt.c | 16 ++-- .../cloudlibc/src/libc/sys/socket/netdb.c | 14 +++ .../src/libc/sys/socket/setsockopt.c | 91 +++++++++++++++++++ .../cloudlibc/src/libc/sys/socket/socket.c | 2 +- .../headers/public/__header_sys_socket.h | 1 + libc-top-half/musl/include/sys/socket.h | 4 +- 7 files changed, 116 insertions(+), 14 deletions(-) create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/socket/setsockopt.c diff --git a/Makefile b/Makefile index 2d2d425ee..cf93d7a67 100644 --- a/Makefile +++ b/Makefile @@ -112,6 +112,7 @@ LIBC_TOP_HALF_MUSL_SOURCES = \ network/inet_aton.c \ network/in6addr_any.c \ network/in6addr_loopback.c \ + network/gai_strerror.c \ fenv/fenv.c \ fenv/fesetround.c \ fenv/feupdateenv.c \ @@ -445,7 +446,6 @@ MUSL_OMIT_HEADERS += \ "sys/auxv.h" \ "pwd.h" "shadow.h" "grp.h" \ "mntent.h" \ - "netdb.h" \ "resolv.h" \ "pty.h" \ "setjmp.h" \ diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c index 658e97995..c6bfc67cf 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c @@ -18,7 +18,6 @@ int getsockopt(int socket, int level, int option_name, return -1; } - int value; switch (option_name) { case SO_TYPE: { // Return the type of the socket. This information can simply be @@ -32,8 +31,13 @@ int getsockopt(int socket, int level, int option_name, errno = ENOTSOCK; return -1; } - value = fsb.fs_filetype; - break; + int value = fsb.fs_filetype; + + // Copy out integer value. + memcpy(option_value, &value, + *option_len < sizeof(int) ? *option_len : sizeof(int)); + *option_len = sizeof(int); + return 0; } case SO_ERROR: { descriptor_table_variant_t variant; @@ -60,10 +64,4 @@ int getsockopt(int socket, int level, int option_name, return -1; } } - - // Copy out integer value. - memcpy(option_value, &value, - *option_len < sizeof(int) ? *option_len : sizeof(int)); - *option_len = sizeof(int); - return 0; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c new file mode 100644 index 000000000..4aeabca80 --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c @@ -0,0 +1,14 @@ +#include +#include + +int getaddrinfo(const char *restrict host, const char *restrict serv, const struct addrinfo *restrict hint, struct addrinfo **restrict res) +{ + // TODO + abort(); +} + +void freeaddrinfo(struct addrinfo *p) +{ + // TODO + abort(); +} diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/setsockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/setsockopt.c new file mode 100644 index 000000000..6c810b7c3 --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/setsockopt.c @@ -0,0 +1,91 @@ +#include +#include +#include +#include +#include + +int setsockopt(int fd, int level, int option_name, const void* option_value, socklen_t option_len) +{ + descriptor_table_variant_t variant; + if (!descriptor_table_get(fd, &variant)) { + errno = EBADF; + return -1; + } + + reactor_own_tcp_socket_t socket; + switch (variant.tag) { + case DESCRIPTOR_TABLE_VARIANT_TCP_NEW: + case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTING: + socket = variant.value.tcp_new.socket; + break; + + case DESCRIPTOR_TABLE_VARIANT_TCP_ERROR: + socket = variant.value.tcp_error.socket.socket; + break; + + case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED: + socket = variant.value.tcp_connected.socket.socket; + break; + + default: + errno = EBADF; + return -1; + } + + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket); + + switch (level) { + case IPPROTO_TCP: { + switch (option_name) { + case TCP_NODELAY: { + if (option_len != sizeof(int)) { + errno = EDOM; + return -1; + } + + wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t error; + if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_no_delay(socket_borrow, *((int*)option_value) != 0, &error)) { + return 0; + } else { + // TODO: map errors appropriately + errno = EBADF; + return -1; + } + } + default: { + errno = ENOPROTOOPT; + return -1; + } + } + } + + case SOL_SOCKET: { + switch (option_name) { + case SO_KEEPALIVE: { + if (option_len != sizeof(int)) { + errno = EDOM; + return -1; + } + + wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t error; + if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_keep_alive(socket_borrow, *((int*)option_value) != 0, &error)) { + return 0; + } else { + // TODO: map errors appropriately + errno = EBADF; + return -1; + } + } + default: { + errno = ENOPROTOOPT; + return -1; + } + } + } + + default: { + errno = ENOPROTOOPT; + return -1; + } + } +} diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c index 9fd05ae5c..b9e3bc50d 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c @@ -52,7 +52,7 @@ int socket(int domain, int type, int protocol) } } -int connect(int fd, struct sockaddr* address, socklen_t len) +int connect(int fd, const struct sockaddr* address, socklen_t len) { descriptor_table_variant_t variant; if (!descriptor_table_get(fd, &variant)) { diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index 5b9c3136e..d2b4f950e 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -25,6 +25,7 @@ #define SO_TYPE 3 #define SO_ERROR 4 +#define SO_KEEPALIVE 9 #define PF_UNSPEC 0 #define PF_INET 1 diff --git a/libc-top-half/musl/include/sys/socket.h b/libc-top-half/musl/include/sys/socket.h index 4d574c662..94a0581ed 100644 --- a/libc-top-half/musl/include/sys/socket.h +++ b/libc-top-half/musl/include/sys/socket.h @@ -395,18 +395,16 @@ struct sockaddr_storage { #include <__struct_sockaddr_storage.h> #endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no socket/socketpair */ int socket (int, int, int); +#ifdef __wasilibc_unmodified_upstream /* WASI has no socketpair */ int socketpair (int, int, int, int [2]); #endif int shutdown (int, int); -#ifdef __wasilibc_unmodified_upstream /* WASI has no bind/connect/listen/accept */ int bind (int, const struct sockaddr *, socklen_t); int connect (int, const struct sockaddr *, socklen_t); int listen (int, int); -#endif int accept (int, struct sockaddr *__restrict, socklen_t *__restrict); int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); From 1937e9422834fce8bf5dc286991b563892cc859a Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Sun, 3 Dec 2023 17:56:45 +0100 Subject: [PATCH 05/63] Implement TCP based on preview2 wasi-sockets --- .../cloudlibc/src/libc/sys/socket/__utils.c | 177 +++++++ .../cloudlibc/src/libc/sys/socket/__utils.h | 14 + .../cloudlibc/src/libc/sys/socket/accept.c | 148 ++++++ .../cloudlibc/src/libc/sys/socket/bind.c | 75 +++ .../cloudlibc/src/libc/sys/socket/connect.c | 115 +++++ .../src/libc/sys/socket/getsockopt.c | 69 --- .../src/libc/sys/socket/getsockpeername.c | 129 +++++ .../cloudlibc/src/libc/sys/socket/listen.c | 96 ++++ .../cloudlibc/src/libc/sys/socket/recv.c | 103 ++-- .../cloudlibc/src/libc/sys/socket/send.c | 94 ++-- .../cloudlibc/src/libc/sys/socket/shutdown.c | 82 ++- .../cloudlibc/src/libc/sys/socket/socket.c | 188 ++----- .../cloudlibc/src/libc/sys/socket/sockopt.c | 470 ++++++++++++++++++ .../libc/sys/wasi_preview2/descriptor_table.c | 67 +-- .../headers/private/descriptor_table.h | 82 ++- .../headers/public/__header_sys_socket.h | 23 + libc-bottom-half/sources/accept.c | 51 -- libc-top-half/musl/include/sys/socket.h | 15 +- 18 files changed, 1551 insertions(+), 447 deletions(-) create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c delete mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c delete mode 100644 libc-bottom-half/sources/accept.c diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c new file mode 100644 index 000000000..d54076473 --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c @@ -0,0 +1,177 @@ +#include +#include + +#include "__utils.h" + +static reactor_own_network_t global_network; +static bool global_network_initialized = false; + +reactor_borrow_network_t __wasi_sockets_utils__borrow_network() { + if (!global_network_initialized) { + global_network = wasi_sockets_0_2_0_rc_2023_10_18_instance_network_instance_network(); + global_network_initialized = true; + } + + return wasi_sockets_0_2_0_rc_2023_10_18_network_borrow_network(global_network); +} + +int __wasi_sockets_utils__map_error(wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_error) { + switch (wasi_error) + { + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_ACCESS_DENIED: return EACCES; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NOT_SUPPORTED: return EOPNOTSUPP; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_INVALID_ARGUMENT: return EINVAL; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_OUT_OF_MEMORY: return ENOMEM; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_TIMEOUT: return ETIMEDOUT; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONCURRENCY_CONFLICT: return EALREADY; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK: return EWOULDBLOCK; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NEW_SOCKET_LIMIT: return EMFILE; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_ADDRESS_NOT_BINDABLE: return EADDRNOTAVAIL; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_ADDRESS_IN_USE: return EADDRINUSE; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_REMOTE_UNREACHABLE: return EHOSTUNREACH; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONNECTION_REFUSED: return ECONNREFUSED; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONNECTION_RESET: return ECONNRESET; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONNECTION_ABORTED: return ECONNABORTED; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE: return EMSGSIZE; + + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_INVALID_STATE: + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NOT_IN_PROGRESS: + assert(false /* If our internal state checks are working right, these errors should never show up. */); + break; + + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NAME_UNRESOLVABLE: + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE: + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE: + assert(false /* These errors are specific to getaddrinfo, which should have filtered these errors out before calling this generic method */); + break; + + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_UNKNOWN: + default: + return EOPNOTSUPP; + } +} + +bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen_t len, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* output, int* error) +{ + *error = 0; + + socklen_t smallest_sockaddr_size = sizeof(struct sockaddr); + if (address == NULL || len < smallest_sockaddr_size) { + *error = EINVAL; + return false; + } + + switch (address->sa_family) { + case AF_INET: { + if (len < sizeof(struct sockaddr_in)) { + *error = EINVAL; + return false; + } + + struct sockaddr_in* ipv4 = (struct sockaddr_in*)address; + unsigned ip = ipv4->sin_addr.s_addr; + unsigned short port = ipv4->sin_port; + *output = (wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t){ + .tag = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV4, + .val = { .ipv4 = { + .port = ntohs(port), // (port << 8) | (port >> 8), + .address = { ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24 }, + } }, + }; + return true; + } + case AF_INET6: { + if (len < sizeof(struct sockaddr_in6)) { + *error = EINVAL; + return false; + } + + struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)address; + unsigned char* ip = (unsigned char*)&(ipv6->sin6_addr.s6_addr); + unsigned short port = ipv6->sin6_port; + *output = (wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t){ + .tag = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV6, + .val = { .ipv6 = { + .port = ntohs(port), + .address = { + (((unsigned short)ip[0]) << 8) | ip[1], + (((unsigned short)ip[2]) << 8) | ip[3], + (((unsigned short)ip[4]) << 8) | ip[5], + (((unsigned short)ip[6]) << 8) | ip[7], + (((unsigned short)ip[8]) << 8) | ip[9], + (((unsigned short)ip[10]) << 8) | ip[11], + (((unsigned short)ip[12]) << 8) | ip[13], + (((unsigned short)ip[14]) << 8) | ip[15], + }, + // TODO: do these need to be endian-reversed? + .flow_info = ipv6->sin6_flowinfo, + .scope_id = ipv6->sin6_scope_id, + } } + }; + return true; + } + default: + *error = EAFNOSUPPORT; + return false; + } +} + +bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address, struct sockaddr* output_addr, socklen_t* output_addrlen, int* error) { + *error = 0; + + if (output_addr == NULL || output_addrlen == NULL) { + *error = EINVAL; + return false; + } + + switch (address->tag) + { + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV4: { + if (*output_addrlen < sizeof(struct sockaddr_in)) { + *error = EINVAL; + return false; + } + *output_addrlen = sizeof(struct sockaddr_in); + struct sockaddr_in* ipv4 = (struct sockaddr_in*)output_addr; + + wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t ip = address->val.ipv4.address; + + *ipv4 = (struct sockaddr_in) { + .sin_family = AF_INET, + .sin_port = htons(address->val.ipv4.port), + .sin_addr = { .s_addr = 0 }, // TODO + }; + return true; + } + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV6: { + if (*output_addrlen < sizeof(struct sockaddr_in6)) { + *error = EINVAL; + return false; + } + *output_addrlen = sizeof(struct sockaddr_in6); + struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)output_addr; + + wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t ip = address->val.ipv6.address; + + *ipv6 = (struct sockaddr_in6) { + .sin6_family = AF_INET, + .sin6_port = htons(address->val.ipv6.port), + .sin6_addr = { .s6_addr = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, // TODO + // TODO: do these need to be endian-reversed? + .sin6_flowinfo = address->val.ipv6.flow_info, + .sin6_scope_id = address->val.ipv6.scope_id, + }; + return true; + } + default: /* unreachable */ abort(); + } +} + +int __wasi_sockets_utils__posix_family(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_family) { + switch (wasi_family) + { + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4: return AF_INET; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6: return AF_INET6; + default: /* unreachable */ abort(); + } +} \ No newline at end of file diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h new file mode 100644 index 000000000..a0a3333de --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h @@ -0,0 +1,14 @@ +#ifndef __wasi_sockets_utils_h +#define __wasi_sockets_utils_h + +#include + +#include + +reactor_borrow_network_t __wasi_sockets_utils__borrow_network(); +int __wasi_sockets_utils__map_error(wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_error); +bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen_t len, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* output, int* error); +bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address, struct sockaddr* output_addr, socklen_t* output_addrlen, int* error); +int __wasi_sockets_utils__posix_family(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_family); + +#endif \ No newline at end of file diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c new file mode 100644 index 000000000..2418ee1e6 --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c @@ -0,0 +1,148 @@ +#include +#include +#include + +#include +#include "__utils.h" + +bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address, int* out_errno) { + + tcp_socket_state_listening_t listener; + if (socket->state_tag == TCP_SOCKET_STATE_LISTENING) { + listener = socket->state.listening; + } else { + *out_errno = EINVAL; + return false; + } + + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + + reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t client_and_io; + wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; + while (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_accept(socket_borrow, &client_and_io, &error)) { + if (error == WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK) { + if (socket->blocking) { + reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(socket->socket_pollable); + wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + } else { + *out_errno = EWOULDBLOCK; + return false; + } + } else { + *out_errno = __wasi_sockets_utils__map_error(error); + return false; + } + } + + reactor_own_tcp_socket_t client = client_and_io.f0; + reactor_borrow_tcp_socket_t client_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(client); + + reactor_own_pollable_t client_pollable = wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(client_borrow); + + reactor_own_input_stream_t input = client_and_io.f1; + reactor_borrow_input_stream_t input_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(input); + reactor_own_pollable_t input_pollable = wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe(input_borrow); + + reactor_own_output_stream_t output = client_and_io.f2; + reactor_borrow_output_stream_t output_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(output); + reactor_own_pollable_t output_pollable = wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe(output_borrow); + + if (out_address != NULL) { + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_remote_address(client_borrow, out_address, &error)) { + // TODO: How to recover from this in a POSIX compatible way? + abort(); + } + } + + descriptor_table_entry_t client_entry = { + .tag = DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, + .value = { .tcp_socket = { + .socket = client, + .socket_pollable = client_pollable, + .blocking = client_blocking, + .state_tag = TCP_SOCKET_STATE_CONNECTED, + .state = { .connected = { + .input = input, + .input_pollable = input_pollable, + .output = output, + .output_pollable = output_pollable, + } }, + } }, + }; + + if (!descriptor_table_insert(client_entry, out_clientfd)) { + *out_errno = EMFILE; + return false; + } + + return true; +} + +bool udp_accept(udp_socket_t* socket, bool client_blocking, int* out_clientfd, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address, int* out_errno) { + // UDP doesn't support accept + *out_errno = EOPNOTSUPP; + return false; +} + + +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; + if (!descriptor_table_get_ref(socket, &entry)) { + errno = EBADF; + return -1; + } + + if (addr != NULL) { + if (addrlen == NULL || *addrlen == 0) { + errno = EINVAL; + return -1; + } + } else { + if (addrlen != NULL && *addrlen == 0) { + errno = EINVAL; + return -1; + } + } + + bool client_blocking = (flags & SOCK_NONBLOCK) == 0; + // Ignore SOCK_CLOEXEC flag. That concept does not exist in WASI. + + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t out_address; + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address_ptr = addr != NULL ? &out_address : NULL; + + int client_fd; + int err; + switch (entry->tag) + { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + if (!tcp_accept(&entry->value.tcp_socket, client_blocking, &client_fd, out_address_ptr, &err)) { + errno = err; + return -1; + } + break; + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + if (!udp_accept(&entry->value.udp_socket, client_blocking, &client_fd, out_address_ptr, &err)) { + errno = err; + return -1; + } + break; + default: + errno = EOPNOTSUPP; + return -1; + } + + if (addr != NULL) { + assert(out_address_ptr != NULL); + + if (!__wasi_sockets_utils__format_address(&out_address, addr, addrlen, &err)) { + abort(); // TODO: validate provided buffer length _before_ doing the actual accept wasi call. + } + } + + return client_fd; +} diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c new file mode 100644 index 000000000..3cb4577c1 --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c @@ -0,0 +1,75 @@ +#include +#include + +#include +#include "__utils.h" + +int tcp_bind(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) { + + tcp_socket_state_unbound_t unbound; + if (socket->state_tag == TCP_SOCKET_STATE_UNBOUND) { + unbound = socket->state.unbound; + } else { + errno = EINVAL; + return -1; + } + + wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; + reactor_borrow_network_t network_borrow = __wasi_sockets_utils__borrow_network(); + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_bind(socket_borrow, network_borrow, address, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + // Bind has successfully started. Attempt to finish it: + while (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_bind(socket_borrow, &error)) { + if (error == WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK) { + reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(socket->socket_pollable); + wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + } else { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + } + + // Bind successful. + + socket->state_tag = TCP_SOCKET_STATE_BOUND; + socket->state = (tcp_socket_state_t){ .bound = { /* No additional state */ } }; + return 0; +} + +int udp_bind(udp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) { + // TODO: implement + errno = EOPNOTSUPP; + return -1; +} + +int bind(int socket, const struct sockaddr* addr, socklen_t addrlen) { + + descriptor_table_entry_t* entry; + if (!descriptor_table_get_ref(socket, &entry)) { + errno = EBADF; + return -1; + } + + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t ip_address; + int parse_err; + if (!__wasi_sockets_utils__parse_address(addr, addrlen, &ip_address, &parse_err)) { + errno = parse_err; + return -1; + } + + switch (entry->tag) + { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + return tcp_bind(&entry->value.tcp_socket, &ip_address); + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + return udp_bind(&entry->value.udp_socket, &ip_address); + default: + errno = EOPNOTSUPP; + return -1; + } +} diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c new file mode 100644 index 000000000..ee143cab2 --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c @@ -0,0 +1,115 @@ +#include +#include + +#include +#include "__utils.h" + + +int tcp_connect(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) +{ + switch (socket->state_tag) { + case TCP_SOCKET_STATE_UNBOUND: + case TCP_SOCKET_STATE_BOUND: + // These can initiate a connect. + break; + case TCP_SOCKET_STATE_CONNECTING: + errno = EALREADY; + return -1; + case TCP_SOCKET_STATE_CONNECTED: + errno = EISCONN; + return -1; + case TCP_SOCKET_STATE_CONNECT_FAILED: // POSIX: "If connect() fails, the state of the socket is unspecified. Conforming applications should close the file descriptor and create a new socket before attempting to reconnect." + case TCP_SOCKET_STATE_LISTENING: + default: + errno = EOPNOTSUPP; + return -1; + } + + wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; + reactor_borrow_network_t network_borrow = __wasi_sockets_utils__borrow_network(); + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_connect(socket_borrow, network_borrow, address, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + // Connect has successfully started. + socket->state_tag = TCP_SOCKET_STATE_CONNECTING; + socket->state = (tcp_socket_state_t){ .connecting = { /* No additional state */ } }; + + // Attempt to finish it: + reactor_tuple2_own_input_stream_own_output_stream_t io; + while (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_connect(socket_borrow, &io, &error)) { + if (error == WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK) { + if (socket->blocking) { + reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(socket->socket_pollable); + wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + } else { + errno = EINPROGRESS; + return -1; + } + } else { + socket->state_tag = TCP_SOCKET_STATE_CONNECT_FAILED; + socket->state = (tcp_socket_state_t){ .connect_failed = { + .error_code = error, + } }; + + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + } + + // Connect successful. + + reactor_own_input_stream_t input = io.f0; + reactor_borrow_input_stream_t input_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(input); + reactor_own_pollable_t input_pollable = wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe(input_borrow); + + reactor_own_output_stream_t output = io.f1; + reactor_borrow_output_stream_t output_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(output); + reactor_own_pollable_t output_pollable = wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe(output_borrow); + + socket->state_tag = TCP_SOCKET_STATE_CONNECTED; + socket->state = (tcp_socket_state_t){ .connected = { + .input = input, + .input_pollable = input_pollable, + .output = output, + .output_pollable = output_pollable, + } }; + return 0; +} + +int udp_connect(udp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) +{ + // TODO: implement + errno = EOPNOTSUPP; + return -1; +} + +int connect(int fd, const struct sockaddr* address, socklen_t len) +{ + descriptor_table_entry_t* entry; + if (!descriptor_table_get_ref(fd, &entry)) { + errno = EBADF; + return -1; + } + + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t ip_address; + int parse_err; + if (!__wasi_sockets_utils__parse_address(address, len, &ip_address, &parse_err)) { + errno = parse_err; + return -1; + } + + switch (entry->tag) + { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + return tcp_connect(&entry->value.tcp_socket, &ip_address); + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + return udp_connect(&entry->value.udp_socket, &ip_address); + default: + errno = EOPNOTSUPP; + return -1; + } +} diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c deleted file mode 100644 index 658e97995..000000000 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include -#include -#include - -int getsockopt(int socket, int level, int option_name, - void* restrict option_value, socklen_t* restrict option_len) -{ - // Only support SOL_SOCKET options for now. - if (level != SOL_SOCKET) { - errno = ENOPROTOOPT; - return -1; - } - - int value; - switch (option_name) { - case SO_TYPE: { - // Return the type of the socket. This information can simply be - // obtained by looking at the file descriptor type. - __wasi_fdstat_t fsb; - if (__wasi_fd_fdstat_get(socket, &fsb) != 0) { - errno = EBADF; - return -1; - } - if (fsb.fs_filetype != __WASI_FILETYPE_SOCKET_DGRAM && fsb.fs_filetype != __WASI_FILETYPE_SOCKET_STREAM) { - errno = ENOTSOCK; - return -1; - } - value = fsb.fs_filetype; - break; - } - case SO_ERROR: { - descriptor_table_variant_t variant; - if (!descriptor_table_get(socket, &variant)) { - errno = EBADF; - return -1; - } - - if (variant.tag == DESCRIPTOR_TABLE_VARIANT_TCP_ERROR) { - // TODO: map variant.value.tcp_error.error to appropriate ERRNO - errno = EBADF; - descriptor_table_variant_t new_variant = { .tag = DESCRIPTOR_TABLE_VARIANT_TCP_NEW, - .value = { .tcp_new = variant.value.tcp_error.socket } }; - if (!descriptor_table_update(socket, new_variant)) { - abort(); - } - return -1; - } else { - return 0; - } - } - default: { - errno = ENOPROTOOPT; - return -1; - } - } - - // Copy out integer value. - memcpy(option_value, &value, - *option_len < sizeof(int) ? *option_len : sizeof(int)); - *option_len = sizeof(int); - return 0; -} diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c new file mode 100644 index 000000000..53c0148c9 --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c @@ -0,0 +1,129 @@ +#include +#include + +#include +#include "__utils.h" + +bool tcp_getsockname(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address) +{ + wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_local_address(socket_borrow, out_address, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return false; + } + + return true; +} + +bool tcp_getpeername(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address) +{ + wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_remote_address(socket_borrow, out_address, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return false; + } + + return true; +} + +bool udp_getsockname(udp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address) +{ + // TODO: implement + errno = EOPNOTSUPP; + return -1; +} + +bool udp_getpeername(udp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address) +{ + // TODO: implement + errno = EOPNOTSUPP; + return -1; +} + +int getsockname(int socket, struct sockaddr *__restrict addr, socklen_t *__restrict addrlen) +{ + descriptor_table_entry_t* entry; + if (!descriptor_table_get_ref(socket, &entry)) { + errno = EBADF; + return -1; + } + + if (addr == NULL || addrlen == NULL || *addrlen == 0) { + errno = EINVAL; + return -1; + } + + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t out_address; + + switch (entry->tag) + { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + if (!tcp_getsockname(&entry->value.tcp_socket, &out_address)) { + // errno is set by tcp_getsockname + return -1; + } + break; + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + if (!udp_getsockname(&entry->value.udp_socket, &out_address)) { + // errno is set by udp_getsockname + return -1; + } + break; + default: + errno = EOPNOTSUPP; + return -1; + } + + int err; + if (!__wasi_sockets_utils__format_address(&out_address, addr, addrlen, &err)) { + errno = err; + return -1; + } + + return 0; +} + +int getpeername(int socket, struct sockaddr *__restrict addr, socklen_t *__restrict addrlen) +{ + descriptor_table_entry_t* entry; + if (!descriptor_table_get_ref(socket, &entry)) { + errno = EBADF; + return -1; + } + + if (addr == NULL || addrlen == NULL || *addrlen == 0) { + errno = EINVAL; + return -1; + } + + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t out_address; + + switch (entry->tag) + { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + if (!tcp_getpeername(&entry->value.tcp_socket, &out_address)) { + // errno is set by tcp_getpeername + return -1; + } + break; + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + if (!udp_getpeername(&entry->value.udp_socket, &out_address)) { + // errno is set by udp_getpeername + return -1; + } + break; + default: + errno = EOPNOTSUPP; + return -1; + } + + int err; + if (!__wasi_sockets_utils__format_address(&out_address, addr, addrlen, &err)) { + errno = err; + return -1; + } + + return 0; +} diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c new file mode 100644 index 000000000..cce96b046 --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c @@ -0,0 +1,96 @@ +#include +#include + +#include +#include "__utils.h" + +int tcp_listen(tcp_socket_t* socket, int backlog) { + + switch (socket->state_tag) { + case TCP_SOCKET_STATE_UNBOUND: + // TODO: perform implicit bind and then continue with this listen operation. + errno = EDESTADDRREQ; + return -1; + case TCP_SOCKET_STATE_BOUND: + // These can initiate a connect. + break; + case TCP_SOCKET_STATE_LISTENING: + // We can only update the backlog size. + break; + case TCP_SOCKET_STATE_CONNECTING: + case TCP_SOCKET_STATE_CONNECTED: + case TCP_SOCKET_STATE_CONNECT_FAILED: + default: + errno = EINVAL; + return -1; + } + + wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_listen_backlog_size(socket_borrow, backlog, &error)) { + abort(); // Our own state checks should've prevented this from happening. + } + + if (socket->state_tag == TCP_SOCKET_STATE_LISTENING) { + // Updating the backlog is all we had to do. + return 0; + } + + reactor_borrow_network_t network_borrow = __wasi_sockets_utils__borrow_network(); + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_listen(socket_borrow, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + // Listen has successfully started. Attempt to finish it: + while (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_listen(socket_borrow, &error)) { + if (error == WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK) { + reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(socket->socket_pollable); + wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + } else { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + } + + // Listen successful. + + socket->state_tag = TCP_SOCKET_STATE_LISTENING; + socket->state = (tcp_socket_state_t){ .listening = { /* No additional state */ } }; + return 0; +} + +int udp_listen(udp_socket_t* socket, int backlog) { + // UDP doesn't support listen + errno = EOPNOTSUPP; + return -1; +} + +int listen(int socket, int backlog) { + + descriptor_table_entry_t* entry; + if (!descriptor_table_get_ref(socket, &entry)) { + errno = EBADF; + return -1; + } + + if (backlog < 0) { + // POSIX: + // > If listen() is called with a backlog argument value that is + // > less than 0, the function behaves as if it had been called + // > with a backlog argument value of 0. + backlog = 0; + } + + switch (entry->tag) + { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + return tcp_listen(&entry->value.tcp_socket, backlog); + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + return udp_listen(&entry->value.udp_socket, backlog); + default: + errno = EOPNOTSUPP; + return -1; + } +} diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index cdde554af..4484ef3ba 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -10,70 +10,39 @@ #include #include +#include "__utils.h" static_assert(MSG_PEEK == __WASI_RIFLAGS_RECV_PEEK, "Value mismatch"); static_assert(MSG_WAITALL == __WASI_RIFLAGS_RECV_WAITALL, "Value mismatch"); -ssize_t recv(int socket, void* restrict buffer, size_t length, int flags) +ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int flags) { -#if 0 - // Validate flags. - if ((flags & ~(MSG_PEEK | MSG_WAITALL)) != 0) { - errno = EOPNOTSUPP; - return -1; - } - - // Prepare input parameters. - __wasi_iovec_t iov = { .buf = buffer, .buf_len = length }; - __wasi_iovec_t* ri_data = &iov; - size_t ri_data_len = 1; - __wasi_riflags_t ri_flags = flags; - - // Perform system call. - size_t ro_datalen; - __wasi_roflags_t ro_flags; - __wasi_errno_t error = __wasi_sock_recv(socket, - ri_data, ri_data_len, ri_flags, - &ro_datalen, - &ro_flags); - if (error != 0) { - errno = error; - return -1; - } - return ro_datalen; -#else - // TODO: what flags do we support? + // TODO: flags: + // - MSG_DONTWAIT, MSG_WAITALL: we can probably support these relatively easy. + // - MSG_OOB: could be shimed by always responding that no OOB data is available. + // - MSG_PEEK: could be shimmed by performing the receive into a local socket-specific buffer. And on subsequent receives first check that buffer. + // - MSG_TRUNC: return EOPNOTSUPP. Is UDP only. + // - MSG_EOR, MSG_CMSG_CLOEXEC: return EOPNOTSUPP. Is not supported on TCP or UDP. if (flags != 0) { errno = EOPNOTSUPP; return -1; } - descriptor_table_variant_t variant; - if (!descriptor_table_get(socket, &variant)) { - errno = EBADF; - return -1; - } - - bool blocking; - reactor_own_input_stream_t rx; - switch (variant.tag) { - case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED: - blocking = variant.value.tcp_connected.socket.blocking; - rx = variant.value.tcp_connected.rx; - break; - - default: + tcp_socket_state_connected_t connection; + if (socket->state_tag == TCP_SOCKET_STATE_CONNECTED) { + connection = socket->state.connected; + } else { errno = ENOTCONN; return -1; } - reactor_borrow_input_stream_t rx_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(rx); + reactor_borrow_input_stream_t rx_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(connection.input); while (true) { reactor_list_u8_t result; wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_read(rx_borrow, length, &result, &error)) { - // TODO: map errors appropriately - errno = EBADF; + // TODO: wasi-sockets has no way to recover stream errors yet. + errno = EPIPE; return -1; } @@ -81,15 +50,45 @@ ssize_t recv(int socket, void* restrict buffer, size_t length, int flags) memcpy(buffer, result.ptr, result.len); reactor_list_u8_free(&result); return result.len; - } else if (blocking) { - reactor_own_pollable_t pollable = wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe(rx_borrow); - reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(pollable); + } else if (socket->blocking) { + reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(connection.input_pollable); wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); - wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(pollable); } else { - errno = EAGAIN; + errno = EWOULDBLOCK; return -1; } } -#endif +} + +ssize_t udp_recv(udp_socket_t* socket, void* restrict buffer, size_t length, int flags) +{ + // TODO: Implement flags. Same as tcp_recv except that MSG_TRUNC is valid for UDP. + + errno = EOPNOTSUPP; + return -1; +} + +ssize_t recv(int socket, void* restrict buffer, size_t length, int flags) +{ + descriptor_table_entry_t* entry; + if (!descriptor_table_get_ref(socket, &entry)) { + errno = EBADF; + return -1; + } + + if (buffer == NULL) { + errno = EINVAL; + return -1; + } + + switch (entry->tag) + { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + return tcp_recv(&entry->value.tcp_socket, buffer, length, flags); + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + return udp_recv(&entry->value.udp_socket, buffer, length, flags); + default: + errno = EOPNOTSUPP; + return -1; + } } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c index 318763b6e..173003154 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c @@ -9,57 +9,35 @@ #include #include +#include "__utils.h" -ssize_t send(int socket, const void* buffer, size_t length, int flags) +ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int flags) { - // This implementation does not support any flags. + // TODO: flags: + // - MSG_DONTWAIT: we can probably support this relatively easy. + // - MSG_NOSIGNAL: ignore it. This is always the case. https://github.com/WebAssembly/wasi-sockets/blob/main/Posix-compatibility.md#writing-to-closed-streams-sigpipe-so_nosigpipe- + // - MSG_OOB: Not supported in WASI + // - MSG_EOR: Not supported in TCP/UDP in general. if (flags != 0) { errno = EOPNOTSUPP; return -1; } -#if 0 - // Prepare input parameters. - __wasi_ciovec_t iov = {.buf = buffer, .buf_len = length}; - __wasi_ciovec_t *si_data = &iov; - size_t si_data_len = 1; - __wasi_siflags_t si_flags = 0; - - // Perform system call. - size_t so_datalen; - __wasi_errno_t error = __wasi_sock_send(socket, si_data, si_data_len, si_flags, &so_datalen); - if (error != 0) { - errno = error; - return -1; - } - return so_datalen; -#else - descriptor_table_variant_t variant; - if (!descriptor_table_get(socket, &variant)) { - errno = EBADF; - return -1; - } - - bool blocking; - reactor_own_output_stream_t tx; - switch (variant.tag) { - case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED: - blocking = variant.value.tcp_connected.socket.blocking; - tx = variant.value.tcp_connected.tx; - break; - - default: + tcp_socket_state_connected_t connection; + if (socket->state_tag == TCP_SOCKET_STATE_CONNECTED) { + connection = socket->state.connected; + } else { errno = ENOTCONN; return -1; } - reactor_borrow_output_stream_t tx_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(tx); + reactor_borrow_output_stream_t tx_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(connection.output); while (true) { wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; uint64_t count; if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_check_write(tx_borrow, &count, &error)) { - // TODO: map errors appropriately - errno = EBADF; + // TODO: wasi-sockets has no way to recover stream errors yet. + errno = EPIPE; return -1; } @@ -67,21 +45,51 @@ ssize_t send(int socket, const void* buffer, size_t length, int flags) count = count < length ? count : length; reactor_list_u8_t list = { .ptr = (uint8_t*)buffer, .len = count }; if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write(tx_borrow, &list, &error)) { - // TODO: map errors appropriately - errno = EBADF; + // TODO: wasi-sockets has no way to recover stream errors yet. + errno = EPIPE; return -1; } else { return count; } - } else if (blocking) { - reactor_own_pollable_t pollable = wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe(tx_borrow); - reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(pollable); + } else if (socket->blocking) { + reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(connection.output_pollable); wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); - wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(pollable); } else { errno = EAGAIN; return -1; } } -#endif +} + +ssize_t udp_send(udp_socket_t* socket, const void* buffer, size_t length, int flags) +{ + // TODO: Implement flags. Same as tcp_send. + + errno = EOPNOTSUPP; + return -1; +} + +ssize_t send(int socket, const void* buffer, size_t length, int flags) +{ + descriptor_table_entry_t* entry; + if (!descriptor_table_get_ref(socket, &entry)) { + errno = EBADF; + return -1; + } + + if (buffer == NULL) { + errno = EINVAL; + return -1; + } + + switch (entry->tag) + { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + return tcp_send(&entry->value.tcp_socket, buffer, length, flags); + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + return udp_send(&entry->value.udp_socket, buffer, length, flags); + default: + errno = EOPNOTSUPP; + return -1; + } } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c index 261fcb81e..956b955e5 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c @@ -8,20 +8,80 @@ #include #include +#include +#include "__utils.h" + static_assert(SHUT_RD == __WASI_SDFLAGS_RD, "Value mismatch"); static_assert(SHUT_WR == __WASI_SDFLAGS_WR, "Value mismatch"); -int shutdown(int socket, int how) { - // Validate shutdown flags. - if (how != SHUT_RD && how != SHUT_WR && how != SHUT_RDWR) { - errno = EINVAL; - return -1; - } +int tcp_shutdown(tcp_socket_t* socket, int posix_how) +{ + wasi_sockets_0_2_0_rc_2023_10_18_tcp_shutdown_type_t wasi_how; + switch (posix_how) + { + case SHUT_RD: + wasi_how = WASI_SOCKETS_0_2_0_RC_2023_10_18_TCP_SHUTDOWN_TYPE_RECEIVE; + break; + case SHUT_WR: + wasi_how = WASI_SOCKETS_0_2_0_RC_2023_10_18_TCP_SHUTDOWN_TYPE_SEND; + break; + case SHUT_RDWR: + wasi_how = WASI_SOCKETS_0_2_0_RC_2023_10_18_TCP_SHUTDOWN_TYPE_BOTH; + break; + default: + errno = EINVAL; + return -1; + } + + tcp_socket_state_connected_t connection; + if (socket->state_tag == TCP_SOCKET_STATE_CONNECTED) { + connection = socket->state.connected; + } else { + errno = ENOTCONN; + return -1; + } + + wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_shutdown(socket_borrow, wasi_how, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + if (posix_how == SHUT_RD || posix_how == SHUT_RDWR) { + // TODO: drop input stream (if not already). And update `recv` to take dropped input streams into account. + } + + if (posix_how == SHUT_WR || posix_how == SHUT_RDWR) { + // TODO: drop output stream (if not already). And update `send` to take dropped output streams into account. + } - __wasi_errno_t error = __wasi_sock_shutdown(socket, how); - if (error != 0) { - errno = error; + return 0; +} + +int udp_shutdown(udp_socket_t* socket, int posix_how) +{ + // UDP has nothing to shut down. + errno = EOPNOTSUPP; return -1; - } - return error; +} + +int shutdown(int socket, int how) { + + descriptor_table_entry_t* entry; + if (!descriptor_table_get_ref(socket, &entry)) { + errno = EBADF; + return -1; + } + + switch (entry->tag) + { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + return tcp_shutdown(&entry->value.tcp_socket, how); + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + return udp_shutdown(&entry->value.udp_socket, how); + default: + errno = EOPNOTSUPP; + return -1; + } } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c index 9fd05ae5c..4ae49ebbd 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c @@ -2,168 +2,76 @@ #include #include +#include "__utils.h" -int socket(int domain, int type, int protocol) +int tcp_socket(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t family, bool blocking) { - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t family; - switch (domain) { - case PF_INET: - family = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4; - break; - - case PF_INET6: - family = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6; - break; - - default: - errno = EAFNOSUPPORT; + wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t error; + reactor_own_tcp_socket_t socket; + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_create_tcp_socket(family, &socket, &error)) { + errno = __wasi_sockets_utils__map_error(error); return -1; } - switch (type & ~(SOCK_NONBLOCK | SOCK_CLOEXEC)) { - case SOCK_STREAM: { - wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t error; - reactor_own_tcp_socket_t socket; - if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_create_tcp_socket( - family, &socket, &error)) { - descriptor_table_variant_t variant = { .tag = DESCRIPTOR_TABLE_VARIANT_TCP_NEW, - .value = { .tcp_new = { .socket = socket, .blocking = (type & SOCK_NONBLOCK) == 0 } } }; - int fd; - if (!descriptor_table_insert(variant, &fd)) { - errno = ENOMEM; - return -1; - } - return fd; - } else { - // TODO: map errors appropriately - errno = EBADF; - return -1; - } - } - - case SOCK_DGRAM: - // TODO - errno = EPROTONOSUPPORT; - return -1; - - default: - errno = EPROTONOSUPPORT; + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket); + reactor_own_pollable_t socket_pollable = wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(socket_borrow); + + descriptor_table_entry_t entry = { + .tag = DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, + .value = { .tcp_socket = { + .socket = socket, + .socket_pollable = socket_pollable, + .blocking = blocking, + .state_tag = TCP_SOCKET_STATE_UNBOUND, + .state = { .unbound = { /* No additional state. */ } }, + } }, + }; + + int fd; + if (!descriptor_table_insert(entry, &fd)) { + errno = EMFILE; return -1; } + return fd; } -int connect(int fd, struct sockaddr* address, socklen_t len) +int udp_socket(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t family, bool blocking) { - descriptor_table_variant_t variant; - if (!descriptor_table_get(fd, &variant)) { - errno = EBADF; - return -1; - } + // TODO: implement + errno = EPROTONOSUPPORT; + return -1; +} + - descriptor_table_tcp_new_t socket; - switch (variant.tag) { - case DESCRIPTOR_TABLE_VARIANT_TCP_NEW: - socket = variant.value.tcp_new; +int socket(int domain, int type, int protocol) +{ + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t family; + switch (domain) { + case PF_INET: + family = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4; break; - case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED: - // TODO: should we disallow re-connecting an already-connected socket? - socket = variant.value.tcp_connected.socket; + case PF_INET6: + family = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6; break; default: - errno = EBADF; + errno = EAFNOSUPPORT; return -1; } - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket.socket); - - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t ip_address; - switch (address->sa_family) { - case AF_INET: { - struct sockaddr_in* ipv4 = (struct sockaddr_in*)address; - unsigned ip = ipv4->sin_addr.s_addr; - unsigned short port = ipv4->sin_port; - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t my_ip_address = { - .tag = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV4, - .val = { .ipv4 = { .port = (port << 8) | (port >> 8), - .address = { ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24 } } } - }; - ip_address = my_ip_address; - break; - } + int real_type = type & ~(SOCK_NONBLOCK | SOCK_CLOEXEC); + bool blocking = (type & SOCK_NONBLOCK) == 0; + // Ignore SOCK_CLOEXEC flag. That concept does not exist in WASI. - case AF_INET6: { - struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)address; - unsigned char* ip = (unsigned char*)&(ipv6->sin6_addr.s6_addr); - unsigned short port = ipv6->sin6_port; - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t my_ip_address = { - .tag = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV6, - .val = { .ipv6 = { .port = (port << 8) | (port >> 8), - .address = { - (((unsigned short)ip[0]) << 8) | ip[1], - (((unsigned short)ip[2]) << 8) | ip[3], - (((unsigned short)ip[4]) << 8) | ip[5], - (((unsigned short)ip[6]) << 8) | ip[7], - (((unsigned short)ip[8]) << 8) | ip[9], - (((unsigned short)ip[10]) << 8) | ip[11], - (((unsigned short)ip[12]) << 8) | ip[13], - (((unsigned short)ip[14]) << 8) | ip[15], - }, - // TODO: do these need to be endian-reversed? - .flow_info = ipv6->sin6_flowinfo, - .scope_id = ipv6->sin6_flowinfo } } - }; - ip_address = my_ip_address; - break; - } + if (real_type == SOCK_STREAM && (protocol == 0 || protocol == IPPROTO_TCP)) { + return tcp_socket(family, blocking); - default: + } else if (real_type == SOCK_DGRAM && (protocol == 0 || protocol == IPPROTO_UDP)) { + return udp_socket(family, blocking); + + } else { errno = EPROTONOSUPPORT; return -1; } - - reactor_own_network_t network = wasi_sockets_0_2_0_rc_2023_10_18_instance_network_instance_network(); - wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t error; - reactor_borrow_network_t network_borrow = wasi_sockets_0_2_0_rc_2023_10_18_network_borrow_network(network); - bool result = wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_connect(socket_borrow, network_borrow, &ip_address, &error); - wasi_sockets_0_2_0_rc_2023_10_18_network_network_drop_own(network); - - if (!result) { - // TODO: map errors appropriately - errno = EBADF; - return -1; - } - - reactor_tuple2_own_input_stream_own_output_stream_t rx_tx; - while (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_connect(socket_borrow, &rx_tx, &error)) { - if (error == WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK) { - if (socket.blocking) { - reactor_own_pollable_t pollable = wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(socket_borrow); - reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(pollable); - wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); - wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(pollable); - } else { - descriptor_table_variant_t new_variant = { .tag = DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTING, - .value = { .tcp_new = socket } }; - if (!descriptor_table_update(fd, new_variant)) { - abort(); - } - errno = EINPROGRESS; - return -1; - } - } else { - // TODO: map errors appropriately - errno = EBADF; - return -1; - } - } - - descriptor_table_variant_t new_variant = { .tag = DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED, - .value = { .tcp_connected = { .socket = socket, .rx = rx_tx.f0, .tx = rx_tx.f1 } } }; - if (!descriptor_table_update(fd, new_variant)) { - abort(); - } - - return 0; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c new file mode 100644 index 000000000..96fc32ac8 --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -0,0 +1,470 @@ +// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ +// +// SPDX-License-Identifier: BSD-2-Clause + +#include +#include + +#include +#include +#include +#include +#include +#include "__utils.h" + +int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, + void* restrict optval, socklen_t* restrict optlen) +{ + int value = 0; + + wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + + switch (level) + { + case SOL_SOCKET: + switch (optname) { + case SO_TYPE: { + value = SOCK_STREAM; + break; + } + case SO_PROTOCOL: { + value = IPPROTO_TCP; + break; + } + case SO_DOMAIN: { + value = __wasi_sockets_utils__posix_family( + wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(socket_borrow) + ); + break; + } + case SO_ERROR: { + if (socket->state_tag == TCP_SOCKET_STATE_CONNECT_FAILED) { + value = __wasi_sockets_utils__map_error(socket->state.connect_failed.error_code); + socket->state.connect_failed.error_code = 0; + } else { + value = 0; + } + break; + } + case SO_ACCEPTCONN: { + // TODO: use 2023-11-10 snapshot to call out to tcp-socket::is-listening ? + value = socket->state_tag == TCP_SOCKET_STATE_LISTENING; + break; + } + case SO_KEEPALIVE: { + bool result; + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_keep_alive(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + value = result; + break; + } + case SO_RCVBUF: { + uint64_t result; + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_receive_buffer_size(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + if (result > INT_MAX) { + abort(); + } + + value = result; + break; + } + case SO_SNDBUF: { + uint64_t result; + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_send_buffer_size(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + if (result > INT_MAX) { + abort(); + } + + value = result; + break; + } + case SO_RCVTIMEO: // TODO: emulate in wasi-libc itself + case SO_SNDTIMEO: // TODO: emulate in wasi-libc itself + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + case SOL_IP: + switch (optname) { + case IP_TTL: { + if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(socket_borrow) + != WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4) + { + errno = EAFNOSUPPORT; + return -1; + } + + uint8_t result; + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_unicast_hop_limit(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + value = result; + break; + } + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + case SOL_IPV6: + switch (optname) { + case IPV6_UNICAST_HOPS: { + if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(socket_borrow) + != WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6) + { + errno = EAFNOSUPPORT; + return -1; + } + + uint8_t result; + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_unicast_hop_limit(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + value = result; + break; + } + case IPV6_V6ONLY: { + bool result; + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_ipv6_only(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + value = result; + break; + } + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + case SOL_TCP: + switch (optname) { + case TCP_KEEPIDLE: // TODO: implement using the 2023-11-10 preview2 snapshot. + case TCP_KEEPINTVL: // TODO: implement using the 2023-11-10 preview2 snapshot. + case TCP_KEEPCNT: // TODO: implement using the 2023-11-10 preview2 snapshot. + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + default: + errno = ENOPROTOOPT; + return -1; + } + + // Copy out integer value. + memcpy(optval, &value, + *optlen < sizeof(int) ? *optlen : sizeof(int)); + *optlen = sizeof(int); + return 0; +} + +int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* optval, socklen_t optlen) { + + int intval = *(int*)optval; + + wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + + switch (level) + { + case SOL_SOCKET: + switch (optname) { + case SO_KEEPALIVE: { + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_keep_alive(socket_borrow, intval != 0, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } + case SO_RCVBUF: { + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_receive_buffer_size(socket_borrow, intval, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } + case SO_SNDBUF: { + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_send_buffer_size(socket_borrow, intval, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } + case SO_RCVTIMEO: // TODO: emulate in wasi-libc itself + case SO_SNDTIMEO: // TODO: emulate in wasi-libc itself + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + case SOL_IP: + switch (optname) { + case IP_TTL: { + if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(socket_borrow) + != WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4) + { + errno = EAFNOSUPPORT; + return -1; + } + + if (intval < 0 || intval > UINT8_MAX) { + errno = EINVAL; + return -1; + } + + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_unicast_hop_limit(socket_borrow, intval, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + case SOL_IPV6: + switch (optname) { + case IPV6_UNICAST_HOPS: { + if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(socket_borrow) + != WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6) + { + errno = EAFNOSUPPORT; + return -1; + } + + if (intval < 0 || intval > UINT8_MAX) { + errno = EINVAL; + return -1; + } + + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_unicast_hop_limit(socket_borrow, intval, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } + case IPV6_V6ONLY: { + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_ipv6_only(socket_borrow, intval != 0, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + case SOL_TCP: + switch (optname) { + case TCP_KEEPIDLE: // TODO: implement using the 2023-11-10 preview2 snapshot. + case TCP_KEEPINTVL: // TODO: implement using the 2023-11-10 preview2 snapshot. + case TCP_KEEPCNT: // TODO: implement using the 2023-11-10 preview2 snapshot. + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + default: + errno = ENOPROTOOPT; + return -1; + } +} + +int udp_getsockopt(udp_socket_t* socket, int level, int optname, + void* restrict optval, socklen_t* restrict optlen) +{ + int value; + + switch (level) + { + case SOL_SOCKET: + switch (optname) { + case SO_TYPE: + value = SOCK_STREAM; + break; + case SO_PROTOCOL: + value = IPPROTO_TCP; + break; + case SO_DOMAIN: // TODO: implement + case SO_RCVBUF: // TODO: implement + case SO_SNDBUF: // TODO: implement + case SO_RCVTIMEO: // TODO: emulate in wasi-libc itself + case SO_SNDTIMEO: // TODO: emulate in wasi-libc itself + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + case SOL_IP: + switch (optname) { + case IP_TTL: // TODO: implement + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + case SOL_IPV6: + switch (optname) { + case IPV6_V6ONLY: // TODO: implement + case IPV6_UNICAST_HOPS: // TODO: implement + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + default: + errno = ENOPROTOOPT; + return -1; + } + + // Copy out integer value. + memcpy(optval, &value, + *optlen < sizeof(int) ? *optlen : sizeof(int)); + *optlen = sizeof(int); + return 0; +} + +int udp_setsockopt(udp_socket_t* socket, int level, int optname, const void* optval, socklen_t optlen) { + switch (level) + { + case SOL_SOCKET: + switch (optname) { + case SO_RCVBUF: // TODO: implement + case SO_SNDBUF: // TODO: implement + case SO_RCVTIMEO: // TODO: emulate in wasi-libc itself + case SO_SNDTIMEO: // TODO: emulate in wasi-libc itself + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + case SOL_IP: + switch (optname) { + case IP_TTL: // TODO: implement + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + case SOL_IPV6: + switch (optname) { + case IPV6_V6ONLY: // TODO: implement + case IPV6_UNICAST_HOPS: // TODO: implement + default: + errno = ENOPROTOOPT; + return -1; + } + break; + + + default: + errno = ENOPROTOOPT; + return -1; + } +} + +int getsockopt(int sockfd, int level, int optname, + void* restrict optval, socklen_t* restrict optlen) +{ + descriptor_table_entry_t* entry; + if (!descriptor_table_get_ref(sockfd, &entry)) { + errno = EBADF; + return -1; + } + + if (optval == NULL || optlen == NULL || *optlen < sizeof(int)) { + // FYI, the protocol-specific implementations implicitly depend on these checks. + errno = EINVAL; + return -1; + } + + switch (entry->tag) + { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + return tcp_getsockopt(&entry->value.tcp_socket, level, optname, optval, optlen); + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + return udp_getsockopt(&entry->value.udp_socket, level, optname, optval, optlen); + default: + errno = ENOPROTOOPT; + return -1; + } +} + +int setsockopt(int sockfd, int level, int optname, const void* optval, socklen_t optlen) { + + descriptor_table_entry_t* entry; + if (!descriptor_table_get_ref(sockfd, &entry)) { + errno = EBADF; + return -1; + } + + if (optval == NULL || optlen < sizeof(int)) { + // FYI, the protocol-specific implementations implicitly depend on these checks. + errno = EINVAL; + return -1; + } + + switch (entry->tag) + { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + return tcp_setsockopt(&entry->value.tcp_socket, level, optname, optval, optlen); + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + return udp_setsockopt(&entry->value.udp_socket, level, optname, optval, optlen); + default: + errno = ENOPROTOOPT; + return -1; + } +} \ No newline at end of file diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c index bc907fd86..809963e3c 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c @@ -47,11 +47,11 @@ static bool wasi_preview1_adapter_open_badfd(int* fd) typedef struct { bool occupied; int key; - descriptor_table_variant_t variant; -} descriptor_table_entry_t; + descriptor_table_entry_t entry; +} descriptor_table_item_t; typedef struct { - descriptor_table_entry_t* entries; + descriptor_table_item_t* entries; size_t mask; size_t used; } descriptor_table_t; @@ -68,9 +68,9 @@ static int resize(size_t nel, descriptor_table_t* table) { size_t newsize; size_t i; - descriptor_table_entry_t *e, *newe; - descriptor_table_entry_t* oldtab = table->entries; - descriptor_table_entry_t* oldend = table->entries + table->mask + 1; + descriptor_table_item_t *e, *newe; + descriptor_table_item_t* oldtab = table->entries; + descriptor_table_item_t* oldend = table->entries + table->mask + 1; if (nel > MAXSIZE) nel = MAXSIZE; @@ -97,10 +97,10 @@ static int resize(size_t nel, descriptor_table_t* table) return 1; } -static descriptor_table_entry_t* lookup(int key, size_t hash, descriptor_table_t* table) +static descriptor_table_item_t* lookup(int key, size_t hash, descriptor_table_t* table) { size_t i; - descriptor_table_entry_t* e; + descriptor_table_item_t* e; for (i = hash;; ++i) { e = table->entries + (i & table->mask); @@ -110,7 +110,7 @@ static descriptor_table_entry_t* lookup(int key, size_t hash, descriptor_table_t return e; } -static bool insert(descriptor_table_variant_t variant, int fd, descriptor_table_t* table) +static bool insert(descriptor_table_entry_t entry, int fd, descriptor_table_t* table) { if (!table->entries) { if (!resize(MINSIZE, table)) { @@ -119,9 +119,9 @@ static bool insert(descriptor_table_variant_t variant, int fd, descriptor_table_ } size_t hash = keyhash(fd); - descriptor_table_entry_t* e = lookup(fd, hash, table); + descriptor_table_item_t* e = lookup(fd, hash, table); - e->variant = variant; + e->entry = entry; if (!e->occupied) { e->key = fd; e->occupied = true; @@ -136,39 +136,23 @@ static bool insert(descriptor_table_variant_t variant, int fd, descriptor_table_ return true; } -static bool update(int fd, descriptor_table_variant_t variant, descriptor_table_t* table) +static bool get(int fd, descriptor_table_entry_t** entry, descriptor_table_t* table) { if (!table->entries) { return false; } size_t hash = keyhash(fd); - descriptor_table_entry_t* e = lookup(fd, hash, table); + descriptor_table_item_t* e = lookup(fd, hash, table); if (e->occupied) { - e->variant = variant; + *entry = &e->entry; return true; } else { return false; } } -static bool get(int fd, descriptor_table_variant_t* variant, descriptor_table_t* table) -{ - if (!table->entries) { - return false; - } - - size_t hash = keyhash(fd); - descriptor_table_entry_t* e = lookup(fd, hash, table); - if (e->occupied) { - *variant = e->variant; - return true; - } else { - return false; - } -} - -static bool remove(int fd, descriptor_table_variant_t* variant, descriptor_table_t* table) +static bool remove(int fd, descriptor_table_entry_t* entry, descriptor_table_t* table) { if (!table->entries) { return false; @@ -176,7 +160,7 @@ static bool remove(int fd, descriptor_table_variant_t* variant, descriptor_table size_t hash = keyhash(fd); size_t i; - descriptor_table_entry_t* e; + descriptor_table_item_t* e; for (i = hash;; ++i) { e = table->entries + (i & table->mask); if (!e->occupied || e->key == fd) @@ -184,7 +168,7 @@ static bool remove(int fd, descriptor_table_variant_t* variant, descriptor_table } if (e->occupied) { - *variant = e->variant; + *entry = e->entry; e->occupied = false; // Search for any occupied entries which would be lost (due to an @@ -221,10 +205,10 @@ static bool remove(int fd, descriptor_table_variant_t* variant, descriptor_table } } -bool descriptor_table_insert(descriptor_table_variant_t variant, int* fd) +bool descriptor_table_insert(descriptor_table_entry_t entry, int* fd) { if (wasi_preview1_adapter_open_badfd(fd)) { - if (insert(variant, *fd, &global_table)) { + if (insert(entry, *fd, &global_table)) { return true; } else { if (__wasi_fd_close(*fd) != 0) { @@ -238,19 +222,14 @@ bool descriptor_table_insert(descriptor_table_variant_t variant, int* fd) } } -bool descriptor_table_update(int fd, descriptor_table_variant_t variant) -{ - return update(fd, variant, &global_table); -} - -bool descriptor_table_get(int fd, descriptor_table_variant_t* variant) +bool descriptor_table_get_ref(int fd, descriptor_table_entry_t** entry) { - return get(fd, variant, &global_table); + return get(fd, entry, &global_table); } -bool descriptor_table_remove(int fd, descriptor_table_variant_t* variant) +bool descriptor_table_remove(int fd, descriptor_table_entry_t* entry) { - if (remove(fd, variant, &global_table)) { + if (remove(fd, entry, &global_table)) { if (__wasi_fd_close(fd) != 0) { abort(); } diff --git a/libc-bottom-half/headers/private/descriptor_table.h b/libc-bottom-half/headers/private/descriptor_table.h index 44fa5e539..f76241ab9 100644 --- a/libc-bottom-half/headers/private/descriptor_table.h +++ b/libc-bottom-half/headers/private/descriptor_table.h @@ -4,45 +4,75 @@ #include typedef enum { - DESCRIPTOR_TABLE_VARIANT_TCP_NEW, - DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTING, - DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED, - DESCRIPTOR_TABLE_VARIANT_TCP_ERROR, -} descriptor_table_tag_t; + TCP_SOCKET_STATE_UNBOUND, + TCP_SOCKET_STATE_BOUND, + TCP_SOCKET_STATE_CONNECTING, + TCP_SOCKET_STATE_CONNECTED, + TCP_SOCKET_STATE_CONNECT_FAILED, + TCP_SOCKET_STATE_LISTENING, +} tcp_socket_state_tag_t; + +typedef struct {} tcp_socket_state_unbound_t; +typedef struct {} tcp_socket_state_bound_t; +typedef struct {} tcp_socket_state_connecting_t; +typedef struct {} tcp_socket_state_listening_t; + +typedef struct { + reactor_own_input_stream_t input; + reactor_own_pollable_t input_pollable; + reactor_own_output_stream_t output; + reactor_own_pollable_t output_pollable; +} tcp_socket_state_connected_t; + +typedef struct { + wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error_code; +} tcp_socket_state_connect_failed_t; + +typedef union { + tcp_socket_state_unbound_t unbound; + tcp_socket_state_bound_t bound; + tcp_socket_state_connecting_t connecting; + tcp_socket_state_connected_t connected; + tcp_socket_state_connect_failed_t connect_failed; + tcp_socket_state_listening_t listening; +} tcp_socket_state_t; typedef struct { reactor_own_tcp_socket_t socket; + reactor_own_pollable_t socket_pollable; bool blocking; -} descriptor_table_tcp_new_t; + tcp_socket_state_tag_t state_tag; + tcp_socket_state_t state; +} tcp_socket_t; + + -typedef struct { - descriptor_table_tcp_new_t socket; - reactor_own_input_stream_t rx; - reactor_own_output_stream_t tx; -} descriptor_table_tcp_connected_t; typedef struct { - descriptor_table_tcp_new_t socket; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t error_code; -} descriptor_table_tcp_error_t; + reactor_own_udp_socket_t socket; + bool blocking; +} udp_socket_t; + + +typedef enum { + DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, + DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET, +} descriptor_table_entry_tag_t; typedef union { - descriptor_table_tcp_new_t tcp_new; - descriptor_table_tcp_connected_t tcp_connected; - descriptor_table_tcp_error_t tcp_error; -} descriptor_table_value_t; + tcp_socket_t tcp_socket; + udp_socket_t udp_socket; +} descriptor_table_entry_value_t; typedef struct { - descriptor_table_tag_t tag; - descriptor_table_value_t value; -} descriptor_table_variant_t; - -bool descriptor_table_insert(descriptor_table_variant_t variant, int* fd); + descriptor_table_entry_tag_t tag; + descriptor_table_entry_value_t value; +} descriptor_table_entry_t; -bool descriptor_table_update(int fd, descriptor_table_variant_t variant); +bool descriptor_table_insert(descriptor_table_entry_t entry, int* fd); -bool descriptor_table_get(int fd, descriptor_table_variant_t* variant); +bool descriptor_table_get_ref(int fd, descriptor_table_entry_t** entry); -bool descriptor_table_remove(int fd, descriptor_table_variant_t* variant); +bool descriptor_table_remove(int fd, descriptor_table_entry_t* entry); #endif diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index 5b9c3136e..525b9e6a5 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -22,9 +22,32 @@ #define SOCK_CLOEXEC (0x00002000) #define SOL_SOCKET 0x7fffffff +#define SOL_IP 0 +#define SOL_TCP 6 +#define SOL_UDP 17 +#define SOL_IPV6 41 #define SO_TYPE 3 #define SO_ERROR 4 +#define SO_SNDBUF 7 +#define SO_RCVBUF 8 +#define SO_KEEPALIVE 9 +#define SO_ACCEPTCONN 30 +#define SO_PROTOCOL 38 +#define SO_DOMAIN 39 + +#if __LONG_MAX == 0x7fffffff +#define SO_RCVTIMEO 66 +#define SO_SNDTIMEO 67 +#else +#define SO_RCVTIMEO 20 +#define SO_SNDTIMEO 21 +#endif + +// TODO: These should be in +#define TCP_KEEPIDLE 4 +#define TCP_KEEPINTVL 5 +#define TCP_KEEPCNT 6 #define PF_UNSPEC 0 #define PF_INET 1 diff --git a/libc-bottom-half/sources/accept.c b/libc-bottom-half/sources/accept.c deleted file mode 100644 index 902e7316f..000000000 --- a/libc-bottom-half/sources/accept.c +++ /dev/null @@ -1,51 +0,0 @@ -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include -#include -#include - -int accept(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen) { - int ret = -1; - - __wasi_errno_t error = __wasi_sock_accept(socket, 0, &ret); - - if (error != 0) { - errno = error; - return -1; - } - - // Clear sockaddr to indicate undefined address - memset(addr, 0, *addrlen); - // might be AF_UNIX or AF_INET - addr->sa_family = AF_UNSPEC; - *addrlen = sizeof(struct sockaddr); - - return ret; -} - -int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen, int flags) { - int ret = -1; - - if (flags & ~(SOCK_NONBLOCK | SOCK_CLOEXEC)) { - errno = EINVAL; - return -1; - } - - __wasi_errno_t error = __wasi_sock_accept(socket, (flags & SOCK_NONBLOCK) ? __WASI_FDFLAGS_NONBLOCK : 0, &ret); - - if (error != 0) { - errno = error; - return -1; - } - - // Clear sockaddr to indicate undefined address - memset(addr, 0, *addrlen); - // might be AF_UNIX or AF_INET - addr->sa_family = AF_UNSPEC; - *addrlen = sizeof(struct sockaddr); - - return ret; -} diff --git a/libc-top-half/musl/include/sys/socket.h b/libc-top-half/musl/include/sys/socket.h index 4d574c662..4fbadbe17 100644 --- a/libc-top-half/musl/include/sys/socket.h +++ b/libc-top-half/musl/include/sys/socket.h @@ -75,6 +75,7 @@ struct mmsghdr { struct timespec; +// TODO: implement int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int); int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *); #endif @@ -395,42 +396,34 @@ struct sockaddr_storage { #include <__struct_sockaddr_storage.h> #endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no socket/socketpair */ int socket (int, int, int); + +#ifdef __wasilibc_unmodified_upstream /* WASI has no socketpair */ int socketpair (int, int, int, int [2]); #endif int shutdown (int, int); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no bind/connect/listen/accept */ int bind (int, const struct sockaddr *, socklen_t); int connect (int, const struct sockaddr *, socklen_t); int listen (int, int); -#endif int accept (int, struct sockaddr *__restrict, socklen_t *__restrict); int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); -#ifdef __wasilibc_unmodified_upstream /* WASI has no getsockname/getpeername */ int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict); int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); -#endif ssize_t send (int, const void *, size_t, int); ssize_t recv (int, void *, size_t, int); -#ifdef __wasilibc_unmodified_upstream /* WASI has no sendto/recvfrom */ +#ifdef __wasilibc_unmodified_upstream /* TODO: implement */ ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no sendmsg/recvmsg */ ssize_t sendmsg (int, const struct msghdr *, int); ssize_t recvmsg (int, struct msghdr *, int); #endif int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict); -#ifdef __wasilibc_unmodified_upstream /* WASI has no setsockopt */ int setsockopt (int, int, int, const void *, socklen_t); -#endif #ifdef __wasilibc_unmodified_upstream /* WASI has no sockatmark */ int sockatmark (int); From c7eda8197595967ee566b6bb9612421f110af4fe Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Sun, 3 Dec 2023 17:57:40 +0100 Subject: [PATCH 06/63] Ignore .vscode --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3af68b684..5eba0790d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ sysroot build +.vscode From f3a1106814f2c2fcabd2df323fa4913ddaabda1c Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Sun, 3 Dec 2023 18:23:25 +0100 Subject: [PATCH 07/63] Fix errors after merge --- .../src/libc/sys/socket/setsockopt.c | 91 ------------------- .../sources/__wasilibc_fd_renumber.c | 58 ++++++++---- 2 files changed, 39 insertions(+), 110 deletions(-) delete mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/socket/setsockopt.c diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/setsockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/setsockopt.c deleted file mode 100644 index 6c810b7c3..000000000 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/setsockopt.c +++ /dev/null @@ -1,91 +0,0 @@ -#include -#include -#include -#include -#include - -int setsockopt(int fd, int level, int option_name, const void* option_value, socklen_t option_len) -{ - descriptor_table_variant_t variant; - if (!descriptor_table_get(fd, &variant)) { - errno = EBADF; - return -1; - } - - reactor_own_tcp_socket_t socket; - switch (variant.tag) { - case DESCRIPTOR_TABLE_VARIANT_TCP_NEW: - case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTING: - socket = variant.value.tcp_new.socket; - break; - - case DESCRIPTOR_TABLE_VARIANT_TCP_ERROR: - socket = variant.value.tcp_error.socket.socket; - break; - - case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED: - socket = variant.value.tcp_connected.socket.socket; - break; - - default: - errno = EBADF; - return -1; - } - - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket); - - switch (level) { - case IPPROTO_TCP: { - switch (option_name) { - case TCP_NODELAY: { - if (option_len != sizeof(int)) { - errno = EDOM; - return -1; - } - - wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t error; - if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_no_delay(socket_borrow, *((int*)option_value) != 0, &error)) { - return 0; - } else { - // TODO: map errors appropriately - errno = EBADF; - return -1; - } - } - default: { - errno = ENOPROTOOPT; - return -1; - } - } - } - - case SOL_SOCKET: { - switch (option_name) { - case SO_KEEPALIVE: { - if (option_len != sizeof(int)) { - errno = EDOM; - return -1; - } - - wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t error; - if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_keep_alive(socket_borrow, *((int*)option_value) != 0, &error)) { - return 0; - } else { - // TODO: map errors appropriately - errno = EBADF; - return -1; - } - } - default: { - errno = ENOPROTOOPT; - return -1; - } - } - } - - default: { - errno = ENOPROTOOPT; - return -1; - } - } -} diff --git a/libc-bottom-half/sources/__wasilibc_fd_renumber.c b/libc-bottom-half/sources/__wasilibc_fd_renumber.c index 7f32366bf..8b6071e3a 100644 --- a/libc-bottom-half/sources/__wasilibc_fd_renumber.c +++ b/libc-bottom-half/sources/__wasilibc_fd_renumber.c @@ -17,31 +17,51 @@ int __wasilibc_fd_renumber(int fd, int newfd) { return 0; } +void drop_tcp_socket(tcp_socket_t socket) { + switch (socket.state_tag) { + case TCP_SOCKET_STATE_UNBOUND: + case TCP_SOCKET_STATE_BOUND: + case TCP_SOCKET_STATE_CONNECTING: + case TCP_SOCKET_STATE_LISTENING: + case TCP_SOCKET_STATE_CONNECT_FAILED: + // No additional resources to drop. + break; + case TCP_SOCKET_STATE_CONNECTED: { + tcp_socket_state_connected_t connection = socket.state.connected; + + wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(connection.input_pollable); + wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(connection.output_pollable); + wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(connection.input); + wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(connection.output); + break; + } + default: /* unreachable */ abort(); + } + + wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(socket.socket_pollable); + wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(socket.socket); +} + +void drop_udp_socket(udp_socket_t socket) { + abort(); // TODO +} + int close(int fd) { // Scan the preopen fds before making any changes. __wasilibc_populate_preopens(); - descriptor_table_variant_t variant; - if (descriptor_table_remove(fd, &variant)) { - switch (variant.tag) { - case DESCRIPTOR_TABLE_VARIANT_TCP_NEW: - case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTING: - wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(variant.value.tcp_new.socket); - break; - - case DESCRIPTOR_TABLE_VARIANT_TCP_ERROR: - wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(variant.value.tcp_error.socket.socket); + descriptor_table_entry_t entry; + if (descriptor_table_remove(fd, &entry)) { + + switch (entry.tag) + { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + drop_tcp_socket(entry.value.tcp_socket); break; - - case DESCRIPTOR_TABLE_VARIANT_TCP_CONNECTED: - wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(variant.value.tcp_connected.rx); - wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(variant.value.tcp_connected.tx); - wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(variant.value.tcp_connected.socket.socket); + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + drop_udp_socket(entry.value.udp_socket); break; - - default: - errno = EBADF; - return -1; + default: /* unreachable */ abort(); } return 0; From ae41e777acfaaf912dd4f79d8a0eced91c2cbd4a Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Sun, 3 Dec 2023 20:45:51 +0100 Subject: [PATCH 08/63] Perform implicit bind in Listen --- .../cloudlibc/src/libc/sys/socket/__utils.c | 62 +++++++++++++++++++ .../cloudlibc/src/libc/sys/socket/__utils.h | 2 + .../cloudlibc/src/libc/sys/socket/bind.c | 35 +---------- .../cloudlibc/src/libc/sys/socket/listen.c | 27 +++++--- 4 files changed, 84 insertions(+), 42 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c index d54076473..07ae380cf 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c @@ -174,4 +174,66 @@ int __wasi_sockets_utils__posix_family(wasi_sockets_0_2_0_rc_2023_10_18_network_ case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6: return AF_INET6; default: /* unreachable */ abort(); } +} + +wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t __wasi_sockets_utils__any_addr(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t family) { + switch (family) + { + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4: + return (wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t){ + .tag = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV4, + .val = { .ipv4 = { + .port = 0, + .address = { 0, 0, 0, 0 }, + }} + }; + case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6: + return (wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t){ + .tag = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV6, + .val = { .ipv6 = { + .port = 0, + .address = { 0, 0, 0, 0, 0, 0, 0, 0 }, + .flow_info = 0, + .scope_id = 0, + }} + }; + default: /* unreachable */ abort(); + } +} + +int __wasi_sockets_utils__tcp_bind(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) { + + tcp_socket_state_unbound_t unbound; + if (socket->state_tag == TCP_SOCKET_STATE_UNBOUND) { + unbound = socket->state.unbound; + } else { + errno = EINVAL; + return -1; + } + + wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; + reactor_borrow_network_t network_borrow = __wasi_sockets_utils__borrow_network(); + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + + if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_bind(socket_borrow, network_borrow, address, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + // Bind has successfully started. Attempt to finish it: + while (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_bind(socket_borrow, &error)) { + if (error == WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK) { + reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(socket->socket_pollable); + wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + } else { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + } + + // Bind successful. + + socket->state_tag = TCP_SOCKET_STATE_BOUND; + socket->state = (tcp_socket_state_t){ .bound = { /* No additional state */ } }; + return 0; } \ No newline at end of file diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h index a0a3333de..1e70059a7 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h @@ -10,5 +10,7 @@ int __wasi_sockets_utils__map_error(wasi_sockets_0_2_0_rc_2023_10_18_network_err bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen_t len, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* output, int* error); bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address, struct sockaddr* output_addr, socklen_t* output_addrlen, int* error); int __wasi_sockets_utils__posix_family(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_family); +wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t __wasi_sockets_utils__any_addr(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t family); +int __wasi_sockets_utils__tcp_bind(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address); #endif \ No newline at end of file diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c index 3cb4577c1..ccf71cd76 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c @@ -5,40 +5,7 @@ #include "__utils.h" int tcp_bind(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) { - - tcp_socket_state_unbound_t unbound; - if (socket->state_tag == TCP_SOCKET_STATE_UNBOUND) { - unbound = socket->state.unbound; - } else { - errno = EINVAL; - return -1; - } - - wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; - reactor_borrow_network_t network_borrow = __wasi_sockets_utils__borrow_network(); - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); - - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_bind(socket_borrow, network_borrow, address, &error)) { - errno = __wasi_sockets_utils__map_error(error); - return -1; - } - - // Bind has successfully started. Attempt to finish it: - while (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_bind(socket_borrow, &error)) { - if (error == WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK) { - reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(socket->socket_pollable); - wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); - } else { - errno = __wasi_sockets_utils__map_error(error); - return -1; - } - } - - // Bind successful. - - socket->state_tag = TCP_SOCKET_STATE_BOUND; - socket->state = (tcp_socket_state_t){ .bound = { /* No additional state */ } }; - return 0; + return __wasi_sockets_utils__tcp_bind(socket, address); } int udp_bind(udp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) { diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c index cce96b046..ee68618ca 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c @@ -1,18 +1,32 @@ #include #include +#include #include #include "__utils.h" int tcp_listen(tcp_socket_t* socket, int backlog) { + wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; + reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + switch (socket->state_tag) { - case TCP_SOCKET_STATE_UNBOUND: - // TODO: perform implicit bind and then continue with this listen operation. - errno = EDESTADDRREQ; - return -1; + case TCP_SOCKET_STATE_UNBOUND: { + // Socket is not explicitly bound by the user. We'll do it for them: + + wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_address_family_t family = wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(socket_borrow); + wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t any = __wasi_sockets_utils__any_addr(family); + int result = __wasi_sockets_utils__tcp_bind(socket, &any); + if (result != 0) { + return result; + } + + assert(socket->state_tag == TCP_SOCKET_STATE_BOUND); + // Great! We'll continue below. + break; + } case TCP_SOCKET_STATE_BOUND: - // These can initiate a connect. + // Great! We'll continue below. break; case TCP_SOCKET_STATE_LISTENING: // We can only update the backlog size. @@ -25,9 +39,6 @@ int tcp_listen(tcp_socket_t* socket, int backlog) { return -1; } - wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_listen_backlog_size(socket_borrow, backlog, &error)) { abort(); // Our own state checks should've prevented this from happening. } From a00da21ee74c516c97591c2d19f4edb8328d4eab Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Sun, 3 Dec 2023 21:16:37 +0100 Subject: [PATCH 09/63] Implement MSG_DONTWAIT flag --- .../cloudlibc/src/libc/sys/socket/recv.c | 12 +++++++++--- .../cloudlibc/src/libc/sys/socket/send.c | 13 +++++++++---- .../headers/public/__header_sys_socket.h | 1 + 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index 4484ef3ba..3945616d7 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -18,12 +18,13 @@ static_assert(MSG_WAITALL == __WASI_RIFLAGS_RECV_WAITALL, "Value mismatch"); ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int flags) { // TODO: flags: - // - MSG_DONTWAIT, MSG_WAITALL: we can probably support these relatively easy. + // - MSG_WAITALL: we can probably support these relatively easy. // - MSG_OOB: could be shimed by always responding that no OOB data is available. // - MSG_PEEK: could be shimmed by performing the receive into a local socket-specific buffer. And on subsequent receives first check that buffer. // - MSG_TRUNC: return EOPNOTSUPP. Is UDP only. // - MSG_EOR, MSG_CMSG_CLOEXEC: return EOPNOTSUPP. Is not supported on TCP or UDP. - if (flags != 0) { + const int supported_flags = MSG_DONTWAIT; + if ((flags & supported_flags) != flags) { errno = EOPNOTSUPP; return -1; } @@ -36,6 +37,11 @@ ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int return -1; } + bool should_block = socket->blocking; + if ((flags & MSG_DONTWAIT) != 0) { + should_block = false; + } + reactor_borrow_input_stream_t rx_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(connection.input); while (true) { reactor_list_u8_t result; @@ -50,7 +56,7 @@ ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int memcpy(buffer, result.ptr, result.len); reactor_list_u8_free(&result); return result.len; - } else if (socket->blocking) { + } else if (should_block) { reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(connection.input_pollable); wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); } else { diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c index 173003154..946a68641 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c @@ -14,11 +14,11 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int flags) { // TODO: flags: - // - MSG_DONTWAIT: we can probably support this relatively easy. // - MSG_NOSIGNAL: ignore it. This is always the case. https://github.com/WebAssembly/wasi-sockets/blob/main/Posix-compatibility.md#writing-to-closed-streams-sigpipe-so_nosigpipe- // - MSG_OOB: Not supported in WASI // - MSG_EOR: Not supported in TCP/UDP in general. - if (flags != 0) { + const int supported_flags = MSG_DONTWAIT; + if ((flags & supported_flags) != flags) { errno = EOPNOTSUPP; return -1; } @@ -31,6 +31,11 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int fl return -1; } + bool should_block = socket->blocking; + if ((flags & MSG_DONTWAIT) != 0) { + should_block = false; + } + reactor_borrow_output_stream_t tx_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(connection.output); while (true) { wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; @@ -51,11 +56,11 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int fl } else { return count; } - } else if (socket->blocking) { + } else if (should_block) { reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(connection.output_pollable); wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); } else { - errno = EAGAIN; + errno = EWOULDBLOCK; return -1; } } diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index 525b9e6a5..2c564102c 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -11,6 +11,7 @@ #define SHUT_WR __WASI_SDFLAGS_WR #define SHUT_RDWR (SHUT_RD | SHUT_WR) +#define MSG_DONTWAIT 0x0040 #define MSG_PEEK __WASI_RIFLAGS_RECV_PEEK #define MSG_WAITALL __WASI_RIFLAGS_RECV_WAITALL #define MSG_TRUNC __WASI_ROFLAGS_RECV_DATA_TRUNCATED From b120ad4afebb8788b876fd01af841a6851512366 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Sun, 3 Dec 2023 21:41:01 +0100 Subject: [PATCH 10/63] "Implement" MSG_NOSIGNAL --- .../cloudlibc/src/libc/sys/socket/send.c | 12 +++++++----- .../headers/public/__header_sys_socket.h | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c index 946a68641..9e149a6bf 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c @@ -13,11 +13,7 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int flags) { - // TODO: flags: - // - MSG_NOSIGNAL: ignore it. This is always the case. https://github.com/WebAssembly/wasi-sockets/blob/main/Posix-compatibility.md#writing-to-closed-streams-sigpipe-so_nosigpipe- - // - MSG_OOB: Not supported in WASI - // - MSG_EOR: Not supported in TCP/UDP in general. - const int supported_flags = MSG_DONTWAIT; + const int supported_flags = MSG_DONTWAIT | MSG_NOSIGNAL; if ((flags & supported_flags) != flags) { errno = EOPNOTSUPP; return -1; @@ -36,6 +32,12 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int fl should_block = false; } + if ((flags & MSG_NOSIGNAL) != 0) { + // Ignore it. WASI has no Unix-style signals. So effectively, + // MSG_NOSIGNAL is always the case, whether it was explicitly + // requested or not. + } + reactor_borrow_output_stream_t tx_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(connection.output); while (true) { wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index 2c564102c..6a08a31ba 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -12,6 +12,7 @@ #define SHUT_RDWR (SHUT_RD | SHUT_WR) #define MSG_DONTWAIT 0x0040 +#define MSG_NOSIGNAL 0x4000 #define MSG_PEEK __WASI_RIFLAGS_RECV_PEEK #define MSG_WAITALL __WASI_RIFLAGS_RECV_WAITALL #define MSG_TRUNC __WASI_ROFLAGS_RECV_DATA_TRUNCATED From ee04f9ed828c3ea3e6006196b1bfdf6cc7462939 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Sun, 3 Dec 2023 21:47:17 +0100 Subject: [PATCH 11/63] No need for these constant to match their preview1 counterparts anymore, now that sockets are fully based on preview2 --- libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c | 3 --- libc-bottom-half/headers/public/__header_sys_socket.h | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index 3945616d7..5106ec3fc 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -12,9 +12,6 @@ #include #include "__utils.h" -static_assert(MSG_PEEK == __WASI_RIFLAGS_RECV_PEEK, "Value mismatch"); -static_assert(MSG_WAITALL == __WASI_RIFLAGS_RECV_WAITALL, "Value mismatch"); - ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int flags) { // TODO: flags: diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index 6a08a31ba..4152df591 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -13,9 +13,9 @@ #define MSG_DONTWAIT 0x0040 #define MSG_NOSIGNAL 0x4000 -#define MSG_PEEK __WASI_RIFLAGS_RECV_PEEK -#define MSG_WAITALL __WASI_RIFLAGS_RECV_WAITALL -#define MSG_TRUNC __WASI_ROFLAGS_RECV_DATA_TRUNCATED +#define MSG_PEEK 0x0002 +#define MSG_WAITALL 0x0100 +#define MSG_TRUNC 0x0020 #define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM #define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM From ea2fcf0b86a519fe8baeda3b47e5f2485ef559ac Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Mon, 4 Dec 2023 19:22:02 +0100 Subject: [PATCH 12/63] Make my own TODOs easier to find --- .../cloudlibc/src/libc/sys/socket/__utils.c | 8 +-- .../cloudlibc/src/libc/sys/socket/accept.c | 4 +- .../cloudlibc/src/libc/sys/socket/bind.c | 2 +- .../cloudlibc/src/libc/sys/socket/connect.c | 2 +- .../src/libc/sys/socket/getsockpeername.c | 4 +- .../cloudlibc/src/libc/sys/socket/netdb.c | 4 +- .../cloudlibc/src/libc/sys/socket/recv.c | 6 +-- .../cloudlibc/src/libc/sys/socket/send.c | 6 +-- .../cloudlibc/src/libc/sys/socket/shutdown.c | 4 +- .../cloudlibc/src/libc/sys/socket/socket.c | 2 +- .../cloudlibc/src/libc/sys/socket/sockopt.c | 52 +++++++++---------- .../headers/public/__header_sys_socket.h | 2 +- libc-top-half/musl/include/sys/socket.h | 4 +- 13 files changed, 50 insertions(+), 50 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c index 07ae380cf..6e7ea14fb 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c @@ -103,7 +103,7 @@ bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen (((unsigned short)ip[12]) << 8) | ip[13], (((unsigned short)ip[14]) << 8) | ip[15], }, - // TODO: do these need to be endian-reversed? + // TODO wasi-sockets: do these need to be endian-reversed? .flow_info = ipv6->sin6_flowinfo, .scope_id = ipv6->sin6_scope_id, } } @@ -139,7 +139,7 @@ bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18 *ipv4 = (struct sockaddr_in) { .sin_family = AF_INET, .sin_port = htons(address->val.ipv4.port), - .sin_addr = { .s_addr = 0 }, // TODO + .sin_addr = { .s_addr = 0 }, // TODO wasi-sockets }; return true; } @@ -156,8 +156,8 @@ bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18 *ipv6 = (struct sockaddr_in6) { .sin6_family = AF_INET, .sin6_port = htons(address->val.ipv6.port), - .sin6_addr = { .s6_addr = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, // TODO - // TODO: do these need to be endian-reversed? + .sin6_addr = { .s6_addr = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, // TODO wasi-sockets + // TODO wasi-sockets: do these need to be endian-reversed? .sin6_flowinfo = address->val.ipv6.flow_info, .sin6_scope_id = address->val.ipv6.scope_id, }; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c index 2418ee1e6..e0d55cd40 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c @@ -49,7 +49,7 @@ bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, w if (out_address != NULL) { if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_remote_address(client_borrow, out_address, &error)) { - // TODO: How to recover from this in a POSIX compatible way? + // TODO wasi-sockets: How to recover from this in a POSIX compatible way? abort(); } } @@ -140,7 +140,7 @@ int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addr assert(out_address_ptr != NULL); if (!__wasi_sockets_utils__format_address(&out_address, addr, addrlen, &err)) { - abort(); // TODO: validate provided buffer length _before_ doing the actual accept wasi call. + abort(); // TODO wasi-sockets: validate provided buffer length _before_ doing the actual accept wasi call. } } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c index ccf71cd76..b28fcf140 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c @@ -9,7 +9,7 @@ int tcp_bind(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_s } int udp_bind(udp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) { - // TODO: implement + // TODO wasi-sockets: implement errno = EOPNOTSUPP; return -1; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c index ee143cab2..37a519efe 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c @@ -82,7 +82,7 @@ int tcp_connect(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_i int udp_connect(udp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) { - // TODO: implement + // TODO wasi-sockets: implement errno = EOPNOTSUPP; return -1; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c index 53c0148c9..3ec3bb074 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c @@ -30,14 +30,14 @@ bool tcp_getpeername(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_netw bool udp_getsockname(udp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address) { - // TODO: implement + // TODO wasi-sockets: implement errno = EOPNOTSUPP; return -1; } bool udp_getpeername(udp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address) { - // TODO: implement + // TODO wasi-sockets: implement errno = EOPNOTSUPP; return -1; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c index 4aeabca80..794f3d8a1 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c @@ -3,12 +3,12 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const struct addrinfo *restrict hint, struct addrinfo **restrict res) { - // TODO + // TODO wasi-sockets abort(); } void freeaddrinfo(struct addrinfo *p) { - // TODO + // TODO wasi-sockets abort(); } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index 5106ec3fc..e06425ebd 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -14,7 +14,7 @@ ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int flags) { - // TODO: flags: + // TODO wasi-sockets: flags: // - MSG_WAITALL: we can probably support these relatively easy. // - MSG_OOB: could be shimed by always responding that no OOB data is available. // - MSG_PEEK: could be shimmed by performing the receive into a local socket-specific buffer. And on subsequent receives first check that buffer. @@ -44,7 +44,7 @@ ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int reactor_list_u8_t result; wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_read(rx_borrow, length, &result, &error)) { - // TODO: wasi-sockets has no way to recover stream errors yet. + // TODO wasi-sockets: wasi-sockets has no way to recover stream errors yet. errno = EPIPE; return -1; } @@ -65,7 +65,7 @@ ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int ssize_t udp_recv(udp_socket_t* socket, void* restrict buffer, size_t length, int flags) { - // TODO: Implement flags. Same as tcp_recv except that MSG_TRUNC is valid for UDP. + // TODO wasi-sockets: Implement flags. Same as tcp_recv except that MSG_TRUNC is valid for UDP. errno = EOPNOTSUPP; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c index 9e149a6bf..e657b7a80 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c @@ -43,7 +43,7 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int fl wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; uint64_t count; if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_check_write(tx_borrow, &count, &error)) { - // TODO: wasi-sockets has no way to recover stream errors yet. + // TODO wasi-sockets: wasi-sockets has no way to recover stream errors yet. errno = EPIPE; return -1; } @@ -52,7 +52,7 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int fl count = count < length ? count : length; reactor_list_u8_t list = { .ptr = (uint8_t*)buffer, .len = count }; if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write(tx_borrow, &list, &error)) { - // TODO: wasi-sockets has no way to recover stream errors yet. + // TODO wasi-sockets: wasi-sockets has no way to recover stream errors yet. errno = EPIPE; return -1; } else { @@ -70,7 +70,7 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int fl ssize_t udp_send(udp_socket_t* socket, const void* buffer, size_t length, int flags) { - // TODO: Implement flags. Same as tcp_send. + // TODO wasi-sockets: Implement flags. Same as tcp_send. errno = EOPNOTSUPP; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c index 956b955e5..7607a2d23 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c @@ -49,11 +49,11 @@ int tcp_shutdown(tcp_socket_t* socket, int posix_how) } if (posix_how == SHUT_RD || posix_how == SHUT_RDWR) { - // TODO: drop input stream (if not already). And update `recv` to take dropped input streams into account. + // TODO wasi-sockets: drop input stream (if not already). And update `recv` to take dropped input streams into account. } if (posix_how == SHUT_WR || posix_how == SHUT_RDWR) { - // TODO: drop output stream (if not already). And update `send` to take dropped output streams into account. + // TODO wasi-sockets: drop output stream (if not already). And update `send` to take dropped output streams into account. } return 0; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c index 4ae49ebbd..a354cb96a 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c @@ -37,7 +37,7 @@ int tcp_socket(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t fami int udp_socket(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t family, bool blocking) { - // TODO: implement + // TODO wasi-sockets: implement errno = EPROTONOSUPPORT; return -1; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c index 96fc32ac8..3836a2c7a 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -48,7 +48,7 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, break; } case SO_ACCEPTCONN: { - // TODO: use 2023-11-10 snapshot to call out to tcp-socket::is-listening ? + // TODO wasi-sockets: use 2023-11-10 snapshot to call out to tcp-socket::is-listening ? value = socket->state_tag == TCP_SOCKET_STATE_LISTENING; break; } @@ -90,8 +90,8 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, value = result; break; } - case SO_RCVTIMEO: // TODO: emulate in wasi-libc itself - case SO_SNDTIMEO: // TODO: emulate in wasi-libc itself + case SO_RCVTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself + case SO_SNDTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself default: errno = ENOPROTOOPT; return -1; @@ -163,9 +163,9 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, case SOL_TCP: switch (optname) { - case TCP_KEEPIDLE: // TODO: implement using the 2023-11-10 preview2 snapshot. - case TCP_KEEPINTVL: // TODO: implement using the 2023-11-10 preview2 snapshot. - case TCP_KEEPCNT: // TODO: implement using the 2023-11-10 preview2 snapshot. + case TCP_KEEPIDLE: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. + case TCP_KEEPINTVL: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. + case TCP_KEEPCNT: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. default: errno = ENOPROTOOPT; return -1; @@ -220,8 +220,8 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt return 0; } - case SO_RCVTIMEO: // TODO: emulate in wasi-libc itself - case SO_SNDTIMEO: // TODO: emulate in wasi-libc itself + case SO_RCVTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself + case SO_SNDTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself default: errno = ENOPROTOOPT; return -1; @@ -297,9 +297,9 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt case SOL_TCP: switch (optname) { - case TCP_KEEPIDLE: // TODO: implement using the 2023-11-10 preview2 snapshot. - case TCP_KEEPINTVL: // TODO: implement using the 2023-11-10 preview2 snapshot. - case TCP_KEEPCNT: // TODO: implement using the 2023-11-10 preview2 snapshot. + case TCP_KEEPIDLE: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. + case TCP_KEEPINTVL: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. + case TCP_KEEPCNT: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. default: errno = ENOPROTOOPT; return -1; @@ -328,11 +328,11 @@ int udp_getsockopt(udp_socket_t* socket, int level, int optname, case SO_PROTOCOL: value = IPPROTO_TCP; break; - case SO_DOMAIN: // TODO: implement - case SO_RCVBUF: // TODO: implement - case SO_SNDBUF: // TODO: implement - case SO_RCVTIMEO: // TODO: emulate in wasi-libc itself - case SO_SNDTIMEO: // TODO: emulate in wasi-libc itself + case SO_DOMAIN: // TODO wasi-sockets: implement + case SO_RCVBUF: // TODO wasi-sockets: implement + case SO_SNDBUF: // TODO wasi-sockets: implement + case SO_RCVTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself + case SO_SNDTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself default: errno = ENOPROTOOPT; return -1; @@ -342,7 +342,7 @@ int udp_getsockopt(udp_socket_t* socket, int level, int optname, case SOL_IP: switch (optname) { - case IP_TTL: // TODO: implement + case IP_TTL: // TODO wasi-sockets: implement default: errno = ENOPROTOOPT; return -1; @@ -352,8 +352,8 @@ int udp_getsockopt(udp_socket_t* socket, int level, int optname, case SOL_IPV6: switch (optname) { - case IPV6_V6ONLY: // TODO: implement - case IPV6_UNICAST_HOPS: // TODO: implement + case IPV6_V6ONLY: // TODO wasi-sockets: implement + case IPV6_UNICAST_HOPS: // TODO wasi-sockets: implement default: errno = ENOPROTOOPT; return -1; @@ -378,10 +378,10 @@ int udp_setsockopt(udp_socket_t* socket, int level, int optname, const void* opt { case SOL_SOCKET: switch (optname) { - case SO_RCVBUF: // TODO: implement - case SO_SNDBUF: // TODO: implement - case SO_RCVTIMEO: // TODO: emulate in wasi-libc itself - case SO_SNDTIMEO: // TODO: emulate in wasi-libc itself + case SO_RCVBUF: // TODO wasi-sockets: implement + case SO_SNDBUF: // TODO wasi-sockets: implement + case SO_RCVTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself + case SO_SNDTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself default: errno = ENOPROTOOPT; return -1; @@ -391,7 +391,7 @@ int udp_setsockopt(udp_socket_t* socket, int level, int optname, const void* opt case SOL_IP: switch (optname) { - case IP_TTL: // TODO: implement + case IP_TTL: // TODO wasi-sockets: implement default: errno = ENOPROTOOPT; return -1; @@ -401,8 +401,8 @@ int udp_setsockopt(udp_socket_t* socket, int level, int optname, const void* opt case SOL_IPV6: switch (optname) { - case IPV6_V6ONLY: // TODO: implement - case IPV6_UNICAST_HOPS: // TODO: implement + case IPV6_V6ONLY: // TODO wasi-sockets: implement + case IPV6_UNICAST_HOPS: // TODO wasi-sockets: implement default: errno = ENOPROTOOPT; return -1; diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index 4152df591..ab1063482 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -46,7 +46,7 @@ #define SO_SNDTIMEO 21 #endif -// TODO: These should be in +// TODO wasi-sockets: These should be in #define TCP_KEEPIDLE 4 #define TCP_KEEPINTVL 5 #define TCP_KEEPCNT 6 diff --git a/libc-top-half/musl/include/sys/socket.h b/libc-top-half/musl/include/sys/socket.h index 4fbadbe17..8b92c34c9 100644 --- a/libc-top-half/musl/include/sys/socket.h +++ b/libc-top-half/musl/include/sys/socket.h @@ -75,7 +75,7 @@ struct mmsghdr { struct timespec; -// TODO: implement +// TODO wasi-sockets: implement int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int); int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *); #endif @@ -415,7 +415,7 @@ int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); ssize_t send (int, const void *, size_t, int); ssize_t recv (int, void *, size_t, int); -#ifdef __wasilibc_unmodified_upstream /* TODO: implement */ +#ifdef __wasilibc_unmodified_upstream /* TODO wasi-sockets: implement */ ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); ssize_t sendmsg (int, const struct msghdr *, int); From 6cf2c3b521aa7e414c58205c76119f83e969ac78 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Mon, 4 Dec 2023 20:02:23 +0100 Subject: [PATCH 13/63] Decode IP addresses --- .../cloudlibc/src/libc/sys/socket/__utils.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c index 6e7ea14fb..725c6e1ce 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c @@ -139,7 +139,7 @@ bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18 *ipv4 = (struct sockaddr_in) { .sin_family = AF_INET, .sin_port = htons(address->val.ipv4.port), - .sin_addr = { .s_addr = 0 }, // TODO wasi-sockets + .sin_addr = { .s_addr = ip.f0 | (ip.f1 << 8) | (ip.f2 << 16) | (ip.f3 << 24) }, }; return true; } @@ -156,7 +156,16 @@ bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18 *ipv6 = (struct sockaddr_in6) { .sin6_family = AF_INET, .sin6_port = htons(address->val.ipv6.port), - .sin6_addr = { .s6_addr = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, // TODO wasi-sockets + .sin6_addr = { .s6_addr = { + ip.f0 >> 8, ip.f0 & 0xFF, + ip.f1 >> 8, ip.f1 & 0xFF, + ip.f2 >> 8, ip.f2 & 0xFF, + ip.f3 >> 8, ip.f3 & 0xFF, + ip.f4 >> 8, ip.f4 & 0xFF, + ip.f5 >> 8, ip.f5 & 0xFF, + ip.f6 >> 8, ip.f6 & 0xFF, + ip.f7 >> 8, ip.f7 & 0xFF, + } }, // TODO wasi-sockets: do these need to be endian-reversed? .sin6_flowinfo = address->val.ipv6.flow_info, .sin6_scope_id = address->val.ipv6.scope_id, From 76160c31e703301c3231c6fca1d34ef49eaff1e2 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Mon, 4 Dec 2023 20:13:38 +0100 Subject: [PATCH 14/63] Replace assert with abort --- libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c | 5 ++--- libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c index 725c6e1ce..e1e724bdf 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c @@ -1,4 +1,3 @@ -#include #include #include "__utils.h" @@ -36,13 +35,13 @@ int __wasi_sockets_utils__map_error(wasi_sockets_0_2_0_rc_2023_10_18_network_err case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_INVALID_STATE: case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NOT_IN_PROGRESS: - assert(false /* If our internal state checks are working right, these errors should never show up. */); + abort(); // If our internal state checks are working right, these errors should never show up. break; case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NAME_UNRESOLVABLE: case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE: case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE: - assert(false /* These errors are specific to getaddrinfo, which should have filtered these errors out before calling this generic method */); + abort(); // These errors are specific to getaddrinfo, which should have filtered these errors out before calling this generic method break; case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_UNKNOWN: diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index e06425ebd..6262a7c47 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -4,7 +4,6 @@ #include -#include #include #include #include From 6bb179a2b7564a7a55a64436975d6e823dd866a7 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Mon, 4 Dec 2023 20:28:24 +0100 Subject: [PATCH 15/63] Update libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c Co-authored-by: Joel Dice --- libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index 6262a7c47..9ac38264a 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -15,7 +15,7 @@ ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int { // TODO wasi-sockets: flags: // - MSG_WAITALL: we can probably support these relatively easy. - // - MSG_OOB: could be shimed by always responding that no OOB data is available. + // - MSG_OOB: could be shimmed by always responding that no OOB data is available. // - MSG_PEEK: could be shimmed by performing the receive into a local socket-specific buffer. And on subsequent receives first check that buffer. // - MSG_TRUNC: return EOPNOTSUPP. Is UDP only. // - MSG_EOR, MSG_CMSG_CLOEXEC: return EOPNOTSUPP. Is not supported on TCP or UDP. From 74b703e837cd34d20abf5668bb86592b4a114c8c Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 4 Dec 2023 17:07:59 -0700 Subject: [PATCH 16/63] add `TCP_NODELAY` support Signed-off-by: Joel Dice --- .../cloudlibc/src/libc/sys/socket/sockopt.c | 11 ++++++++++- libc-bottom-half/headers/public/__header_sys_socket.h | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c index 3836a2c7a..c7959ac62 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -297,6 +297,15 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt case SOL_TCP: switch (optname) { + case TCP_NODELAY: { + if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_no_delay(socket_borrow, intval != 0, &error)) { + return 0; + } else { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + } + case TCP_KEEPIDLE: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. case TCP_KEEPINTVL: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. case TCP_KEEPCNT: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. @@ -467,4 +476,4 @@ int setsockopt(int sockfd, int level, int optname, const void* optval, socklen_t errno = ENOPROTOOPT; return -1; } -} \ No newline at end of file +} diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index ab1063482..bb41677d6 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -47,6 +47,7 @@ #endif // TODO wasi-sockets: These should be in +#define TCP_NODELAY 1 #define TCP_KEEPIDLE 4 #define TCP_KEEPINTVL 5 #define TCP_KEEPCNT 6 From 076265144351ff1aee6ba450522d2d804d5c8ca3 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Tue, 5 Dec 2023 21:42:06 +0100 Subject: [PATCH 17/63] Update to preview2 version rc-2023-11-10. And use the new --rename option of wit-bindgen to generate shorter names. The full command used to generate the bindings was: wit-bindgen c --world imports \ --rename wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10=monotonic_clock \ --rename wasi:clocks/wall-clock@0.2.0-rc-2023-11-10=wall_clock \ --rename wasi:filesystem/preopens@0.2.0-rc-2023-11-10=filesystem_preopens \ --rename wasi:filesystem/types@0.2.0-rc-2023-11-10=filesystem \ --rename wasi:io/error@0.2.0-rc-2023-11-10=io_error \ --rename wasi:io/poll@0.2.0-rc-2023-11-10=poll \ --rename wasi:io/streams@0.2.0-rc-2023-11-10=streams \ --rename wasi:random/insecure-seed@0.2.0-rc-2023-11-10=random_insecure_seed \ --rename wasi:random/insecure@0.2.0-rc-2023-11-10=random_insecure \ --rename wasi:random/random@0.2.0-rc-2023-11-10=random \ --rename wasi:sockets/instance-network@0.2.0-rc-2023-11-10=instance_network \ --rename wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10=ip_name_lookup \ --rename wasi:sockets/network@0.2.0-rc-2023-11-10=network \ --rename wasi:sockets/tcp-create-socket@0.2.0-rc-2023-11-10=tcp_create_socket \ --rename wasi:sockets/tcp@0.2.0-rc-2023-11-10=tcp \ --rename wasi:sockets/udp-create-socket@0.2.0-rc-2023-11-10=udp_create_socket \ --rename wasi:sockets/udp@0.2.0-rc-2023-11-10=udp \ --rename wasi:cli/environment@0.2.0-rc-2023-11-10=environment \ --rename wasi:cli/exit@0.2.0-rc-2023-11-10=exit \ --rename wasi:cli/stdin@0.2.0-rc-2023-11-10=stdin \ --rename wasi:cli/stdout@0.2.0-rc-2023-11-10=stdout \ --rename wasi:cli/stderr@0.2.0-rc-2023-11-10=stderr \ ./wit --- Makefile | 4 +- .../cloudlibc/src/libc/sys/socket/__utils.c | 112 +- .../cloudlibc/src/libc/sys/socket/__utils.h | 14 +- .../cloudlibc/src/libc/sys/socket/accept.c | 42 +- .../cloudlibc/src/libc/sys/socket/bind.c | 6 +- .../cloudlibc/src/libc/sys/socket/connect.c | 36 +- .../src/libc/sys/socket/getsockpeername.c | 24 +- .../cloudlibc/src/libc/sys/socket/listen.c | 22 +- .../cloudlibc/src/libc/sys/socket/recv.c | 14 +- .../cloudlibc/src/libc/sys/socket/send.c | 14 +- .../cloudlibc/src/libc/sys/socket/shutdown.c | 14 +- .../cloudlibc/src/libc/sys/socket/socket.c | 20 +- .../cloudlibc/src/libc/sys/socket/sockopt.c | 50 +- .../src/libc/sys/wasi_preview2/preview2.c | 4479 ++++++++++++++++ .../wasi_preview2/preview2_component_type.o | Bin 0 -> 26798 bytes .../src/libc/sys/wasi_preview2/reactor.c | 4587 ----------------- .../wasi_preview2/reactor_component_type.o | Bin 38549 -> 0 bytes .../headers/private/descriptor_table.h | 18 +- libc-bottom-half/headers/private/preview2.h | 2481 +++++++++ libc-bottom-half/headers/private/reactor.h | 2043 -------- .../sources/__wasilibc_fd_renumber.c | 12 +- 21 files changed, 7161 insertions(+), 6831 deletions(-) create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c create mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2_component_type.o delete mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor.c delete mode 100644 libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor_component_type.o create mode 100644 libc-bottom-half/headers/private/preview2.h delete mode 100644 libc-bottom-half/headers/private/reactor.h diff --git a/Makefile b/Makefile index cf93d7a67..7181421ab 100644 --- a/Makefile +++ b/Makefile @@ -357,7 +357,7 @@ DLMALLOC_OBJS = $(call objs,$(DLMALLOC_SOURCES)) EMMALLOC_OBJS = $(call objs,$(EMMALLOC_SOURCES)) LIBC_BOTTOM_HALF_ALL_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_ALL_SOURCES)) LIBC_TOP_HALF_ALL_OBJS = $(call asmobjs,$(call objs,$(LIBC_TOP_HALF_ALL_SOURCES))) -LIBC_OBJS += $(OBJDIR)/reactor_component_type.o +LIBC_OBJS += $(OBJDIR)/preview2_component_type.o ifeq ($(MALLOC_IMPL),dlmalloc) LIBC_OBJS += $(DLMALLOC_OBJS) else ifeq ($(MALLOC_IMPL),emmalloc) @@ -578,7 +578,7 @@ $(OBJDIR)/%.long-double.pic.o: %.c include_dirs @mkdir -p "$(@D)" $(CC) $(CFLAGS) -MD -MP -o $@ -c $< -$(OBJDIR)/reactor_component_type.pic.o $(OBJDIR)/reactor_component_type.o: $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)/libc/sys/wasi_preview2/reactor_component_type.o +$(OBJDIR)/preview2_component_type.pic.o $(OBJDIR)/preview2_component_type.o: $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)/libc/sys/wasi_preview2/preview2_component_type.o @mkdir -p "$(@D)" cp $< $@ diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c index e1e724bdf..3c8fe692e 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c @@ -2,55 +2,55 @@ #include "__utils.h" -static reactor_own_network_t global_network; +static network_own_network_t global_network; static bool global_network_initialized = false; -reactor_borrow_network_t __wasi_sockets_utils__borrow_network() { +network_borrow_network_t __wasi_sockets_utils__borrow_network() { if (!global_network_initialized) { - global_network = wasi_sockets_0_2_0_rc_2023_10_18_instance_network_instance_network(); + global_network = instance_network_instance_network(); global_network_initialized = true; } - return wasi_sockets_0_2_0_rc_2023_10_18_network_borrow_network(global_network); + return network_borrow_network(global_network); } -int __wasi_sockets_utils__map_error(wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_error) { +int __wasi_sockets_utils__map_error(network_error_code_t wasi_error) { switch (wasi_error) { - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_ACCESS_DENIED: return EACCES; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NOT_SUPPORTED: return EOPNOTSUPP; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_INVALID_ARGUMENT: return EINVAL; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_OUT_OF_MEMORY: return ENOMEM; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_TIMEOUT: return ETIMEDOUT; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONCURRENCY_CONFLICT: return EALREADY; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK: return EWOULDBLOCK; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NEW_SOCKET_LIMIT: return EMFILE; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_ADDRESS_NOT_BINDABLE: return EADDRNOTAVAIL; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_ADDRESS_IN_USE: return EADDRINUSE; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_REMOTE_UNREACHABLE: return EHOSTUNREACH; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONNECTION_REFUSED: return ECONNREFUSED; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONNECTION_RESET: return ECONNRESET; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONNECTION_ABORTED: return ECONNABORTED; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE: return EMSGSIZE; - - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_INVALID_STATE: - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NOT_IN_PROGRESS: + case NETWORK_ERROR_CODE_ACCESS_DENIED: return EACCES; + case NETWORK_ERROR_CODE_NOT_SUPPORTED: return EOPNOTSUPP; + case NETWORK_ERROR_CODE_INVALID_ARGUMENT: return EINVAL; + case NETWORK_ERROR_CODE_OUT_OF_MEMORY: return ENOMEM; + case NETWORK_ERROR_CODE_TIMEOUT: return ETIMEDOUT; + 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: return EADDRNOTAVAIL; + case NETWORK_ERROR_CODE_ADDRESS_IN_USE: return EADDRINUSE; + case NETWORK_ERROR_CODE_REMOTE_UNREACHABLE: return EHOSTUNREACH; + case NETWORK_ERROR_CODE_CONNECTION_REFUSED: return ECONNREFUSED; + case NETWORK_ERROR_CODE_CONNECTION_RESET: return ECONNRESET; + case NETWORK_ERROR_CODE_CONNECTION_ABORTED: return ECONNABORTED; + case NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE: return EMSGSIZE; + + case NETWORK_ERROR_CODE_INVALID_STATE: + case NETWORK_ERROR_CODE_NOT_IN_PROGRESS: abort(); // If our internal state checks are working right, these errors should never show up. break; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NAME_UNRESOLVABLE: - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE: - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE: + 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; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_UNKNOWN: + case NETWORK_ERROR_CODE_UNKNOWN: default: return EOPNOTSUPP; } } -bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen_t len, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* output, int* error) +bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen_t len, network_ip_socket_address_t* output, int* error) { *error = 0; @@ -70,8 +70,8 @@ bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen struct sockaddr_in* ipv4 = (struct sockaddr_in*)address; unsigned ip = ipv4->sin_addr.s_addr; unsigned short port = ipv4->sin_port; - *output = (wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t){ - .tag = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV4, + *output = (network_ip_socket_address_t){ + .tag = NETWORK_IP_SOCKET_ADDRESS_IPV4, .val = { .ipv4 = { .port = ntohs(port), // (port << 8) | (port >> 8), .address = { ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24 }, @@ -88,8 +88,8 @@ bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)address; unsigned char* ip = (unsigned char*)&(ipv6->sin6_addr.s6_addr); unsigned short port = ipv6->sin6_port; - *output = (wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t){ - .tag = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV6, + *output = (network_ip_socket_address_t){ + .tag = NETWORK_IP_SOCKET_ADDRESS_IPV6, .val = { .ipv6 = { .port = ntohs(port), .address = { @@ -115,7 +115,7 @@ bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen } } -bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address, struct sockaddr* output_addr, socklen_t* output_addrlen, int* error) { +bool __wasi_sockets_utils__format_address(const network_ip_socket_address_t* address, struct sockaddr* output_addr, socklen_t* output_addrlen, int* error) { *error = 0; if (output_addr == NULL || output_addrlen == NULL) { @@ -125,7 +125,7 @@ bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18 switch (address->tag) { - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV4: { + case NETWORK_IP_SOCKET_ADDRESS_IPV4: { if (*output_addrlen < sizeof(struct sockaddr_in)) { *error = EINVAL; return false; @@ -133,7 +133,7 @@ bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18 *output_addrlen = sizeof(struct sockaddr_in); struct sockaddr_in* ipv4 = (struct sockaddr_in*)output_addr; - wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t ip = address->val.ipv4.address; + network_ipv4_address_t ip = address->val.ipv4.address; *ipv4 = (struct sockaddr_in) { .sin_family = AF_INET, @@ -142,7 +142,7 @@ bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18 }; return true; } - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV6: { + case NETWORK_IP_SOCKET_ADDRESS_IPV6: { if (*output_addrlen < sizeof(struct sockaddr_in6)) { *error = EINVAL; return false; @@ -150,7 +150,7 @@ bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18 *output_addrlen = sizeof(struct sockaddr_in6); struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)output_addr; - wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t ip = address->val.ipv6.address; + network_ipv6_address_t ip = address->val.ipv6.address; *ipv6 = (struct sockaddr_in6) { .sin6_family = AF_INET, @@ -175,29 +175,29 @@ bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18 } } -int __wasi_sockets_utils__posix_family(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_family) { +int __wasi_sockets_utils__posix_family(network_ip_address_family_t wasi_family) { switch (wasi_family) { - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4: return AF_INET; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6: return AF_INET6; + case NETWORK_IP_ADDRESS_FAMILY_IPV4: return AF_INET; + case NETWORK_IP_ADDRESS_FAMILY_IPV6: return AF_INET6; default: /* unreachable */ abort(); } } -wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t __wasi_sockets_utils__any_addr(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t family) { +network_ip_socket_address_t __wasi_sockets_utils__any_addr(network_ip_address_family_t family) { switch (family) { - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4: - return (wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t){ - .tag = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV4, + case NETWORK_IP_ADDRESS_FAMILY_IPV4: + return (network_ip_socket_address_t){ + .tag = NETWORK_IP_SOCKET_ADDRESS_IPV4, .val = { .ipv4 = { .port = 0, .address = { 0, 0, 0, 0 }, }} }; - case WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6: - return (wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t){ - .tag = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV6, + case NETWORK_IP_ADDRESS_FAMILY_IPV6: + return (network_ip_socket_address_t){ + .tag = NETWORK_IP_SOCKET_ADDRESS_IPV6, .val = { .ipv6 = { .port = 0, .address = { 0, 0, 0, 0, 0, 0, 0, 0 }, @@ -209,7 +209,7 @@ wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t __wasi_sockets_util } } -int __wasi_sockets_utils__tcp_bind(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) { +int __wasi_sockets_utils__tcp_bind(tcp_socket_t* socket, network_ip_socket_address_t* address) { tcp_socket_state_unbound_t unbound; if (socket->state_tag == TCP_SOCKET_STATE_UNBOUND) { @@ -219,20 +219,20 @@ int __wasi_sockets_utils__tcp_bind(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2 return -1; } - wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; - reactor_borrow_network_t network_borrow = __wasi_sockets_utils__borrow_network(); - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + network_error_code_t error; + network_borrow_network_t network_borrow = __wasi_sockets_utils__borrow_network(); + tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_bind(socket_borrow, network_borrow, address, &error)) { + if (!tcp_method_tcp_socket_start_bind(socket_borrow, network_borrow, address, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } // Bind has successfully started. Attempt to finish it: - while (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_bind(socket_borrow, &error)) { - if (error == WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK) { - reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(socket->socket_pollable); - wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + while (!tcp_method_tcp_socket_finish_bind(socket_borrow, &error)) { + if (error == NETWORK_ERROR_CODE_WOULD_BLOCK) { + poll_borrow_pollable_t pollable_borrow = poll_borrow_pollable(socket->socket_pollable); + poll_method_pollable_block(pollable_borrow); } else { errno = __wasi_sockets_utils__map_error(error); return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h index 1e70059a7..051b28932 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h @@ -5,12 +5,12 @@ #include -reactor_borrow_network_t __wasi_sockets_utils__borrow_network(); -int __wasi_sockets_utils__map_error(wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_error); -bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen_t len, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* output, int* error); -bool __wasi_sockets_utils__format_address(const wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address, struct sockaddr* output_addr, socklen_t* output_addrlen, int* error); -int __wasi_sockets_utils__posix_family(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_family); -wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t __wasi_sockets_utils__any_addr(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t family); -int __wasi_sockets_utils__tcp_bind(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address); +network_borrow_network_t __wasi_sockets_utils__borrow_network(); +int __wasi_sockets_utils__map_error(network_error_code_t wasi_error); +bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen_t len, network_ip_socket_address_t* output, int* error); +bool __wasi_sockets_utils__format_address(const network_ip_socket_address_t* address, struct sockaddr* output_addr, socklen_t* output_addrlen, int* error); +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); +int __wasi_sockets_utils__tcp_bind(tcp_socket_t* socket, network_ip_socket_address_t* address); #endif \ No newline at end of file diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c index e0d55cd40..01e8481f9 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c @@ -5,7 +5,7 @@ #include #include "__utils.h" -bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address, int* out_errno) { +bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, network_ip_socket_address_t* out_address, int* out_errno) { tcp_socket_state_listening_t listener; if (socket->state_tag == TCP_SOCKET_STATE_LISTENING) { @@ -15,15 +15,15 @@ bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, w return false; } - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); - reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t client_and_io; - wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; - while (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_accept(socket_borrow, &client_and_io, &error)) { - if (error == WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK) { + tcp_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t client_and_io; + network_error_code_t error; + while (!tcp_method_tcp_socket_accept(socket_borrow, &client_and_io, &error)) { + if (error == NETWORK_ERROR_CODE_WOULD_BLOCK) { if (socket->blocking) { - reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(socket->socket_pollable); - wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + poll_borrow_pollable_t pollable_borrow = poll_borrow_pollable(socket->socket_pollable); + poll_method_pollable_block(pollable_borrow); } else { *out_errno = EWOULDBLOCK; return false; @@ -34,21 +34,21 @@ bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, w } } - reactor_own_tcp_socket_t client = client_and_io.f0; - reactor_borrow_tcp_socket_t client_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(client); + tcp_own_tcp_socket_t client = client_and_io.f0; + tcp_borrow_tcp_socket_t client_borrow = tcp_borrow_tcp_socket(client); - reactor_own_pollable_t client_pollable = wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(client_borrow); + poll_own_pollable_t client_pollable = tcp_method_tcp_socket_subscribe(client_borrow); - reactor_own_input_stream_t input = client_and_io.f1; - reactor_borrow_input_stream_t input_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(input); - reactor_own_pollable_t input_pollable = wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe(input_borrow); + streams_own_input_stream_t input = client_and_io.f1; + streams_borrow_input_stream_t input_borrow = streams_borrow_input_stream(input); + poll_own_pollable_t input_pollable = streams_method_input_stream_subscribe(input_borrow); - reactor_own_output_stream_t output = client_and_io.f2; - reactor_borrow_output_stream_t output_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(output); - reactor_own_pollable_t output_pollable = wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe(output_borrow); + streams_own_output_stream_t output = client_and_io.f2; + streams_borrow_output_stream_t output_borrow = streams_borrow_output_stream(output); + poll_own_pollable_t output_pollable = streams_method_output_stream_subscribe(output_borrow); if (out_address != NULL) { - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_remote_address(client_borrow, out_address, &error)) { + if (!tcp_method_tcp_socket_remote_address(client_borrow, out_address, &error)) { // TODO wasi-sockets: How to recover from this in a POSIX compatible way? abort(); } @@ -78,7 +78,7 @@ bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, w return true; } -bool udp_accept(udp_socket_t* socket, bool client_blocking, int* out_clientfd, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address, int* out_errno) { +bool udp_accept(udp_socket_t* socket, bool client_blocking, int* out_clientfd, network_ip_socket_address_t* out_address, int* out_errno) { // UDP doesn't support accept *out_errno = EOPNOTSUPP; return false; @@ -112,8 +112,8 @@ int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addr bool client_blocking = (flags & SOCK_NONBLOCK) == 0; // Ignore SOCK_CLOEXEC flag. That concept does not exist in WASI. - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t out_address; - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address_ptr = addr != NULL ? &out_address : NULL; + network_ip_socket_address_t out_address; + network_ip_socket_address_t* out_address_ptr = addr != NULL ? &out_address : NULL; int client_fd; int err; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c index b28fcf140..4758fc749 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c @@ -4,11 +4,11 @@ #include #include "__utils.h" -int tcp_bind(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) { +int tcp_bind(tcp_socket_t* socket, network_ip_socket_address_t* address) { return __wasi_sockets_utils__tcp_bind(socket, address); } -int udp_bind(udp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) { +int udp_bind(udp_socket_t* socket, network_ip_socket_address_t* address) { // TODO wasi-sockets: implement errno = EOPNOTSUPP; return -1; @@ -22,7 +22,7 @@ int bind(int socket, const struct sockaddr* addr, socklen_t addrlen) { return -1; } - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t ip_address; + network_ip_socket_address_t ip_address; int parse_err; if (!__wasi_sockets_utils__parse_address(addr, addrlen, &ip_address, &parse_err)) { errno = parse_err; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c index 37a519efe..4e7efe923 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c @@ -5,7 +5,7 @@ #include "__utils.h" -int tcp_connect(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) +int tcp_connect(tcp_socket_t* socket, network_ip_socket_address_t* address) { switch (socket->state_tag) { case TCP_SOCKET_STATE_UNBOUND: @@ -25,11 +25,11 @@ int tcp_connect(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_i return -1; } - wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; - reactor_borrow_network_t network_borrow = __wasi_sockets_utils__borrow_network(); - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + network_error_code_t error; + network_borrow_network_t network_borrow = __wasi_sockets_utils__borrow_network(); + tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_connect(socket_borrow, network_borrow, address, &error)) { + if (!tcp_method_tcp_socket_start_connect(socket_borrow, network_borrow, address, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -39,12 +39,12 @@ int tcp_connect(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_i socket->state = (tcp_socket_state_t){ .connecting = { /* No additional state */ } }; // Attempt to finish it: - reactor_tuple2_own_input_stream_own_output_stream_t io; - while (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_connect(socket_borrow, &io, &error)) { - if (error == WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK) { + tcp_tuple2_own_input_stream_own_output_stream_t io; + while (!tcp_method_tcp_socket_finish_connect(socket_borrow, &io, &error)) { + if (error == NETWORK_ERROR_CODE_WOULD_BLOCK) { if (socket->blocking) { - reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(socket->socket_pollable); - wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + poll_borrow_pollable_t pollable_borrow = poll_borrow_pollable(socket->socket_pollable); + poll_method_pollable_block(pollable_borrow); } else { errno = EINPROGRESS; return -1; @@ -62,13 +62,13 @@ int tcp_connect(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_i // Connect successful. - reactor_own_input_stream_t input = io.f0; - reactor_borrow_input_stream_t input_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(input); - reactor_own_pollable_t input_pollable = wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe(input_borrow); + streams_own_input_stream_t input = io.f0; + streams_borrow_input_stream_t input_borrow = streams_borrow_input_stream(input); + poll_own_pollable_t input_pollable = streams_method_input_stream_subscribe(input_borrow); - reactor_own_output_stream_t output = io.f1; - reactor_borrow_output_stream_t output_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(output); - reactor_own_pollable_t output_pollable = wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe(output_borrow); + streams_own_output_stream_t output = io.f1; + streams_borrow_output_stream_t output_borrow = streams_borrow_output_stream(output); + poll_own_pollable_t output_pollable = streams_method_output_stream_subscribe(output_borrow); socket->state_tag = TCP_SOCKET_STATE_CONNECTED; socket->state = (tcp_socket_state_t){ .connected = { @@ -80,7 +80,7 @@ int tcp_connect(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_i return 0; } -int udp_connect(udp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* address) +int udp_connect(udp_socket_t* socket, network_ip_socket_address_t* address) { // TODO wasi-sockets: implement errno = EOPNOTSUPP; @@ -95,7 +95,7 @@ int connect(int fd, const struct sockaddr* address, socklen_t len) return -1; } - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t ip_address; + network_ip_socket_address_t ip_address; int parse_err; if (!__wasi_sockets_utils__parse_address(address, len, &ip_address, &parse_err)) { errno = parse_err; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c index 3ec3bb074..6e34b8797 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c @@ -4,11 +4,11 @@ #include #include "__utils.h" -bool tcp_getsockname(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address) +bool tcp_getsockname(tcp_socket_t* socket, network_ip_socket_address_t* out_address) { - wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_local_address(socket_borrow, out_address, &error)) { + network_error_code_t error; + tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); + if (!tcp_method_tcp_socket_local_address(socket_borrow, out_address, &error)) { errno = __wasi_sockets_utils__map_error(error); return false; } @@ -16,11 +16,11 @@ bool tcp_getsockname(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_netw return true; } -bool tcp_getpeername(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address) +bool tcp_getpeername(tcp_socket_t* socket, network_ip_socket_address_t* out_address) { - wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_remote_address(socket_borrow, out_address, &error)) { + network_error_code_t error; + tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); + if (!tcp_method_tcp_socket_remote_address(socket_borrow, out_address, &error)) { errno = __wasi_sockets_utils__map_error(error); return false; } @@ -28,14 +28,14 @@ bool tcp_getpeername(tcp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_netw return true; } -bool udp_getsockname(udp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address) +bool udp_getsockname(udp_socket_t* socket, network_ip_socket_address_t* out_address) { // TODO wasi-sockets: implement errno = EOPNOTSUPP; return -1; } -bool udp_getpeername(udp_socket_t* socket, wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t* out_address) +bool udp_getpeername(udp_socket_t* socket, network_ip_socket_address_t* out_address) { // TODO wasi-sockets: implement errno = EOPNOTSUPP; @@ -55,7 +55,7 @@ int getsockname(int socket, struct sockaddr *__restrict addr, socklen_t *__restr return -1; } - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t out_address; + network_ip_socket_address_t out_address; switch (entry->tag) { @@ -98,7 +98,7 @@ int getpeername(int socket, struct sockaddr *__restrict addr, socklen_t *__restr return -1; } - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t out_address; + network_ip_socket_address_t out_address; switch (entry->tag) { diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c index ee68618ca..f0f4f6710 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c @@ -7,15 +7,15 @@ int tcp_listen(tcp_socket_t* socket, int backlog) { - wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + network_error_code_t error; + tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); switch (socket->state_tag) { case TCP_SOCKET_STATE_UNBOUND: { // Socket is not explicitly bound by the user. We'll do it for them: - wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_address_family_t family = wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(socket_borrow); - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t any = __wasi_sockets_utils__any_addr(family); + tcp_ip_address_family_t family = tcp_method_tcp_socket_address_family(socket_borrow); + network_ip_socket_address_t any = __wasi_sockets_utils__any_addr(family); int result = __wasi_sockets_utils__tcp_bind(socket, &any); if (result != 0) { return result; @@ -39,7 +39,7 @@ int tcp_listen(tcp_socket_t* socket, int backlog) { return -1; } - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_listen_backlog_size(socket_borrow, backlog, &error)) { + if (!tcp_method_tcp_socket_set_listen_backlog_size(socket_borrow, backlog, &error)) { abort(); // Our own state checks should've prevented this from happening. } @@ -48,17 +48,17 @@ int tcp_listen(tcp_socket_t* socket, int backlog) { return 0; } - reactor_borrow_network_t network_borrow = __wasi_sockets_utils__borrow_network(); - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_listen(socket_borrow, &error)) { + network_borrow_network_t network_borrow = __wasi_sockets_utils__borrow_network(); + if (!tcp_method_tcp_socket_start_listen(socket_borrow, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } // Listen has successfully started. Attempt to finish it: - while (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_listen(socket_borrow, &error)) { - if (error == WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK) { - reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(socket->socket_pollable); - wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + while (!tcp_method_tcp_socket_finish_listen(socket_borrow, &error)) { + if (error == NETWORK_ERROR_CODE_WOULD_BLOCK) { + poll_borrow_pollable_t pollable_borrow = poll_borrow_pollable(socket->socket_pollable); + poll_method_pollable_block(pollable_borrow); } else { errno = __wasi_sockets_utils__map_error(error); return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index 9ac38264a..74e730495 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -38,11 +38,11 @@ ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int should_block = false; } - reactor_borrow_input_stream_t rx_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(connection.input); + streams_borrow_input_stream_t rx_borrow = streams_borrow_input_stream(connection.input); while (true) { - reactor_list_u8_t result; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; - if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_read(rx_borrow, length, &result, &error)) { + streams_list_u8_t result; + streams_stream_error_t error; + if (!streams_method_input_stream_read(rx_borrow, length, &result, &error)) { // TODO wasi-sockets: wasi-sockets has no way to recover stream errors yet. errno = EPIPE; return -1; @@ -50,11 +50,11 @@ ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int if (result.len) { memcpy(buffer, result.ptr, result.len); - reactor_list_u8_free(&result); + streams_list_u8_free(&result); return result.len; } else if (should_block) { - reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(connection.input_pollable); - wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + poll_borrow_pollable_t pollable_borrow = poll_borrow_pollable(connection.input_pollable); + poll_method_pollable_block(pollable_borrow); } else { errno = EWOULDBLOCK; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c index e657b7a80..61850292e 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c @@ -38,11 +38,11 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int fl // requested or not. } - reactor_borrow_output_stream_t tx_borrow = wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(connection.output); + streams_borrow_output_stream_t tx_borrow = streams_borrow_output_stream(connection.output); while (true) { - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t error; + streams_stream_error_t error; uint64_t count; - if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_check_write(tx_borrow, &count, &error)) { + if (!streams_method_output_stream_check_write(tx_borrow, &count, &error)) { // TODO wasi-sockets: wasi-sockets has no way to recover stream errors yet. errno = EPIPE; return -1; @@ -50,8 +50,8 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int fl if (count) { count = count < length ? count : length; - reactor_list_u8_t list = { .ptr = (uint8_t*)buffer, .len = count }; - if (!wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write(tx_borrow, &list, &error)) { + streams_list_u8_t list = { .ptr = (uint8_t*)buffer, .len = count }; + if (!streams_method_output_stream_write(tx_borrow, &list, &error)) { // TODO wasi-sockets: wasi-sockets has no way to recover stream errors yet. errno = EPIPE; return -1; @@ -59,8 +59,8 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int fl return count; } } else if (should_block) { - reactor_borrow_pollable_t pollable_borrow = wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(connection.output_pollable); - wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(pollable_borrow); + poll_borrow_pollable_t pollable_borrow = poll_borrow_pollable(connection.output_pollable); + poll_method_pollable_block(pollable_borrow); } else { errno = EWOULDBLOCK; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c index 7607a2d23..1528fdce3 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c @@ -16,17 +16,17 @@ static_assert(SHUT_WR == __WASI_SDFLAGS_WR, "Value mismatch"); int tcp_shutdown(tcp_socket_t* socket, int posix_how) { - wasi_sockets_0_2_0_rc_2023_10_18_tcp_shutdown_type_t wasi_how; + tcp_shutdown_type_t wasi_how; switch (posix_how) { case SHUT_RD: - wasi_how = WASI_SOCKETS_0_2_0_RC_2023_10_18_TCP_SHUTDOWN_TYPE_RECEIVE; + wasi_how = TCP_SHUTDOWN_TYPE_RECEIVE; break; case SHUT_WR: - wasi_how = WASI_SOCKETS_0_2_0_RC_2023_10_18_TCP_SHUTDOWN_TYPE_SEND; + wasi_how = TCP_SHUTDOWN_TYPE_SEND; break; case SHUT_RDWR: - wasi_how = WASI_SOCKETS_0_2_0_RC_2023_10_18_TCP_SHUTDOWN_TYPE_BOTH; + wasi_how = TCP_SHUTDOWN_TYPE_BOTH; break; default: errno = EINVAL; @@ -41,9 +41,9 @@ int tcp_shutdown(tcp_socket_t* socket, int posix_how) return -1; } - wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_shutdown(socket_borrow, wasi_how, &error)) { + network_error_code_t error; + tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); + if (!tcp_method_tcp_socket_shutdown(socket_borrow, wasi_how, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c index a354cb96a..6702ad893 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c @@ -4,17 +4,17 @@ #include #include "__utils.h" -int tcp_socket(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t family, bool blocking) +int tcp_socket(network_ip_address_family_t family, bool blocking) { - wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t error; - reactor_own_tcp_socket_t socket; - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_create_tcp_socket(family, &socket, &error)) { + tcp_create_socket_error_code_t error; + tcp_own_tcp_socket_t socket; + if (!tcp_create_socket_create_tcp_socket(family, &socket, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket); - reactor_own_pollable_t socket_pollable = wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(socket_borrow); + tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket); + poll_own_pollable_t socket_pollable = tcp_method_tcp_socket_subscribe(socket_borrow); descriptor_table_entry_t entry = { .tag = DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, @@ -35,7 +35,7 @@ int tcp_socket(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t fami return fd; } -int udp_socket(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t family, bool blocking) +int udp_socket(network_ip_address_family_t family, bool blocking) { // TODO wasi-sockets: implement errno = EPROTONOSUPPORT; @@ -45,14 +45,14 @@ int udp_socket(wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t fami int socket(int domain, int type, int protocol) { - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t family; + network_ip_address_family_t family; switch (domain) { case PF_INET: - family = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4; + family = NETWORK_IP_ADDRESS_FAMILY_IPV4; break; case PF_INET6: - family = WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6; + family = NETWORK_IP_ADDRESS_FAMILY_IPV6; break; default: diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c index 3836a2c7a..69aba7e0c 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -17,8 +17,8 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, { int value = 0; - wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + network_error_code_t error; + tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); switch (level) { @@ -34,7 +34,7 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, } case SO_DOMAIN: { value = __wasi_sockets_utils__posix_family( - wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(socket_borrow) + tcp_method_tcp_socket_address_family(socket_borrow) ); break; } @@ -54,7 +54,7 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, } case SO_KEEPALIVE: { bool result; - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_keep_alive(socket_borrow, &result, &error)) { + if (!tcp_method_tcp_socket_keep_alive_enabled(socket_borrow, &result, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -64,7 +64,7 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, } case SO_RCVBUF: { uint64_t result; - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_receive_buffer_size(socket_borrow, &result, &error)) { + if (!tcp_method_tcp_socket_receive_buffer_size(socket_borrow, &result, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -78,7 +78,7 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, } case SO_SNDBUF: { uint64_t result; - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_send_buffer_size(socket_borrow, &result, &error)) { + if (!tcp_method_tcp_socket_send_buffer_size(socket_borrow, &result, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -102,15 +102,15 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, case SOL_IP: switch (optname) { case IP_TTL: { - if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(socket_borrow) - != WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4) + if (tcp_method_tcp_socket_address_family(socket_borrow) + != NETWORK_IP_ADDRESS_FAMILY_IPV4) { errno = EAFNOSUPPORT; return -1; } uint8_t result; - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_unicast_hop_limit(socket_borrow, &result, &error)) { + if (!tcp_method_tcp_socket_hop_limit(socket_borrow, &result, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -128,15 +128,15 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, case SOL_IPV6: switch (optname) { case IPV6_UNICAST_HOPS: { - if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(socket_borrow) - != WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6) + if (tcp_method_tcp_socket_address_family(socket_borrow) + != NETWORK_IP_ADDRESS_FAMILY_IPV6) { errno = EAFNOSUPPORT; return -1; } uint8_t result; - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_unicast_hop_limit(socket_borrow, &result, &error)) { + if (!tcp_method_tcp_socket_hop_limit(socket_borrow, &result, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -146,7 +146,7 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, } case IPV6_V6ONLY: { bool result; - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_ipv6_only(socket_borrow, &result, &error)) { + if (!tcp_method_tcp_socket_ipv6_only(socket_borrow, &result, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -189,15 +189,15 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt int intval = *(int*)optval; - wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error; - reactor_borrow_tcp_socket_t socket_borrow = wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(socket->socket); + network_error_code_t error; + tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); switch (level) { case SOL_SOCKET: switch (optname) { case SO_KEEPALIVE: { - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_keep_alive(socket_borrow, intval != 0, &error)) { + if (!tcp_method_tcp_socket_set_keep_alive_enabled(socket_borrow, intval != 0, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -205,7 +205,7 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt return 0; } case SO_RCVBUF: { - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_receive_buffer_size(socket_borrow, intval, &error)) { + if (!tcp_method_tcp_socket_set_receive_buffer_size(socket_borrow, intval, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -213,7 +213,7 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt return 0; } case SO_SNDBUF: { - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_send_buffer_size(socket_borrow, intval, &error)) { + if (!tcp_method_tcp_socket_set_send_buffer_size(socket_borrow, intval, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -232,8 +232,8 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt case SOL_IP: switch (optname) { case IP_TTL: { - if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(socket_borrow) - != WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4) + if (tcp_method_tcp_socket_address_family(socket_borrow) + != NETWORK_IP_ADDRESS_FAMILY_IPV4) { errno = EAFNOSUPPORT; return -1; @@ -244,7 +244,7 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt return -1; } - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_unicast_hop_limit(socket_borrow, intval, &error)) { + if (!tcp_method_tcp_socket_set_hop_limit(socket_borrow, intval, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -261,8 +261,8 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt case SOL_IPV6: switch (optname) { case IPV6_UNICAST_HOPS: { - if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(socket_borrow) - != WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6) + if (tcp_method_tcp_socket_address_family(socket_borrow) + != NETWORK_IP_ADDRESS_FAMILY_IPV6) { errno = EAFNOSUPPORT; return -1; @@ -273,7 +273,7 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt return -1; } - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_unicast_hop_limit(socket_borrow, intval, &error)) { + if (!tcp_method_tcp_socket_set_hop_limit(socket_borrow, intval, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -281,7 +281,7 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt return 0; } case IPV6_V6ONLY: { - if (!wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_ipv6_only(socket_borrow, intval != 0, &error)) { + if (!tcp_method_tcp_socket_set_ipv6_only(socket_borrow, intval != 0, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c new file mode 100644 index 000000000..e0cf47fee --- /dev/null +++ b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c @@ -0,0 +1,4479 @@ +// Generated by `wit-bindgen` 0.16.0. DO NOT EDIT! +#include "preview2.h" + + +__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-11-10"), __import_name__("get-environment"))) +extern void __wasm_import_environment_get_environment(int32_t); + +__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-11-10"), __import_name__("get-arguments"))) +extern void __wasm_import_environment_get_arguments(int32_t); + +__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-11-10"), __import_name__("initial-cwd"))) +extern void __wasm_import_environment_initial_cwd(int32_t); + +__attribute__((__import_module__("wasi:cli/exit@0.2.0-rc-2023-11-10"), __import_name__("exit"))) +extern void __wasm_import_exit_exit(int32_t); + +__attribute__((__import_module__("wasi:io/error@0.2.0-rc-2023-11-10"), __import_name__("[method]error.to-debug-string"))) +extern void __wasm_import_io_error_method_error_to_debug_string(int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-11-10"), __import_name__("[method]pollable.ready"))) +extern int32_t __wasm_import_poll_method_pollable_ready(int32_t); + +__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-11-10"), __import_name__("[method]pollable.block"))) +extern void __wasm_import_poll_method_pollable_block(int32_t); + +__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-11-10"), __import_name__("poll"))) +extern void __wasm_import_poll_poll(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]input-stream.read"))) +extern void __wasm_import_streams_method_input_stream_read(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]input-stream.blocking-read"))) +extern void __wasm_import_streams_method_input_stream_blocking_read(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]input-stream.skip"))) +extern void __wasm_import_streams_method_input_stream_skip(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]input-stream.blocking-skip"))) +extern void __wasm_import_streams_method_input_stream_blocking_skip(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]input-stream.subscribe"))) +extern int32_t __wasm_import_streams_method_input_stream_subscribe(int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.check-write"))) +extern void __wasm_import_streams_method_output_stream_check_write(int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.write"))) +extern void __wasm_import_streams_method_output_stream_write(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.blocking-write-and-flush"))) +extern void __wasm_import_streams_method_output_stream_blocking_write_and_flush(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.flush"))) +extern void __wasm_import_streams_method_output_stream_flush(int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.blocking-flush"))) +extern void __wasm_import_streams_method_output_stream_blocking_flush(int32_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.subscribe"))) +extern int32_t __wasm_import_streams_method_output_stream_subscribe(int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.write-zeroes"))) +extern void __wasm_import_streams_method_output_stream_write_zeroes(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.blocking-write-zeroes-and-flush"))) +extern void __wasm_import_streams_method_output_stream_blocking_write_zeroes_and_flush(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.splice"))) +extern void __wasm_import_streams_method_output_stream_splice(int32_t, int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.blocking-splice"))) +extern void __wasm_import_streams_method_output_stream_blocking_splice(int32_t, int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:cli/stdin@0.2.0-rc-2023-11-10"), __import_name__("get-stdin"))) +extern int32_t __wasm_import_stdin_get_stdin(void); + +__attribute__((__import_module__("wasi:cli/stdout@0.2.0-rc-2023-11-10"), __import_name__("get-stdout"))) +extern int32_t __wasm_import_stdout_get_stdout(void); + +__attribute__((__import_module__("wasi:cli/stderr@0.2.0-rc-2023-11-10"), __import_name__("get-stderr"))) +extern int32_t __wasm_import_stderr_get_stderr(void); + +__attribute__((__import_module__("wasi:cli/terminal-stdin@0.2.0-rc-2023-11-10"), __import_name__("get-terminal-stdin"))) +extern void __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_get_terminal_stdin(int32_t); + +__attribute__((__import_module__("wasi:cli/terminal-stdout@0.2.0-rc-2023-11-10"), __import_name__("get-terminal-stdout"))) +extern void __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_get_terminal_stdout(int32_t); + +__attribute__((__import_module__("wasi:cli/terminal-stderr@0.2.0-rc-2023-11-10"), __import_name__("get-terminal-stderr"))) +extern void __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_get_terminal_stderr(int32_t); + +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10"), __import_name__("now"))) +extern int64_t __wasm_import_monotonic_clock_now(void); + +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10"), __import_name__("resolution"))) +extern int64_t __wasm_import_monotonic_clock_resolution(void); + +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10"), __import_name__("subscribe-instant"))) +extern int32_t __wasm_import_monotonic_clock_subscribe_instant(int64_t); + +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10"), __import_name__("subscribe-duration"))) +extern int32_t __wasm_import_monotonic_clock_subscribe_duration(int64_t); + +__attribute__((__import_module__("wasi:clocks/wall-clock@0.2.0-rc-2023-11-10"), __import_name__("now"))) +extern void __wasm_import_wall_clock_now(int32_t); + +__attribute__((__import_module__("wasi:clocks/wall-clock@0.2.0-rc-2023-11-10"), __import_name__("resolution"))) +extern void __wasm_import_wall_clock_resolution(int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.read-via-stream"))) +extern void __wasm_import_filesystem_method_descriptor_read_via_stream(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.write-via-stream"))) +extern void __wasm_import_filesystem_method_descriptor_write_via_stream(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.append-via-stream"))) +extern void __wasm_import_filesystem_method_descriptor_append_via_stream(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.advise"))) +extern void __wasm_import_filesystem_method_descriptor_advise(int32_t, int64_t, int64_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.sync-data"))) +extern void __wasm_import_filesystem_method_descriptor_sync_data(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.get-flags"))) +extern void __wasm_import_filesystem_method_descriptor_get_flags(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.get-type"))) +extern void __wasm_import_filesystem_method_descriptor_get_type(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.set-size"))) +extern void __wasm_import_filesystem_method_descriptor_set_size(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.set-times"))) +extern void __wasm_import_filesystem_method_descriptor_set_times(int32_t, int32_t, int64_t, int32_t, int32_t, int64_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.read"))) +extern void __wasm_import_filesystem_method_descriptor_read(int32_t, int64_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.write"))) +extern void __wasm_import_filesystem_method_descriptor_write(int32_t, int32_t, int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.read-directory"))) +extern void __wasm_import_filesystem_method_descriptor_read_directory(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.sync"))) +extern void __wasm_import_filesystem_method_descriptor_sync(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.create-directory-at"))) +extern void __wasm_import_filesystem_method_descriptor_create_directory_at(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.stat"))) +extern void __wasm_import_filesystem_method_descriptor_stat(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.stat-at"))) +extern void __wasm_import_filesystem_method_descriptor_stat_at(int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.set-times-at"))) +extern void __wasm_import_filesystem_method_descriptor_set_times_at(int32_t, int32_t, int32_t, int32_t, int32_t, int64_t, int32_t, int32_t, int64_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.link-at"))) +extern void __wasm_import_filesystem_method_descriptor_link_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.open-at"))) +extern void __wasm_import_filesystem_method_descriptor_open_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.readlink-at"))) +extern void __wasm_import_filesystem_method_descriptor_readlink_at(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.remove-directory-at"))) +extern void __wasm_import_filesystem_method_descriptor_remove_directory_at(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.rename-at"))) +extern void __wasm_import_filesystem_method_descriptor_rename_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.symlink-at"))) +extern void __wasm_import_filesystem_method_descriptor_symlink_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.unlink-file-at"))) +extern void __wasm_import_filesystem_method_descriptor_unlink_file_at(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.is-same-object"))) +extern int32_t __wasm_import_filesystem_method_descriptor_is_same_object(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.metadata-hash"))) +extern void __wasm_import_filesystem_method_descriptor_metadata_hash(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.metadata-hash-at"))) +extern void __wasm_import_filesystem_method_descriptor_metadata_hash_at(int32_t, int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]directory-entry-stream.read-directory-entry"))) +extern void __wasm_import_filesystem_method_directory_entry_stream_read_directory_entry(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("filesystem-error-code"))) +extern void __wasm_import_filesystem_filesystem_error_code(int32_t, int32_t); + +__attribute__((__import_module__("wasi:filesystem/preopens@0.2.0-rc-2023-11-10"), __import_name__("get-directories"))) +extern void __wasm_import_filesystem_preopens_get_directories(int32_t); + +__attribute__((__import_module__("wasi:sockets/instance-network@0.2.0-rc-2023-11-10"), __import_name__("instance-network"))) +extern int32_t __wasm_import_instance_network_instance_network(void); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.start-bind"))) +extern void __wasm_import_udp_method_udp_socket_start_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, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.finish-bind"))) +extern void __wasm_import_udp_method_udp_socket_finish_bind(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.stream"))) +extern void __wasm_import_udp_method_udp_socket_stream(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, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.local-address"))) +extern void __wasm_import_udp_method_udp_socket_local_address(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.remote-address"))) +extern void __wasm_import_udp_method_udp_socket_remote_address(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.address-family"))) +extern int32_t __wasm_import_udp_method_udp_socket_address_family(int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.ipv6-only"))) +extern void __wasm_import_udp_method_udp_socket_ipv6_only(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.set-ipv6-only"))) +extern void __wasm_import_udp_method_udp_socket_set_ipv6_only(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.unicast-hop-limit"))) +extern void __wasm_import_udp_method_udp_socket_unicast_hop_limit(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.set-unicast-hop-limit"))) +extern void __wasm_import_udp_method_udp_socket_set_unicast_hop_limit(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.receive-buffer-size"))) +extern void __wasm_import_udp_method_udp_socket_receive_buffer_size(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.set-receive-buffer-size"))) +extern void __wasm_import_udp_method_udp_socket_set_receive_buffer_size(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.send-buffer-size"))) +extern void __wasm_import_udp_method_udp_socket_send_buffer_size(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.set-send-buffer-size"))) +extern void __wasm_import_udp_method_udp_socket_set_send_buffer_size(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.subscribe"))) +extern int32_t __wasm_import_udp_method_udp_socket_subscribe(int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]incoming-datagram-stream.receive"))) +extern void __wasm_import_udp_method_incoming_datagram_stream_receive(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]incoming-datagram-stream.subscribe"))) +extern int32_t __wasm_import_udp_method_incoming_datagram_stream_subscribe(int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]outgoing-datagram-stream.check-send"))) +extern void __wasm_import_udp_method_outgoing_datagram_stream_check_send(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]outgoing-datagram-stream.send"))) +extern void __wasm_import_udp_method_outgoing_datagram_stream_send(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]outgoing-datagram-stream.subscribe"))) +extern int32_t __wasm_import_udp_method_outgoing_datagram_stream_subscribe(int32_t); + +__attribute__((__import_module__("wasi:sockets/udp-create-socket@0.2.0-rc-2023-11-10"), __import_name__("create-udp-socket"))) +extern void __wasm_import_udp_create_socket_create_udp_socket(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.start-bind"))) +extern void __wasm_import_tcp_method_tcp_socket_start_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, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.finish-bind"))) +extern void __wasm_import_tcp_method_tcp_socket_finish_bind(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.start-connect"))) +extern void __wasm_import_tcp_method_tcp_socket_start_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, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.finish-connect"))) +extern void __wasm_import_tcp_method_tcp_socket_finish_connect(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.start-listen"))) +extern void __wasm_import_tcp_method_tcp_socket_start_listen(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.finish-listen"))) +extern void __wasm_import_tcp_method_tcp_socket_finish_listen(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.accept"))) +extern void __wasm_import_tcp_method_tcp_socket_accept(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.local-address"))) +extern void __wasm_import_tcp_method_tcp_socket_local_address(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.remote-address"))) +extern void __wasm_import_tcp_method_tcp_socket_remote_address(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.is-listening"))) +extern int32_t __wasm_import_tcp_method_tcp_socket_is_listening(int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.address-family"))) +extern int32_t __wasm_import_tcp_method_tcp_socket_address_family(int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.ipv6-only"))) +extern void __wasm_import_tcp_method_tcp_socket_ipv6_only(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-ipv6-only"))) +extern void __wasm_import_tcp_method_tcp_socket_set_ipv6_only(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-listen-backlog-size"))) +extern void __wasm_import_tcp_method_tcp_socket_set_listen_backlog_size(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.keep-alive-enabled"))) +extern void __wasm_import_tcp_method_tcp_socket_keep_alive_enabled(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-keep-alive-enabled"))) +extern void __wasm_import_tcp_method_tcp_socket_set_keep_alive_enabled(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.keep-alive-idle-time"))) +extern void __wasm_import_tcp_method_tcp_socket_keep_alive_idle_time(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-keep-alive-idle-time"))) +extern void __wasm_import_tcp_method_tcp_socket_set_keep_alive_idle_time(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.keep-alive-interval"))) +extern void __wasm_import_tcp_method_tcp_socket_keep_alive_interval(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-keep-alive-interval"))) +extern void __wasm_import_tcp_method_tcp_socket_set_keep_alive_interval(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.keep-alive-count"))) +extern void __wasm_import_tcp_method_tcp_socket_keep_alive_count(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-keep-alive-count"))) +extern void __wasm_import_tcp_method_tcp_socket_set_keep_alive_count(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.hop-limit"))) +extern void __wasm_import_tcp_method_tcp_socket_hop_limit(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-hop-limit"))) +extern void __wasm_import_tcp_method_tcp_socket_set_hop_limit(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.receive-buffer-size"))) +extern void __wasm_import_tcp_method_tcp_socket_receive_buffer_size(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-receive-buffer-size"))) +extern void __wasm_import_tcp_method_tcp_socket_set_receive_buffer_size(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.send-buffer-size"))) +extern void __wasm_import_tcp_method_tcp_socket_send_buffer_size(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-send-buffer-size"))) +extern void __wasm_import_tcp_method_tcp_socket_set_send_buffer_size(int32_t, int64_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.subscribe"))) +extern int32_t __wasm_import_tcp_method_tcp_socket_subscribe(int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.shutdown"))) +extern void __wasm_import_tcp_method_tcp_socket_shutdown(int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/tcp-create-socket@0.2.0-rc-2023-11-10"), __import_name__("create-tcp-socket"))) +extern void __wasm_import_tcp_create_socket_create_tcp_socket(int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10"), __import_name__("resolve-addresses"))) +extern void __wasm_import_ip_name_lookup_resolve_addresses(int32_t, int32_t, int32_t, int32_t); + +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10"), __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, int32_t); + +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10"), __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:random/random@0.2.0-rc-2023-11-10"), __import_name__("get-random-bytes"))) +extern void __wasm_import_random_get_random_bytes(int64_t, int32_t); + +__attribute__((__import_module__("wasi:random/random@0.2.0-rc-2023-11-10"), __import_name__("get-random-u64"))) +extern int64_t __wasm_import_random_get_random_u64(void); + +__attribute__((__import_module__("wasi:random/insecure@0.2.0-rc-2023-11-10"), __import_name__("get-insecure-random-bytes"))) +extern void __wasm_import_random_insecure_get_insecure_random_bytes(int64_t, int32_t); + +__attribute__((__import_module__("wasi:random/insecure@0.2.0-rc-2023-11-10"), __import_name__("get-insecure-random-u64"))) +extern int64_t __wasm_import_random_insecure_get_insecure_random_u64(void); + +__attribute__((__import_module__("wasi:random/insecure-seed@0.2.0-rc-2023-11-10"), __import_name__("insecure-seed"))) +extern void __wasm_import_random_insecure_seed_insecure_seed(int32_t); + +__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 environment_tuple2_string_string_free(environment_tuple2_string_string_t *ptr) { + imports_string_free(&ptr->f0); + imports_string_free(&ptr->f1); +} + +void environment_list_tuple2_string_string_free(environment_list_tuple2_string_string_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + environment_tuple2_string_string_free(&ptr->ptr[i]); + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void environment_list_string_free(environment_list_string_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + imports_string_free(&ptr->ptr[i]); + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void environment_option_string_free(environment_option_string_t *ptr) { + if (ptr->is_some) { + imports_string_free(&ptr->val); + } +} + +void exit_result_void_void_free(exit_result_void_void_t *ptr) { + if (!ptr->is_err) { + } +} + +__attribute__((__import_module__("wasi:io/error@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]error"))) +extern void __wasm_import_io_error_error_drop(int32_t handle); + +void io_error_error_drop_own(io_error_own_error_t handle) { + __wasm_import_io_error_error_drop(handle.__handle); +} + +void io_error_error_drop_borrow(io_error_own_error_t handle) { + __wasm_import_io_error_error_drop(handle.__handle); +} + +io_error_borrow_error_t io_error_borrow_error(io_error_own_error_t arg) { + return (io_error_borrow_error_t) { arg.__handle }; +} + +__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]pollable"))) +extern void __wasm_import_poll_pollable_drop(int32_t handle); + +void poll_pollable_drop_own(poll_own_pollable_t handle) { + __wasm_import_poll_pollable_drop(handle.__handle); +} + +void poll_pollable_drop_borrow(poll_own_pollable_t handle) { + __wasm_import_poll_pollable_drop(handle.__handle); +} + +poll_borrow_pollable_t poll_borrow_pollable(poll_own_pollable_t arg) { + return (poll_borrow_pollable_t) { arg.__handle }; +} + +void poll_list_borrow_pollable_free(poll_list_borrow_pollable_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void poll_list_u32_free(poll_list_u32_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void streams_stream_error_free(streams_stream_error_t *ptr) { + switch ((int32_t) ptr->tag) { + case 0: { + break; + } + } +} + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]input-stream"))) +extern void __wasm_import_streams_input_stream_drop(int32_t handle); + +void streams_input_stream_drop_own(streams_own_input_stream_t handle) { + __wasm_import_streams_input_stream_drop(handle.__handle); +} + +void streams_input_stream_drop_borrow(streams_own_input_stream_t handle) { + __wasm_import_streams_input_stream_drop(handle.__handle); +} + +streams_borrow_input_stream_t streams_borrow_input_stream(streams_own_input_stream_t arg) { + return (streams_borrow_input_stream_t) { arg.__handle }; +} + +__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]output-stream"))) +extern void __wasm_import_streams_output_stream_drop(int32_t handle); + +void streams_output_stream_drop_own(streams_own_output_stream_t handle) { + __wasm_import_streams_output_stream_drop(handle.__handle); +} + +void streams_output_stream_drop_borrow(streams_own_output_stream_t handle) { + __wasm_import_streams_output_stream_drop(handle.__handle); +} + +streams_borrow_output_stream_t streams_borrow_output_stream(streams_own_output_stream_t arg) { + return (streams_borrow_output_stream_t) { arg.__handle }; +} + +void streams_list_u8_free(streams_list_u8_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void streams_result_list_u8_stream_error_free(streams_result_list_u8_stream_error_t *ptr) { + if (!ptr->is_err) { + streams_list_u8_free(&ptr->val.ok); + } else { + streams_stream_error_free(&ptr->val.err); + } +} + +void streams_result_u64_stream_error_free(streams_result_u64_stream_error_t *ptr) { + if (!ptr->is_err) { + } else { + streams_stream_error_free(&ptr->val.err); + } +} + +void streams_result_void_stream_error_free(streams_result_void_stream_error_t *ptr) { + if (!ptr->is_err) { + } else { + streams_stream_error_free(&ptr->val.err); + } +} + +__attribute__((__import_module__("wasi:cli/terminal-input@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]terminal-input"))) +extern void __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop(int32_t handle); + +void wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop_own(wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t handle) { + __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop(handle.__handle); +} + +void wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop_borrow(wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t handle) { + __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop(handle.__handle); +} + +wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input_t wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input(wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t arg) { + return (wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input_t) { arg.__handle }; +} + +__attribute__((__import_module__("wasi:cli/terminal-output@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]terminal-output"))) +extern void __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop(int32_t handle); + +void wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop_own(wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t handle) { + __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop(handle.__handle); +} + +void wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop_borrow(wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t handle) { + __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop(handle.__handle); +} + +wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output_t wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output(wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t arg) { + return (wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output_t) { arg.__handle }; +} + +void wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_option_own_terminal_input_free(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_option_own_terminal_input_t *ptr) { + if (ptr->is_some) { + } +} + +void wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_option_own_terminal_output_free(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_option_own_terminal_output_t *ptr) { + if (ptr->is_some) { + } +} + +void wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_option_own_terminal_output_free(wasi_cli_0_2_0_rc_2023_11_10_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) { + imports_string_free(&ptr->name); +} + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __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); +} + +void filesystem_descriptor_drop_borrow(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 }; +} + +__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]directory-entry-stream"))) +extern void __wasm_import_filesystem_directory_entry_stream_drop(int32_t handle); + +void filesystem_directory_entry_stream_drop_own(filesystem_own_directory_entry_stream_t handle) { + __wasm_import_filesystem_directory_entry_stream_drop(handle.__handle); +} + +void filesystem_directory_entry_stream_drop_borrow(filesystem_own_directory_entry_stream_t handle) { + __wasm_import_filesystem_directory_entry_stream_drop(handle.__handle); +} + +filesystem_borrow_directory_entry_stream_t filesystem_borrow_directory_entry_stream(filesystem_own_directory_entry_stream_t arg) { + return (filesystem_borrow_directory_entry_stream_t) { arg.__handle }; +} + +void filesystem_result_own_input_stream_error_code_free(filesystem_result_own_input_stream_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void filesystem_result_own_output_stream_error_code_free(filesystem_result_own_output_stream_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +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_list_u8_free(filesystem_list_u8_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void filesystem_tuple2_list_u8_bool_free(filesystem_tuple2_list_u8_bool_t *ptr) { + filesystem_list_u8_free(&ptr->f0); +} + +void filesystem_result_tuple2_list_u8_bool_error_code_free(filesystem_result_tuple2_list_u8_bool_error_code_t *ptr) { + if (!ptr->is_err) { + filesystem_tuple2_list_u8_bool_free(&ptr->val.ok); + } else { + } +} + +void filesystem_result_filesize_error_code_free(filesystem_result_filesize_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void filesystem_result_own_directory_entry_stream_error_code_free(filesystem_result_own_directory_entry_stream_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) { + imports_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 { + } +} + +void filesystem_option_directory_entry_free(filesystem_option_directory_entry_t *ptr) { + if (ptr->is_some) { + filesystem_directory_entry_free(&ptr->val); + } +} + +void filesystem_result_option_directory_entry_error_code_free(filesystem_result_option_directory_entry_error_code_t *ptr) { + if (!ptr->is_err) { + filesystem_option_directory_entry_free(&ptr->val.ok); + } else { + } +} + +void filesystem_option_error_code_free(filesystem_option_error_code_t *ptr) { + if (ptr->is_some) { + } +} + +void filesystem_preopens_tuple2_own_descriptor_string_free(filesystem_preopens_tuple2_own_descriptor_string_t *ptr) { + imports_string_free(&ptr->f1); +} + +void filesystem_preopens_list_tuple2_own_descriptor_string_free(filesystem_preopens_list_tuple2_own_descriptor_string_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + filesystem_preopens_tuple2_own_descriptor_string_free(&ptr->ptr[i]); + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +__attribute__((__import_module__("wasi:sockets/network@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]network"))) +extern void __wasm_import_network_network_drop(int32_t handle); + +void network_network_drop_own(network_own_network_t handle) { + __wasm_import_network_network_drop(handle.__handle); +} + +void network_network_drop_borrow(network_own_network_t handle) { + __wasm_import_network_network_drop(handle.__handle); +} + +network_borrow_network_t network_borrow_network(network_own_network_t arg) { + return (network_borrow_network_t) { arg.__handle }; +} + +void network_ip_address_free(network_ip_address_t *ptr) { + switch ((int32_t) ptr->tag) { + case 0: { + break; + } + case 1: { + break; + } + } +} + +void network_ip_socket_address_free(network_ip_socket_address_t *ptr) { + switch ((int32_t) ptr->tag) { + case 0: { + break; + } + case 1: { + break; + } + } +} + +void udp_ip_socket_address_free(udp_ip_socket_address_t *ptr) { + network_ip_socket_address_free(ptr); +} + +void udp_list_u8_free(udp_list_u8_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void udp_incoming_datagram_free(udp_incoming_datagram_t *ptr) { + udp_list_u8_free(&ptr->data); + udp_ip_socket_address_free(&ptr->remote_address); +} + +void udp_option_ip_socket_address_free(udp_option_ip_socket_address_t *ptr) { + if (ptr->is_some) { + udp_ip_socket_address_free(&ptr->val); + } +} + +void udp_outgoing_datagram_free(udp_outgoing_datagram_t *ptr) { + udp_list_u8_free(&ptr->data); + udp_option_ip_socket_address_free(&ptr->remote_address); +} + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]udp-socket"))) +extern void __wasm_import_udp_udp_socket_drop(int32_t handle); + +void udp_udp_socket_drop_own(udp_own_udp_socket_t handle) { + __wasm_import_udp_udp_socket_drop(handle.__handle); +} + +void udp_udp_socket_drop_borrow(udp_own_udp_socket_t handle) { + __wasm_import_udp_udp_socket_drop(handle.__handle); +} + +udp_borrow_udp_socket_t udp_borrow_udp_socket(udp_own_udp_socket_t arg) { + return (udp_borrow_udp_socket_t) { arg.__handle }; +} + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]incoming-datagram-stream"))) +extern void __wasm_import_udp_incoming_datagram_stream_drop(int32_t handle); + +void udp_incoming_datagram_stream_drop_own(udp_own_incoming_datagram_stream_t handle) { + __wasm_import_udp_incoming_datagram_stream_drop(handle.__handle); +} + +void udp_incoming_datagram_stream_drop_borrow(udp_own_incoming_datagram_stream_t handle) { + __wasm_import_udp_incoming_datagram_stream_drop(handle.__handle); +} + +udp_borrow_incoming_datagram_stream_t udp_borrow_incoming_datagram_stream(udp_own_incoming_datagram_stream_t arg) { + return (udp_borrow_incoming_datagram_stream_t) { arg.__handle }; +} + +__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]outgoing-datagram-stream"))) +extern void __wasm_import_udp_outgoing_datagram_stream_drop(int32_t handle); + +void udp_outgoing_datagram_stream_drop_own(udp_own_outgoing_datagram_stream_t handle) { + __wasm_import_udp_outgoing_datagram_stream_drop(handle.__handle); +} + +void udp_outgoing_datagram_stream_drop_borrow(udp_own_outgoing_datagram_stream_t handle) { + __wasm_import_udp_outgoing_datagram_stream_drop(handle.__handle); +} + +udp_borrow_outgoing_datagram_stream_t udp_borrow_outgoing_datagram_stream(udp_own_outgoing_datagram_stream_t arg) { + return (udp_borrow_outgoing_datagram_stream_t) { arg.__handle }; +} + +void udp_result_void_error_code_free(udp_result_void_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +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) { + if (!ptr->is_err) { + } else { + } +} + +void udp_result_ip_socket_address_error_code_free(udp_result_ip_socket_address_error_code_t *ptr) { + if (!ptr->is_err) { + udp_ip_socket_address_free(&ptr->val.ok); + } else { + } +} + +void udp_result_bool_error_code_free(udp_result_bool_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void udp_result_u8_error_code_free(udp_result_u8_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void udp_result_u64_error_code_free(udp_result_u64_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void udp_list_incoming_datagram_free(udp_list_incoming_datagram_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + udp_incoming_datagram_free(&ptr->ptr[i]); + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void udp_result_list_incoming_datagram_error_code_free(udp_result_list_incoming_datagram_error_code_t *ptr) { + if (!ptr->is_err) { + udp_list_incoming_datagram_free(&ptr->val.ok); + } else { + } +} + +void udp_list_outgoing_datagram_free(udp_list_outgoing_datagram_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + udp_outgoing_datagram_free(&ptr->ptr[i]); + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void udp_create_socket_result_own_udp_socket_error_code_free(udp_create_socket_result_own_udp_socket_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void tcp_ip_socket_address_free(tcp_ip_socket_address_t *ptr) { + network_ip_socket_address_free(ptr); +} + +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]tcp-socket"))) +extern void __wasm_import_tcp_tcp_socket_drop(int32_t handle); + +void tcp_tcp_socket_drop_own(tcp_own_tcp_socket_t handle) { + __wasm_import_tcp_tcp_socket_drop(handle.__handle); +} + +void tcp_tcp_socket_drop_borrow(tcp_own_tcp_socket_t handle) { + __wasm_import_tcp_tcp_socket_drop(handle.__handle); +} + +tcp_borrow_tcp_socket_t tcp_borrow_tcp_socket(tcp_own_tcp_socket_t arg) { + return (tcp_borrow_tcp_socket_t) { arg.__handle }; +} + +void tcp_result_void_error_code_free(tcp_result_void_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +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) { + if (!ptr->is_err) { + } else { + } +} + +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) { + if (!ptr->is_err) { + } else { + } +} + +void tcp_result_ip_socket_address_error_code_free(tcp_result_ip_socket_address_error_code_t *ptr) { + if (!ptr->is_err) { + tcp_ip_socket_address_free(&ptr->val.ok); + } else { + } +} + +void tcp_result_bool_error_code_free(tcp_result_bool_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void tcp_result_duration_error_code_free(tcp_result_duration_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void tcp_result_u32_error_code_free(tcp_result_u32_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void tcp_result_u8_error_code_free(tcp_result_u8_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void tcp_result_u64_error_code_free(tcp_result_u64_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void tcp_create_socket_result_own_tcp_socket_error_code_free(tcp_create_socket_result_own_tcp_socket_error_code_t *ptr) { + if (!ptr->is_err) { + } else { + } +} + +void ip_name_lookup_ip_address_free(ip_name_lookup_ip_address_t *ptr) { + network_ip_address_free(ptr); +} + +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]resolve-address-stream"))) +extern void __wasm_import_ip_name_lookup_resolve_address_stream_drop(int32_t handle); + +void ip_name_lookup_resolve_address_stream_drop_own(ip_name_lookup_own_resolve_address_stream_t handle) { + __wasm_import_ip_name_lookup_resolve_address_stream_drop(handle.__handle); +} + +void ip_name_lookup_resolve_address_stream_drop_borrow(ip_name_lookup_own_resolve_address_stream_t handle) { + __wasm_import_ip_name_lookup_resolve_address_stream_drop(handle.__handle); +} + +ip_name_lookup_borrow_resolve_address_stream_t ip_name_lookup_borrow_resolve_address_stream(ip_name_lookup_own_resolve_address_stream_t arg) { + 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); + } +} + +void ip_name_lookup_result_option_ip_address_error_code_free(ip_name_lookup_result_option_ip_address_error_code_t *ptr) { + if (!ptr->is_err) { + ip_name_lookup_option_ip_address_free(&ptr->val.ok); + } else { + } +} + +void random_list_u8_free(random_list_u8_t *ptr) { + for (size_t i = 0; i < ptr->len; i++) { + } + if (ptr->len > 0) { + free(ptr->ptr); + } +} + +void imports_string_set(imports_string_t *ret, char*s) { + ret->ptr = (uint8_t*) s; + ret->len = strlen(s); +} + +void imports_string_dup(imports_string_t *ret, const char*s) { + ret->len = strlen(s); + ret->ptr = cabi_realloc(NULL, 0, 1, ret->len * 1); + memcpy(ret->ptr, s, ret->len * 1); +} + +void imports_string_free(imports_string_t *ret) { + if (ret->len > 0) { + free(ret->ptr); + } + ret->ptr = NULL; + ret->len = 0; +} + +// Component Adapters + +void environment_get_environment(environment_list_tuple2_string_string_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_environment_get_environment(ptr); + *ret = (environment_list_tuple2_string_string_t) { (environment_tuple2_string_string_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +void environment_get_arguments(environment_list_string_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_environment_get_arguments(ptr); + *ret = (environment_list_string_t) { (imports_string_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +bool environment_initial_cwd(imports_string_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_environment_initial_cwd(ptr); + environment_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 = (imports_string_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; + 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 io_error_method_error_to_debug_string(io_error_borrow_error_t self, imports_string_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_io_error_method_error_to_debug_string((self).__handle, ptr); + *ret = (imports_string_t) { (uint8_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +bool poll_method_pollable_ready(poll_borrow_pollable_t self) { + int32_t ret = __wasm_import_poll_method_pollable_ready((self).__handle); + return ret; +} + +void poll_method_pollable_block(poll_borrow_pollable_t self) { + __wasm_import_poll_method_pollable_block((self).__handle); +} + +void poll_poll(poll_list_borrow_pollable_t *in, poll_list_u32_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_poll_poll((int32_t) (*in).ptr, (int32_t) (*in).len, ptr); + *ret = (poll_list_u32_t) { (uint32_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +bool streams_method_input_stream_read(streams_borrow_input_stream_t self, uint64_t len, streams_list_u8_t *ret, streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_streams_method_input_stream_read((self).__handle, (int64_t) (len), ptr); + streams_result_list_u8_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (streams_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; + break; + } + case 1: { + result.is_err = true; + streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (streams_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool streams_method_input_stream_blocking_read(streams_borrow_input_stream_t self, uint64_t len, streams_list_u8_t *ret, streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_streams_method_input_stream_blocking_read((self).__handle, (int64_t) (len), ptr); + streams_result_list_u8_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (streams_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; + break; + } + case 1: { + result.is_err = true; + streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (streams_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool streams_method_input_stream_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_streams_method_input_stream_skip((self).__handle, (int64_t) (len), ptr); + streams_result_u64_stream_error_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; + streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (streams_own_error_t) { *((int32_t*) (ptr + 12)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool streams_method_input_stream_blocking_skip(streams_borrow_input_stream_t self, uint64_t len, uint64_t *ret, streams_stream_error_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_streams_method_input_stream_blocking_skip((self).__handle, (int64_t) (len), ptr); + streams_result_u64_stream_error_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; + streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (streams_own_error_t) { *((int32_t*) (ptr + 12)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +streams_own_pollable_t streams_method_input_stream_subscribe(streams_borrow_input_stream_t self) { + int32_t ret = __wasm_import_streams_method_input_stream_subscribe((self).__handle); + return (streams_own_pollable_t) { ret }; +} + +bool streams_method_output_stream_check_write(streams_borrow_output_stream_t self, uint64_t *ret, streams_stream_error_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_streams_method_output_stream_check_write((self).__handle, ptr); + streams_result_u64_stream_error_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; + streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (streams_own_error_t) { *((int32_t*) (ptr + 12)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool streams_method_output_stream_write(streams_borrow_output_stream_t self, streams_list_u8_t *contents, streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_streams_method_output_stream_write((self).__handle, (int32_t) (*contents).ptr, (int32_t) (*contents).len, ptr); + streams_result_void_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (streams_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool streams_method_output_stream_blocking_write_and_flush(streams_borrow_output_stream_t self, streams_list_u8_t *contents, streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_streams_method_output_stream_blocking_write_and_flush((self).__handle, (int32_t) (*contents).ptr, (int32_t) (*contents).len, ptr); + streams_result_void_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (streams_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool streams_method_output_stream_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_streams_method_output_stream_flush((self).__handle, ptr); + streams_result_void_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (streams_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool streams_method_output_stream_blocking_flush(streams_borrow_output_stream_t self, streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_streams_method_output_stream_blocking_flush((self).__handle, ptr); + streams_result_void_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (streams_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +streams_own_pollable_t streams_method_output_stream_subscribe(streams_borrow_output_stream_t self) { + int32_t ret = __wasm_import_streams_method_output_stream_subscribe((self).__handle); + return (streams_own_pollable_t) { ret }; +} + +bool streams_method_output_stream_write_zeroes(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_streams_method_output_stream_write_zeroes((self).__handle, (int64_t) (len), ptr); + streams_result_void_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (streams_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +bool streams_method_output_stream_blocking_write_zeroes_and_flush(streams_borrow_output_stream_t self, uint64_t len, streams_stream_error_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_streams_method_output_stream_blocking_write_zeroes_and_flush((self).__handle, (int64_t) (len), ptr); + streams_result_void_stream_error_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + break; + } + case 1: { + result.is_err = true; + streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (streams_own_error_t) { *((int32_t*) (ptr + 8)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +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) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_streams_method_output_stream_splice((self).__handle, (src).__handle, (int64_t) (len), ptr); + streams_result_u64_stream_error_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; + streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (streams_own_error_t) { *((int32_t*) (ptr + 12)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +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) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_streams_method_output_stream_blocking_splice((self).__handle, (src).__handle, (int64_t) (len), ptr); + streams_result_u64_stream_error_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; + streams_stream_error_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.last_operation_failed = (streams_own_error_t) { *((int32_t*) (ptr + 12)) }; + break; + } + case 1: { + break; + } + } + + result.val.err = variant; + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +stdin_own_input_stream_t stdin_get_stdin(void) { + int32_t ret = __wasm_import_stdin_get_stdin(); + return (stdin_own_input_stream_t) { ret }; +} + +stdout_own_output_stream_t stdout_get_stdout(void) { + int32_t ret = __wasm_import_stdout_get_stdout(); + return (stdout_own_output_stream_t) { ret }; +} + +stderr_own_output_stream_t stderr_get_stderr(void) { + int32_t ret = __wasm_import_stderr_get_stderr(); + return (stderr_own_output_stream_t) { ret }; +} + +bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_get_terminal_stdin(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_own_terminal_input_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_get_terminal_stdin(ptr); + wasi_cli_0_2_0_rc_2023_11_10_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 = (wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_own_terminal_input_t) { *((int32_t*) (ptr + 4)) }; + break; + } + } + *ret = option.val; + return option.is_some; +} + +bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_get_terminal_stdout(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_own_terminal_output_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_get_terminal_stdout(ptr); + wasi_cli_0_2_0_rc_2023_11_10_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 = (wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_own_terminal_output_t) { *((int32_t*) (ptr + 4)) }; + break; + } + } + *ret = option.val; + return option.is_some; +} + +bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_get_terminal_stderr(wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_own_terminal_output_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_get_terminal_stderr(ptr); + wasi_cli_0_2_0_rc_2023_11_10_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 = (wasi_cli_0_2_0_rc_2023_11_10_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_resolution(void) { + int64_t ret = __wasm_import_monotonic_clock_resolution(); + return (uint64_t) (ret); +} + +monotonic_clock_own_pollable_t monotonic_clock_subscribe_instant(monotonic_clock_instant_t when) { + int32_t ret = __wasm_import_monotonic_clock_subscribe_instant((int64_t) (when)); + return (monotonic_clock_own_pollable_t) { ret }; +} + +monotonic_clock_own_pollable_t monotonic_clock_subscribe_duration(monotonic_clock_duration_t when) { + int32_t ret = __wasm_import_monotonic_clock_subscribe_duration((int64_t) (when)); + return (monotonic_clock_own_pollable_t) { ret }; +} + +void wall_clock_now(wall_clock_datetime_t *ret) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wall_clock_now(ptr); + *ret = (wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 0))), + (uint32_t) (*((int32_t*) (ptr + 8))), + }; +} + +void wall_clock_resolution(wall_clock_datetime_t *ret) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_wall_clock_resolution(ptr); + *ret = (wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 0))), + (uint32_t) (*((int32_t*) (ptr + 8))), + }; +} + +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) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_read_via_stream((self).__handle, (int64_t) (offset), ptr); + filesystem_result_own_input_stream_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (filesystem_own_input_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 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) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_write_via_stream((self).__handle, (int64_t) (offset), ptr); + filesystem_result_own_output_stream_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (filesystem_own_output_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 filesystem_method_descriptor_append_via_stream(filesystem_borrow_descriptor_t self, filesystem_own_output_stream_t *ret, filesystem_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_append_via_stream((self).__handle, ptr); + filesystem_result_own_output_stream_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (filesystem_own_output_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 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) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_advise((self).__handle, (int64_t) (offset), (int64_t) (length), (int32_t) advice, ptr); + filesystem_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 filesystem_method_descriptor_sync_data(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_sync_data((self).__handle, ptr); + filesystem_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 filesystem_method_descriptor_get_flags(filesystem_borrow_descriptor_t self, filesystem_descriptor_flags_t *ret, filesystem_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_get_flags((self).__handle, ptr); + filesystem_result_descriptor_flags_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 filesystem_method_descriptor_get_type(filesystem_borrow_descriptor_t self, filesystem_descriptor_type_t *ret, filesystem_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_get_type((self).__handle, ptr); + filesystem_result_descriptor_type_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 filesystem_method_descriptor_set_size(filesystem_borrow_descriptor_t self, filesystem_filesize_t size, filesystem_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_set_size((self).__handle, (int64_t) (size), ptr); + filesystem_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 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) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t variant; + int64_t variant2; + int32_t variant3; + switch ((int32_t) (*data_access_timestamp).tag) { + case 0: { + variant = 0; + variant2 = 0; + variant3 = 0; + break; + } + case 1: { + variant = 1; + variant2 = 0; + variant3 = 0; + break; + } + case 2: { + const filesystem_datetime_t *payload1 = &(*data_access_timestamp).val.timestamp; + variant = 2; + variant2 = (int64_t) ((*payload1).seconds); + variant3 = (int32_t) ((*payload1).nanoseconds); + break; + } + } + int32_t variant7; + int64_t variant8; + int32_t variant9; + switch ((int32_t) (*data_modification_timestamp).tag) { + case 0: { + variant7 = 0; + variant8 = 0; + variant9 = 0; + break; + } + case 1: { + variant7 = 1; + variant8 = 0; + variant9 = 0; + break; + } + case 2: { + const filesystem_datetime_t *payload6 = &(*data_modification_timestamp).val.timestamp; + variant7 = 2; + variant8 = (int64_t) ((*payload6).seconds); + variant9 = (int32_t) ((*payload6).nanoseconds); + break; + } + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_set_times((self).__handle, variant, variant2, variant3, variant7, variant8, variant9, ptr); + filesystem_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 filesystem_method_descriptor_read(filesystem_borrow_descriptor_t self, filesystem_filesize_t length, filesystem_filesize_t offset, filesystem_tuple2_list_u8_bool_t *ret, filesystem_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_read((self).__handle, (int64_t) (length), (int64_t) (offset), ptr); + filesystem_result_tuple2_list_u8_bool_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (filesystem_tuple2_list_u8_bool_t) { + (filesystem_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, + (int32_t) (*((uint8_t*) (ptr + 12))), + }; + 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 filesystem_method_descriptor_write(filesystem_borrow_descriptor_t self, filesystem_list_u8_t *buffer, filesystem_filesize_t offset, filesystem_filesize_t *ret, filesystem_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_write((self).__handle, (int32_t) (*buffer).ptr, (int32_t) (*buffer).len, (int64_t) (offset), ptr); + filesystem_result_filesize_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 filesystem_method_descriptor_read_directory(filesystem_borrow_descriptor_t self, filesystem_own_directory_entry_stream_t *ret, filesystem_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_read_directory((self).__handle, ptr); + filesystem_result_own_directory_entry_stream_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (filesystem_own_directory_entry_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 filesystem_method_descriptor_sync(filesystem_borrow_descriptor_t self, filesystem_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_sync((self).__handle, ptr); + filesystem_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 filesystem_method_descriptor_create_directory_at(filesystem_borrow_descriptor_t self, imports_string_t *path, filesystem_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_create_directory_at((self).__handle, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); + filesystem_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 filesystem_method_descriptor_stat(filesystem_borrow_descriptor_t self, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[104]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_stat((self).__handle, ptr); + filesystem_result_descriptor_stat_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + filesystem_option_datetime_t option; + switch ((int32_t) (*((uint8_t*) (ptr + 32)))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + option.val = (wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 40))), + (uint32_t) (*((int32_t*) (ptr + 48))), + }; + break; + } + } + filesystem_option_datetime_t option0; + switch ((int32_t) (*((uint8_t*) (ptr + 56)))) { + case 0: { + option0.is_some = false; + break; + } + case 1: { + option0.is_some = true; + option0.val = (wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 64))), + (uint32_t) (*((int32_t*) (ptr + 72))), + }; + break; + } + } + filesystem_option_datetime_t option1; + switch ((int32_t) (*((uint8_t*) (ptr + 80)))) { + case 0: { + option1.is_some = false; + break; + } + case 1: { + option1.is_some = true; + option1.val = (wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 88))), + (uint32_t) (*((int32_t*) (ptr + 96))), + }; + break; + } + } + + result.val.ok = (filesystem_descriptor_stat_t) { + (int32_t) (*((uint8_t*) (ptr + 8))), + (uint64_t) (*((int64_t*) (ptr + 16))), + (uint64_t) (*((int64_t*) (ptr + 24))), + option, + option0, + option1, + }; + 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 filesystem_method_descriptor_stat_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, imports_string_t *path, filesystem_descriptor_stat_t *ret, filesystem_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[104]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_stat_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); + filesystem_result_descriptor_stat_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + filesystem_option_datetime_t option; + switch ((int32_t) (*((uint8_t*) (ptr + 32)))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + option.val = (wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 40))), + (uint32_t) (*((int32_t*) (ptr + 48))), + }; + break; + } + } + filesystem_option_datetime_t option0; + switch ((int32_t) (*((uint8_t*) (ptr + 56)))) { + case 0: { + option0.is_some = false; + break; + } + case 1: { + option0.is_some = true; + option0.val = (wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 64))), + (uint32_t) (*((int32_t*) (ptr + 72))), + }; + break; + } + } + filesystem_option_datetime_t option1; + switch ((int32_t) (*((uint8_t*) (ptr + 80)))) { + case 0: { + option1.is_some = false; + break; + } + case 1: { + option1.is_some = true; + option1.val = (wall_clock_datetime_t) { + (uint64_t) (*((int64_t*) (ptr + 88))), + (uint32_t) (*((int32_t*) (ptr + 96))), + }; + break; + } + } + + result.val.ok = (filesystem_descriptor_stat_t) { + (int32_t) (*((uint8_t*) (ptr + 8))), + (uint64_t) (*((int64_t*) (ptr + 16))), + (uint64_t) (*((int64_t*) (ptr + 24))), + option, + option0, + option1, + }; + 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 filesystem_method_descriptor_set_times_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, imports_string_t *path, filesystem_new_timestamp_t *data_access_timestamp, filesystem_new_timestamp_t *data_modification_timestamp, filesystem_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t variant; + int64_t variant2; + int32_t variant3; + switch ((int32_t) (*data_access_timestamp).tag) { + case 0: { + variant = 0; + variant2 = 0; + variant3 = 0; + break; + } + case 1: { + variant = 1; + variant2 = 0; + variant3 = 0; + break; + } + case 2: { + const filesystem_datetime_t *payload1 = &(*data_access_timestamp).val.timestamp; + variant = 2; + variant2 = (int64_t) ((*payload1).seconds); + variant3 = (int32_t) ((*payload1).nanoseconds); + break; + } + } + int32_t variant7; + int64_t variant8; + int32_t variant9; + switch ((int32_t) (*data_modification_timestamp).tag) { + case 0: { + variant7 = 0; + variant8 = 0; + variant9 = 0; + break; + } + case 1: { + variant7 = 1; + variant8 = 0; + variant9 = 0; + break; + } + case 2: { + const filesystem_datetime_t *payload6 = &(*data_modification_timestamp).val.timestamp; + variant7 = 2; + variant8 = (int64_t) ((*payload6).seconds); + variant9 = (int32_t) ((*payload6).nanoseconds); + break; + } + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_set_times_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, variant, variant2, variant3, variant7, variant8, variant9, ptr); + filesystem_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 filesystem_method_descriptor_link_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t old_path_flags, imports_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, imports_string_t *new_path, filesystem_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_link_at((self).__handle, old_path_flags, (int32_t) (*old_path).ptr, (int32_t) (*old_path).len, (new_descriptor).__handle, (int32_t) (*new_path).ptr, (int32_t) (*new_path).len, ptr); + filesystem_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 filesystem_method_descriptor_open_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, imports_string_t *path, filesystem_open_flags_t open_flags, filesystem_descriptor_flags_t flags, filesystem_own_descriptor_t *ret, filesystem_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_open_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, open_flags, flags, ptr); + filesystem_result_own_descriptor_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (filesystem_own_descriptor_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 filesystem_method_descriptor_readlink_at(filesystem_borrow_descriptor_t self, imports_string_t *path, imports_string_t *ret, filesystem_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_readlink_at((self).__handle, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); + filesystem_result_string_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (imports_string_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; + 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 filesystem_method_descriptor_remove_directory_at(filesystem_borrow_descriptor_t self, imports_string_t *path, filesystem_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_remove_directory_at((self).__handle, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); + filesystem_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 filesystem_method_descriptor_rename_at(filesystem_borrow_descriptor_t self, imports_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, imports_string_t *new_path, filesystem_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_rename_at((self).__handle, (int32_t) (*old_path).ptr, (int32_t) (*old_path).len, (new_descriptor).__handle, (int32_t) (*new_path).ptr, (int32_t) (*new_path).len, ptr); + filesystem_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 filesystem_method_descriptor_symlink_at(filesystem_borrow_descriptor_t self, imports_string_t *old_path, imports_string_t *new_path, filesystem_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_symlink_at((self).__handle, (int32_t) (*old_path).ptr, (int32_t) (*old_path).len, (int32_t) (*new_path).ptr, (int32_t) (*new_path).len, ptr); + filesystem_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 filesystem_method_descriptor_unlink_file_at(filesystem_borrow_descriptor_t self, imports_string_t *path, filesystem_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_unlink_file_at((self).__handle, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); + filesystem_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 filesystem_method_descriptor_is_same_object(filesystem_borrow_descriptor_t self, filesystem_borrow_descriptor_t other) { + int32_t ret = __wasm_import_filesystem_method_descriptor_is_same_object((self).__handle, (other).__handle); + return ret; +} + +bool filesystem_method_descriptor_metadata_hash(filesystem_borrow_descriptor_t self, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[24]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_metadata_hash((self).__handle, ptr); + filesystem_result_metadata_hash_value_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (filesystem_metadata_hash_value_t) { + (uint64_t) (*((int64_t*) (ptr + 8))), + (uint64_t) (*((int64_t*) (ptr + 16))), + }; + 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 filesystem_method_descriptor_metadata_hash_at(filesystem_borrow_descriptor_t self, filesystem_path_flags_t path_flags, imports_string_t *path, filesystem_metadata_hash_value_t *ret, filesystem_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[24]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_descriptor_metadata_hash_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); + filesystem_result_metadata_hash_value_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (filesystem_metadata_hash_value_t) { + (uint64_t) (*((int64_t*) (ptr + 8))), + (uint64_t) (*((int64_t*) (ptr + 16))), + }; + 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 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) { + __attribute__((__aligned__(4))) + uint8_t ret_area[20]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_method_directory_entry_stream_read_directory_entry((self).__handle, ptr); + filesystem_result_option_directory_entry_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + filesystem_option_directory_entry_t option; + switch ((int32_t) (*((uint8_t*) (ptr + 4)))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + option.val = (filesystem_directory_entry_t) { + (int32_t) (*((uint8_t*) (ptr + 8))), + (imports_string_t) { (uint8_t*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }, + }; + break; + } + } + + result.val.ok = option; + 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 filesystem_filesystem_error_code(filesystem_borrow_error_t err_, filesystem_error_code_t *ret) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_filesystem_filesystem_error_code((err_).__handle, ptr); + filesystem_option_error_code_t option; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + option.val = (int32_t) (*((uint8_t*) (ptr + 1))); + break; + } + } + *ret = option.val; + return option.is_some; +} + +void filesystem_preopens_get_directories(filesystem_preopens_list_tuple2_own_descriptor_string_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_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*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +instance_network_own_network_t instance_network_instance_network(void) { + int32_t ret = __wasm_import_instance_network_instance_network(); + return (instance_network_own_network_t) { ret }; +} + +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) { + __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 network_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 network_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; + } + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_udp_socket_start_bind((self).__handle, (network).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); + udp_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 udp_method_udp_socket_finish_bind(udp_borrow_udp_socket_t self, udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_udp_socket_finish_bind((self).__handle, ptr); + udp_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 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) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + udp_option_ip_socket_address_t remote_address; + remote_address.is_some = maybe_remote_address != NULL;if (maybe_remote_address) { + remote_address.val = *maybe_remote_address; + } + int32_t option; + int32_t option14; + int32_t option15; + int32_t option16; + int32_t option17; + int32_t option18; + int32_t option19; + int32_t option20; + int32_t option21; + int32_t option22; + int32_t option23; + int32_t option24; + int32_t option25; + if ((remote_address).is_some) { + const udp_ip_socket_address_t *payload0 = &(remote_address).val; + int32_t variant; + 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; + int32_t variant12; + int32_t variant13; + switch ((int32_t) (*payload0).tag) { + case 0: { + const network_ipv4_socket_address_t *payload1 = &(*payload0).val.ipv4; + variant = 0; + variant3 = (int32_t) ((*payload1).port); + variant4 = (int32_t) (((*payload1).address).f0); + variant5 = (int32_t) (((*payload1).address).f1); + variant6 = (int32_t) (((*payload1).address).f2); + variant7 = (int32_t) (((*payload1).address).f3); + variant8 = 0; + variant9 = 0; + variant10 = 0; + variant11 = 0; + variant12 = 0; + variant13 = 0; + break; + } + case 1: { + const network_ipv6_socket_address_t *payload2 = &(*payload0).val.ipv6; + variant = 1; + variant3 = (int32_t) ((*payload2).port); + variant4 = (int32_t) ((*payload2).flow_info); + variant5 = (int32_t) (((*payload2).address).f0); + variant6 = (int32_t) (((*payload2).address).f1); + variant7 = (int32_t) (((*payload2).address).f2); + variant8 = (int32_t) (((*payload2).address).f3); + variant9 = (int32_t) (((*payload2).address).f4); + variant10 = (int32_t) (((*payload2).address).f5); + variant11 = (int32_t) (((*payload2).address).f6); + variant12 = (int32_t) (((*payload2).address).f7); + variant13 = (int32_t) ((*payload2).scope_id); + break; + } + } + option = 1; + option14 = variant; + option15 = variant3; + option16 = variant4; + option17 = variant5; + option18 = variant6; + option19 = variant7; + option20 = variant8; + option21 = variant9; + option22 = variant10; + option23 = variant11; + option24 = variant12; + option25 = variant13; + } else { + option = 0; + option14 = 0; + option15 = 0; + option16 = 0; + option17 = 0; + option18 = 0; + option19 = 0; + option20 = 0; + option21 = 0; + option22 = 0; + option23 = 0; + option24 = 0; + option25 = 0; + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_udp_socket_stream((self).__handle, option, option14, option15, option16, option17, option18, option19, option20, option21, option22, option23, option24, option25, ptr); + udp_result_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (udp_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_t) { + (udp_own_incoming_datagram_stream_t) { *((int32_t*) (ptr + 4)) }, + (udp_own_outgoing_datagram_stream_t) { *((int32_t*) (ptr + 8)) }, + }; + 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 udp_method_udp_socket_local_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[36]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_udp_socket_local_address((self).__handle, ptr); + udp_result_ip_socket_address_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + network_ip_socket_address_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (network_ipv4_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (network_ipv4_address_t) { + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 10)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 11)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 12)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 13)))), + }, + }; + break; + } + case 1: { + variant.val.ipv6 = (network_ipv6_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (uint32_t) (*((int32_t*) (ptr + 12))), + (network_ipv6_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 22)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 24)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 26)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 28)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 30)))), + }, + (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 udp_method_udp_socket_remote_address(udp_borrow_udp_socket_t self, udp_ip_socket_address_t *ret, udp_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[36]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_udp_socket_remote_address((self).__handle, ptr); + udp_result_ip_socket_address_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + network_ip_socket_address_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (network_ipv4_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (network_ipv4_address_t) { + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 10)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 11)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 12)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 13)))), + }, + }; + break; + } + case 1: { + variant.val.ipv6 = (network_ipv6_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (uint32_t) (*((int32_t*) (ptr + 12))), + (network_ipv6_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 22)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 24)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 26)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 28)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 30)))), + }, + (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; + } +} + +udp_ip_address_family_t udp_method_udp_socket_address_family(udp_borrow_udp_socket_t self) { + int32_t ret = __wasm_import_udp_method_udp_socket_address_family((self).__handle); + return ret; +} + +bool udp_method_udp_socket_ipv6_only(udp_borrow_udp_socket_t self, bool *ret, udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_udp_socket_ipv6_only((self).__handle, ptr); + udp_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 udp_method_udp_socket_set_ipv6_only(udp_borrow_udp_socket_t self, bool value, udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_udp_socket_set_ipv6_only((self).__handle, value, ptr); + udp_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 udp_method_udp_socket_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t *ret, udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_udp_socket_unicast_hop_limit((self).__handle, ptr); + udp_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 udp_method_udp_socket_set_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t value, udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_udp_socket_set_unicast_hop_limit((self).__handle, (int32_t) (value), ptr); + udp_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 udp_method_udp_socket_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_udp_socket_receive_buffer_size((self).__handle, ptr); + udp_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 udp_method_udp_socket_set_receive_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_udp_socket_set_receive_buffer_size((self).__handle, (int64_t) (value), ptr); + udp_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 udp_method_udp_socket_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t *ret, udp_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_udp_socket_send_buffer_size((self).__handle, ptr); + udp_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 udp_method_udp_socket_set_send_buffer_size(udp_borrow_udp_socket_t self, uint64_t value, udp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_udp_socket_set_send_buffer_size((self).__handle, (int64_t) (value), ptr); + udp_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; + } +} + +udp_own_pollable_t udp_method_udp_socket_subscribe(udp_borrow_udp_socket_t self) { + int32_t ret = __wasm_import_udp_method_udp_socket_subscribe((self).__handle); + return (udp_own_pollable_t) { ret }; +} + +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) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_incoming_datagram_stream_receive((self).__handle, (int64_t) (max_results), ptr); + udp_result_list_incoming_datagram_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (udp_list_incoming_datagram_t) { (udp_incoming_datagram_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; + 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; + } +} + +udp_own_pollable_t udp_method_incoming_datagram_stream_subscribe(udp_borrow_incoming_datagram_stream_t self) { + int32_t ret = __wasm_import_udp_method_incoming_datagram_stream_subscribe((self).__handle); + return (udp_own_pollable_t) { ret }; +} + +bool udp_method_outgoing_datagram_stream_check_send(udp_borrow_outgoing_datagram_stream_t self, uint64_t *ret, udp_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_outgoing_datagram_stream_check_send((self).__handle, ptr); + udp_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 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) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_method_outgoing_datagram_stream_send((self).__handle, (int32_t) (*datagrams).ptr, (int32_t) (*datagrams).len, ptr); + udp_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; + } +} + +udp_own_pollable_t udp_method_outgoing_datagram_stream_subscribe(udp_borrow_outgoing_datagram_stream_t self) { + int32_t ret = __wasm_import_udp_method_outgoing_datagram_stream_subscribe((self).__handle); + return (udp_own_pollable_t) { ret }; +} + +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) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_udp_create_socket_create_udp_socket((int32_t) address_family, ptr); + udp_create_socket_result_own_udp_socket_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (udp_create_socket_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 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) { + __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 network_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 network_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; + } + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_start_bind((self).__handle, (network).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); + tcp_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 tcp_method_tcp_socket_finish_bind(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_finish_bind((self).__handle, ptr); + tcp_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 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) { + __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 network_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 network_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; + } + } + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_start_connect((self).__handle, (network).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); + tcp_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 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) { + __attribute__((__aligned__(4))) + uint8_t ret_area[12]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_finish_connect((self).__handle, ptr); + tcp_result_tuple2_own_input_stream_own_output_stream_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (tcp_tuple2_own_input_stream_own_output_stream_t) { + (tcp_own_input_stream_t) { *((int32_t*) (ptr + 4)) }, + (tcp_own_output_stream_t) { *((int32_t*) (ptr + 8)) }, + }; + 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 tcp_method_tcp_socket_start_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_start_listen((self).__handle, ptr); + tcp_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 tcp_method_tcp_socket_finish_listen(tcp_borrow_tcp_socket_t self, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_finish_listen((self).__handle, ptr); + tcp_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 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) { + __attribute__((__aligned__(4))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_accept((self).__handle, ptr); + tcp_result_tuple3_own_tcp_socket_own_input_stream_own_output_stream_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (tcp_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t) { + (tcp_own_tcp_socket_t) { *((int32_t*) (ptr + 4)) }, + (tcp_own_input_stream_t) { *((int32_t*) (ptr + 8)) }, + (tcp_own_output_stream_t) { *((int32_t*) (ptr + 12)) }, + }; + 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 tcp_method_tcp_socket_local_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[36]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_local_address((self).__handle, ptr); + tcp_result_ip_socket_address_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + network_ip_socket_address_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (network_ipv4_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (network_ipv4_address_t) { + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 10)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 11)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 12)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 13)))), + }, + }; + break; + } + case 1: { + variant.val.ipv6 = (network_ipv6_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (uint32_t) (*((int32_t*) (ptr + 12))), + (network_ipv6_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 22)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 24)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 26)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 28)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 30)))), + }, + (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 tcp_method_tcp_socket_remote_address(tcp_borrow_tcp_socket_t self, tcp_ip_socket_address_t *ret, tcp_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[36]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_remote_address((self).__handle, ptr); + tcp_result_ip_socket_address_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + network_ip_socket_address_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (network_ipv4_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (network_ipv4_address_t) { + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 10)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 11)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 12)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 13)))), + }, + }; + break; + } + case 1: { + variant.val.ipv6 = (network_ipv6_socket_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (uint32_t) (*((int32_t*) (ptr + 12))), + (network_ipv6_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 22)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 24)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 26)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 28)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 30)))), + }, + (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 tcp_method_tcp_socket_is_listening(tcp_borrow_tcp_socket_t self) { + int32_t ret = __wasm_import_tcp_method_tcp_socket_is_listening((self).__handle); + return ret; +} + +tcp_ip_address_family_t tcp_method_tcp_socket_address_family(tcp_borrow_tcp_socket_t self) { + int32_t ret = __wasm_import_tcp_method_tcp_socket_address_family((self).__handle); + return ret; +} + +bool tcp_method_tcp_socket_ipv6_only(tcp_borrow_tcp_socket_t self, bool *ret, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_ipv6_only((self).__handle, ptr); + tcp_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 tcp_method_tcp_socket_set_ipv6_only(tcp_borrow_tcp_socket_t self, bool value, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_set_ipv6_only((self).__handle, value, ptr); + tcp_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 tcp_method_tcp_socket_set_listen_backlog_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_set_listen_backlog_size((self).__handle, (int64_t) (value), ptr); + tcp_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 tcp_method_tcp_socket_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool *ret, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_keep_alive_enabled((self).__handle, ptr); + tcp_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 tcp_method_tcp_socket_set_keep_alive_enabled(tcp_borrow_tcp_socket_t self, bool value, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_set_keep_alive_enabled((self).__handle, value, ptr); + tcp_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 tcp_method_tcp_socket_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_keep_alive_idle_time((self).__handle, ptr); + tcp_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 tcp_method_tcp_socket_set_keep_alive_idle_time(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_set_keep_alive_idle_time((self).__handle, (int64_t) (value), ptr); + tcp_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 tcp_method_tcp_socket_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t *ret, tcp_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_keep_alive_interval((self).__handle, ptr); + tcp_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 tcp_method_tcp_socket_set_keep_alive_interval(tcp_borrow_tcp_socket_t self, tcp_duration_t value, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_set_keep_alive_interval((self).__handle, (int64_t) (value), ptr); + tcp_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 tcp_method_tcp_socket_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t *ret, tcp_error_code_t *err) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_keep_alive_count((self).__handle, ptr); + tcp_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 tcp_method_tcp_socket_set_keep_alive_count(tcp_borrow_tcp_socket_t self, uint32_t value, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_set_keep_alive_count((self).__handle, (int32_t) (value), ptr); + tcp_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 tcp_method_tcp_socket_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t *ret, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_hop_limit((self).__handle, ptr); + tcp_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 tcp_method_tcp_socket_set_hop_limit(tcp_borrow_tcp_socket_t self, uint8_t value, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_set_hop_limit((self).__handle, (int32_t) (value), ptr); + tcp_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 tcp_method_tcp_socket_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_receive_buffer_size((self).__handle, ptr); + tcp_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 tcp_method_tcp_socket_set_receive_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_set_receive_buffer_size((self).__handle, (int64_t) (value), ptr); + tcp_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 tcp_method_tcp_socket_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t *ret, tcp_error_code_t *err) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_send_buffer_size((self).__handle, ptr); + tcp_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 tcp_method_tcp_socket_set_send_buffer_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_set_send_buffer_size((self).__handle, (int64_t) (value), ptr); + tcp_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; + } +} + +tcp_own_pollable_t tcp_method_tcp_socket_subscribe(tcp_borrow_tcp_socket_t self) { + int32_t ret = __wasm_import_tcp_method_tcp_socket_subscribe((self).__handle); + return (tcp_own_pollable_t) { ret }; +} + +bool tcp_method_tcp_socket_shutdown(tcp_borrow_tcp_socket_t self, tcp_shutdown_type_t shutdown_type, tcp_error_code_t *err) { + __attribute__((__aligned__(1))) + uint8_t ret_area[2]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_method_tcp_socket_shutdown((self).__handle, (int32_t) shutdown_type, ptr); + tcp_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 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) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_tcp_create_socket_create_tcp_socket((int32_t) address_family, ptr); + tcp_create_socket_result_own_tcp_socket_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + result.val.ok = (tcp_create_socket_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 ip_name_lookup_resolve_addresses(ip_name_lookup_borrow_network_t network, imports_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]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_ip_name_lookup_resolve_addresses((network).__handle, (int32_t) (*name).ptr, (int32_t) (*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]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_ip_name_lookup_method_resolve_address_stream_resolve_next_address((self).__handle, ptr); + ip_name_lookup_result_option_ip_address_error_code_t result; + switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { + case 0: { + result.is_err = false; + ip_name_lookup_option_ip_address_t option; + switch ((int32_t) (*((uint8_t*) (ptr + 2)))) { + case 0: { + option.is_some = false; + break; + } + case 1: { + option.is_some = true; + network_ip_address_t variant; + variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); + switch ((int32_t) variant.tag) { + case 0: { + variant.val.ipv4 = (network_ipv4_address_t) { + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 6)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 7)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 8)))), + (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 9)))), + }; + break; + } + case 1: { + variant.val.ipv6 = (network_ipv6_address_t) { + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 6)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 10)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 12)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 14)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), + (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), + }; + break; + } + } + + option.val = variant; + break; + } + } + + result.val.ok = option; + break; + } + case 1: { + result.is_err = true; + result.val.err = (int32_t) (*((uint8_t*) (ptr + 2))); + break; + } + } + if (!result.is_err) { + *ret = result.val.ok; + return 1; + } else { + *err = result.val.err; + return 0; + } +} + +ip_name_lookup_own_pollable_t ip_name_lookup_method_resolve_address_stream_subscribe(ip_name_lookup_borrow_resolve_address_stream_t self) { + int32_t ret = __wasm_import_ip_name_lookup_method_resolve_address_stream_subscribe((self).__handle); + return (ip_name_lookup_own_pollable_t) { ret }; +} + +void random_get_random_bytes(uint64_t len, random_list_u8_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_random_get_random_bytes((int64_t) (len), ptr); + *ret = (random_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +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, random_list_u8_t *ret) { + __attribute__((__aligned__(4))) + uint8_t ret_area[8]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_random_insecure_get_insecure_random_bytes((int64_t) (len), ptr); + *ret = (random_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; +} + +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_insecure_seed(random_insecure_seed_tuple2_u64_u64_t *ret) { + __attribute__((__aligned__(8))) + uint8_t ret_area[16]; + int32_t ptr = (int32_t) &ret_area; + __wasm_import_random_insecure_seed_insecure_seed(ptr); + *ret = (random_insecure_seed_tuple2_u64_u64_t) { + (uint64_t) (*((int64_t*) (ptr + 0))), + (uint64_t) (*((int64_t*) (ptr + 8))), + }; +} + +extern void __component_type_object_force_link_imports(void); +void __component_type_object_force_link_imports_public_use_in_this_compilation_unit(void) { + __component_type_object_force_link_imports(); +} diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2_component_type.o b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2_component_type.o new file mode 100644 index 0000000000000000000000000000000000000000..1d3af745676a6b4af5eaf7ede6129dfa4e793936 GIT binary patch literal 26798 zcmeHQS&!UEa?UKWuD&nbbCkMgG&-8yx<YCbtpf~>l`@zrtDK_@O2JC?s*eCxOf04;dCaYLdYj$>F0~}yi-DGA&WJF|K8O&yG zGUSXgZu6InSvAg|G@dv z8b4a%Q7uXMi18-`k*%NjspE%dK^%ocfZ;VhO6Z+svsHTM#wTNXkpTUvcvH98au5b- z;0~Pb#N!Q{-<-Hf@VGk&4h>LG?jGDfxa-7S=lG4lAiEJlDg?Q0ns+I{jYL9!`4MDhfE4Qt>(TF&EQP zCMKu`$w}g(T@N|n*#beWaE2{S1FTjhDY5Z>XOhAOpOX}xyB zR~M#uZWY#hu7Ygy3=n?QAlp{LBe`u(Yh>VHrnhM4=v4}{#qClyig%@JtQFZP23i}e z`K?~!90Onw-jk2C$XPJ?Dreth)XIDylZ-+JiJ3s*B zO%d)YS}5F{A9Xy4x~JGiBhE)tjI9MBmV&^P;P8fZj-bxMo~r4f&e9PZKe|cABWH~a z>Hu61`E3Vvyx-)b*ZdV<;tl?!CWO+q27WkU%Qm~BcxJ|if^U4qX1k?t1-~FShuF(k z0D3Y9dUX-#7PR^r?N(nZl5`YdZ<|3CQ@xSon$WQnsn|)pmdS{D~#BZqrKQZl-#W%?IV+lF=aO`uwuZJ}n=h@u`vLjELdJnO&B)G-p#IGafe6 z7VBJTON;OnBkU~lZqKD$CZ^d?EHc(>Gai82mvm}%UO{J0B zTY{#|-vA-W-d==okrHh2BP?7b_J+S=e1e)u5Tb??rsTfxYs(wUS_E{T%XrudBjFcN z?XcNW>?hG+Ow|hB6xk-XCw)JJSZ%hctrM~j0hPDOsL_Br4cN*DC_H@0;)hxO0Qa37 z4x=ziqcG??sDX4(OQX(hY!@Eanu!l9? zFzH9Qa@)i_aR;c9EkwFQ_CUu5YZ?hZiix)+)`uRK*oqoGhg-;MR19^P8oyW|yCG!J zLp3M~et~7Q_^{O+ho=xlxFQTEBCj*p*Ntx9jomKPHha+ag4pk-Q9QMKK`&ZOro-b1 zme?5t;ps~3pNt1?>=5Ke0`~eTl-~2n?~X7@R3;y4Z$+us3i|Py=1zAzuTnM5WV1ycR(j zmqu>dhsPBo)_7<)x*#g`^EI~pue)%_!I|GmQ6cQ&C8nXEhFY4Own3a+5@5U0nDl&$ zpEh~iu&D^UY`odFiP!B5VqtE#>nDjrN(4n7j&`nz$HT}AdI8W-wJv{oNtQt!2qQf4 zjTc4c(kP2v;9ptoFvtBtd)UBf;o1|+(+-Vd! zP?Zz^LNFNkC#WbKPa(#HL>zW~l$D)P9G$=(B={K$7>`GgJnYGtI|#g55Um7>A@xBN zjn)Y0&<&?T8X^~n{6XkbA{IS-K6h;xG_e44D`7YQ1$rYj3Q;hwS~OwI$8Kv{1g6x3O4r| zQLmTyX`6j&#G5%lk#aa^ftx|$Hz@Xh#XlO0@)=Zj5ypuhV#cyL3S?v%`2$KxquRqaSjp$K5}6_FX*Mfud1SLoC8DO?!+(IuZFBN5 zwznTY)T;JFn_VuMEcAr`9uIZ_;IYZa-#0QwgDqmOYHjB~DyNAg3Snj`_MS~nC?Qtd zD4{_*q}q)#={wFoXIchT!D^?R~L-YW;N*P`DwAIp{`95kRG@!&ex_pf5_E?k`9 z;Wz7IFRikFgV!vBEP??*{sLeVl8P*yD7pR;({wo^Ct27rMbww&vX9|<&WylD%3fKV z^KzqXgT=mZhM@XSw0h+5irmySIfHl=NCCjJ@~toq#o~mg$EY7`w$!7v@5g%#bvRvg zF(AXGC*-H2<5!3>`JaNR9aGi+1MKXSsBFO(@jutAnpa##Aj;fA0R-{-C%nJQPp^W6 z{}SpV?e2dv_AMYh&_oo&Bvm>p+5#D2@W0~yIzJ^7Zox(WH)Fp7qzlBPWQwphJA@UE zoBzz>w?y`kzdodpviz*|5|W2?!}0Q?CPn?Iju;QKY%{9WaO#hW8IFGu=aKbSMk|2L zt*h+MKs<_l((`iMSNPE;61~t*CsBL~zdpR6a*5R}&h`8-@I4XV=wN6=1vILyfNCL5 z)XPGyCRqeL*+JIT9mi1F?i8E}dq_4?5oDPWq7jd-D!63E{0%YpqEbzOLilO|ka~G&0>Yf_)XDM}X+YQ-G$2$hPRHejNK(DI9b~Q^)M9nK%z@ui3%q z>>>Rh+~H<0a@4AN?l2f2g12~Nzs7%5$ihhV-ePqgwZ6&zlP@3TFPrEj5RiF;3E;d1 zwOz{LqvS#91I4)CG&7tH1c(Ah#{2BC#g=(&%b{(Gd6DAvqN$qIY9(DLniF_PvuXY# zB|ANTRa3K)QL_eWXtlGL*45dDe32Yx8d{q2U&RL6R63kh%dQz(ZC2o*xzH^nDTtSa z&QrDQp4hAk)$E8;oF5QQBUq*;hMbQ`pO**}_mhF*@ER-iUgAgr9RPa|yPtvAjxO@s~yPMeHCsA<<3Uy0k zPl=NCnXwOK^3`Ap;@~F$HAC07eM>?q(EfKyZgg2GH zHl`B7`RShm@x(-Y!wAoe*~syI6o!z1Q#K*A;AWbIBF&MgNa~@>t z;|EH|?hta#jfL}aQVw~4OHIDZAcs3@&5JgDc4S99KsGyCSM=X)E1Q(uCqU+zQPBXY z08W5-kYhJVUx+;?{h`G_DR=}(v(yQ6VBfb5gU63n=B&8r@SC;b!n7~2)WX7FFB($T z;6W2oZQ)eq3D*&i+}Cx6?Z262o4Mjq_5A+qGMsFf^mV0++Qp()b*-Nt{S7VYJuBEn z*Ctj36QF@wOt`9ox5JTIjnDFFi5@QSc7oLlc(}%gRx{IKWWk|lA0u}`=``t&(ZV)C zffnJo#c-^%ly-A}MLOGWlh;{(m)BV(^Ps&>4&)qO#~57nI$4P%cXV^!#x%bM80qP< zn3i8Aqk+;|RJ%eM&^20&@;@IKp27f-(V-wf4m#O4MoBaS)PenwPK&iCFvet%)F9zT zt&apDADe{0_h`RqOsAw{l)~{)!OWn0w;Ws1Z$ihk8#G|f_|3hX8^~nK)`?73(odZ$ za7l`JID0RHKjUV}3B56Cht1NNyg^p(FK1m((ajoDif;C%vXI--Sr$Fk%rv;+%{aEG2NIN zcsNF)w2|MLSyhuZnsy$>>>1=agnh&58{c+~So2>E*EBLsT)?g-%qrL{&4fgfEY zKV5YCBJL@8_{I4wtcw8-Yr)A=Rx(jZo{<=~C@-a6H!bTnTQ;hCd|}>#cb_R|pykB0kD^emTNRWkWK|@`IubvjS6!`!@BbMzzU=N}E_9DuEeN zoSAwYaj#>pqVTp9;2k>);;FqV`--Y;AijcH#dlTei>r&Q`9HF0_ZfOoLDBd9m6a-N ziB{YEgRL^s>a1$ot(ta?54vE(s2kTfT`#os>aIySO!)HIeqfk59d;KcS53RJf%Ppd z!Bx|4)wFA!?{m4TX_r0#K&w;Xi!*r;qdzmMns(6$jKk!rX}4t7rl~|5g9{X16cCWX5;*URg_R*6o{( zur4$9kE<)V66%z$n)0GSLz;oa_+e%iqW z8J)lUi@$#Mcj#B24*ZTWqI2fP0ewxA96S%7hhN}wg3{NWAnD-tth2!Ly^fo7+|I}i z;!f1-$g6ZUoDTJkC(m)eotMADMNR_zPjDx}U@+Y$iW0x$#`qs*;&n&1I`4Om$7u(* zo&|%#b0DO#XSlZ&aUZIop>2k47?5E>c&Z8?q zp40VLxc#l;)1v9*sS~8MPJG3UuZs?L_jie%>M{xNx0IRseJ70sP2!Rh+x{3Q#_ z{;9-ItV@Bg@2133y2~L^B;pnb;x5<&=4P`y^0JDwLziLT+pp)Lx?BT{6l#IXG*Z0i zygYbGv$5P5&>?_c6bp_V?7n`zze|6;qM$AE!R{A$E+|)s(8n%rBj^weTz=M}t5+a* z^*oXAaDQC^ocMkBr(?-t%?3hUY`LRZ;^q!-;oP~hKvmag?8$D z@Ile>n=t}sE#DI(0O>n2LeP*gf}s4481ecw`=d5?wKwkial%*dBV9R(yEBicwNF{TDR&MfM@g{{rq1Jjwt7 literal 0 HcmV?d00001 diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor.c b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor.c deleted file mode 100644 index b913166f9..000000000 --- a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor.c +++ /dev/null @@ -1,4587 +0,0 @@ -// Generated by `wit-bindgen` 0.14.0. DO NOT EDIT! -#include "reactor.h" - - -typedef struct { - bool is_err; - union { - reactor_list_u8_t ok; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t err; - } val; -} reactor_result_list_u8_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t; - -typedef struct { - bool is_err; - union { - uint64_t ok; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t err; - } val; -} reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t; - -typedef struct { - bool is_err; - union { - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t err; - } val; -} reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t; - -typedef struct { - bool is_err; - union { - reactor_own_input_stream_t ok; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; - } val; -} reactor_result_own_input_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_err; - union { - reactor_own_output_stream_t ok; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; - } val; -} reactor_result_own_output_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_err; - union { - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; - } val; -} reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_err; - union { - wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_t ok; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; - } val; -} reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_err; - union { - wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_t ok; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; - } val; -} reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_err; - union { - reactor_tuple2_list_u8_bool_t ok; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; - } val; -} reactor_result_tuple2_list_u8_bool_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_err; - union { - wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t ok; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; - } val; -} reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_err; - union { - reactor_own_directory_entry_stream_t ok; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; - } val; -} reactor_result_own_directory_entry_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_err; - union { - wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t ok; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; - } val; -} reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_err; - union { - reactor_own_descriptor_t ok; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; - } val; -} reactor_result_own_descriptor_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_err; - union { - reactor_string_t ok; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; - } val; -} reactor_result_string_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_err; - union { - wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t ok; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; - } val; -} reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_err; - union { - reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t ok; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t err; - } val; -} reactor_result_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_some; - wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t val; -} reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -typedef struct { - bool is_some; - wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t val; -} reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t; - -typedef struct { - bool is_err; - union { - reactor_own_resolve_address_stream_t ok; - wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t err; - } val; -} reactor_result_own_resolve_address_stream_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t; - -typedef struct { - bool is_err; - union { - reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t ok; - wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t err; - } val; -} reactor_result_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t; - -typedef struct { - bool is_err; - union { - wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; - } val; -} reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; - -typedef struct { - bool is_err; - union { - reactor_tuple2_own_input_stream_own_output_stream_t ok; - wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; - } val; -} reactor_result_tuple2_own_input_stream_own_output_stream_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; - -typedef struct { - bool is_err; - union { - reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t ok; - wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; - } val; -} reactor_result_tuple3_own_tcp_socket_own_input_stream_own_output_stream_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; - -typedef struct { - bool is_err; - union { - wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t ok; - wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; - } val; -} reactor_result_wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; - -typedef struct { - bool is_err; - union { - bool ok; - wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; - } val; -} reactor_result_bool_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; - -typedef struct { - bool is_err; - union { - uint8_t ok; - wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; - } val; -} reactor_result_u8_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; - -typedef struct { - bool is_err; - union { - uint64_t ok; - wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t err; - } val; -} reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; - -typedef struct { - bool is_err; - union { - reactor_own_tcp_socket_t ok; - wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t err; - } val; -} reactor_result_own_tcp_socket_wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t; - -typedef struct { - bool is_err; - union { - wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t err; - } val; -} reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; - -typedef struct { - bool is_err; - union { - reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t ok; - wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t err; - } val; -} reactor_result_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; - -typedef struct { - bool is_err; - union { - uint64_t ok; - wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t err; - } val; -} reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; - -typedef struct { - bool is_err; - union { - wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t ok; - wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t err; - } val; -} reactor_result_wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; - -typedef struct { - bool is_err; - union { - bool ok; - wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t err; - } val; -} reactor_result_bool_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; - -typedef struct { - bool is_err; - union { - uint8_t ok; - wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t err; - } val; -} reactor_result_u8_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; - -typedef struct { - bool is_err; - union { - reactor_own_udp_socket_t ok; - wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_error_code_t err; - } val; -} reactor_result_own_udp_socket_wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_error_code_t; - -typedef struct { - bool is_some; - reactor_string_t val; -} reactor_option_string_t; - -typedef struct { - bool is_some; - reactor_own_terminal_input_t val; -} reactor_option_own_terminal_input_t; - -typedef struct { - bool is_some; - reactor_own_terminal_output_t val; -} reactor_option_own_terminal_output_t; - -__attribute__((__import_module__("wasi:clocks/wall-clock@0.2.0-rc-2023-10-18"), __import_name__("now"))) -extern void __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_now(int32_t); - -__attribute__((__import_module__("wasi:clocks/wall-clock@0.2.0-rc-2023-10-18"), __import_name__("resolution"))) -extern void __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_resolution(int32_t); - -__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-10-18"), __import_name__("poll-list"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_poll_poll_list(int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-10-18"), __import_name__("poll-one"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(int32_t); - -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18"), __import_name__("now"))) -extern int64_t __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_now(void); - -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18"), __import_name__("resolution"))) -extern int64_t __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_resolution(void); - -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18"), __import_name__("subscribe"))) -extern int32_t __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_subscribe(int64_t, int32_t); - -__attribute__((__import_module__("wasi:clocks/timezone@0.2.0-rc-2023-10-18"), __import_name__("display"))) -extern void __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_timezone_display(int64_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:clocks/timezone@0.2.0-rc-2023-10-18"), __import_name__("utc-offset"))) -extern int32_t __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_timezone_utc_offset(int64_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]error.to-debug-string"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_error_to_debug_string(int32_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]input-stream.read"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_read(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]input-stream.blocking-read"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_read(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]input-stream.skip"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_skip(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]input-stream.blocking-skip"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_skip(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]input-stream.subscribe"))) -extern int32_t __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe(int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.check-write"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_check_write(int32_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.write"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write(int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.blocking-write-and-flush"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_and_flush(int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.flush"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_flush(int32_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.blocking-flush"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_flush(int32_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.subscribe"))) -extern int32_t __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe(int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.write-zeroes"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write_zeroes(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.blocking-write-zeroes-and-flush"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_zeroes_and_flush(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.splice"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_splice(int32_t, int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.blocking-splice"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_splice(int32_t, int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[method]output-stream.forward"))) -extern void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_forward(int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.read-via-stream"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_via_stream(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.write-via-stream"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write_via_stream(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.append-via-stream"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_append_via_stream(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.advise"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_advise(int32_t, int64_t, int64_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.sync-data"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync_data(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.get-flags"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_flags(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.get-type"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_type(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.set-size"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_size(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.set-times"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times(int32_t, int32_t, int64_t, int32_t, int32_t, int64_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.read"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read(int32_t, int64_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.write"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write(int32_t, int32_t, int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.read-directory"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_directory(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.sync"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.create-directory-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_create_directory_at(int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.stat"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.stat-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat_at(int32_t, int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.set-times-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times_at(int32_t, int32_t, int32_t, int32_t, int32_t, int64_t, int32_t, int32_t, int64_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.link-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_link_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.open-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_open_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.readlink-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_readlink_at(int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.remove-directory-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_remove_directory_at(int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.rename-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_rename_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.symlink-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_symlink_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.access-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_access_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.unlink-file-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlink_file_at(int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.change-file-permissions-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_file_permissions_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.change-directory-permissions-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_directory_permissions_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.lock-shared"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_shared(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.lock-exclusive"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_exclusive(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.try-lock-shared"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_shared(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.try-lock-exclusive"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_exclusive(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.unlock"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlock(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.is-same-object"))) -extern int32_t __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_is_same_object(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.metadata-hash"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]descriptor.metadata-hash-at"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash_at(int32_t, int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[method]directory-entry-stream.read-directory-entry"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_directory_entry_stream_read_directory_entry(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("filesystem-error-code"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_filesystem_error_code(int32_t, int32_t); - -__attribute__((__import_module__("wasi:filesystem/preopens@0.2.0-rc-2023-10-18"), __import_name__("get-directories"))) -extern void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_preopens_get_directories(int32_t); - -__attribute__((__import_module__("wasi:sockets/instance-network@0.2.0-rc-2023-10-18"), __import_name__("instance-network"))) -extern int32_t __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_instance_network_instance_network(void); - -__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18"), __import_name__("resolve-addresses"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_addresses(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18"), __import_name__("[method]resolve-address-stream.resolve-next-address"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_resolve_next_address(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18"), __import_name__("[method]resolve-address-stream.subscribe"))) -extern int32_t __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_subscribe(int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.start-bind"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_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, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.finish-bind"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_bind(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.start-connect"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_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, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.finish-connect"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_connect(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.start-listen"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_listen(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.finish-listen"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_listen(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.accept"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_accept(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.local-address"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_local_address(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.remote-address"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_remote_address(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.address-family"))) -extern int32_t __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.ipv6-only"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_ipv6_only(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-ipv6-only"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_ipv6_only(int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-listen-backlog-size"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_listen_backlog_size(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.keep-alive"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_keep_alive(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-keep-alive"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_keep_alive(int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.no-delay"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_no_delay(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-no-delay"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_no_delay(int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.unicast-hop-limit"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_unicast_hop_limit(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-unicast-hop-limit"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_unicast_hop_limit(int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.receive-buffer-size"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_receive_buffer_size(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-receive-buffer-size"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_receive_buffer_size(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.send-buffer-size"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_send_buffer_size(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.set-send-buffer-size"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_send_buffer_size(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.subscribe"))) -extern int32_t __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[method]tcp-socket.shutdown"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_shutdown(int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18"), __import_name__("create-tcp-socket"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_create_tcp_socket(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.start-bind"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_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, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.finish-bind"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_bind(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.start-connect"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_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, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.finish-connect"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_connect(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.receive"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.send"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send(int32_t, int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.local-address"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_local_address(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.remote-address"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_remote_address(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.address-family"))) -extern int32_t __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_address_family(int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.ipv6-only"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_ipv6_only(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.set-ipv6-only"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_ipv6_only(int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.unicast-hop-limit"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_unicast_hop_limit(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.set-unicast-hop-limit"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_unicast_hop_limit(int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.receive-buffer-size"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive_buffer_size(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.set-receive-buffer-size"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_receive_buffer_size(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.send-buffer-size"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send_buffer_size(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.set-send-buffer-size"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_send_buffer_size(int32_t, int64_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[method]udp-socket.subscribe"))) -extern int32_t __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_subscribe(int32_t); - -__attribute__((__import_module__("wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18"), __import_name__("create-udp-socket"))) -extern void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_create_udp_socket(int32_t, int32_t); - -__attribute__((__import_module__("wasi:random/random@0.2.0-rc-2023-10-18"), __import_name__("get-random-bytes"))) -extern void __wasm_import_wasi_random_0_2_0_rc_2023_10_18_random_get_random_bytes(int64_t, int32_t); - -__attribute__((__import_module__("wasi:random/random@0.2.0-rc-2023-10-18"), __import_name__("get-random-u64"))) -extern int64_t __wasm_import_wasi_random_0_2_0_rc_2023_10_18_random_get_random_u64(void); - -__attribute__((__import_module__("wasi:random/insecure@0.2.0-rc-2023-10-18"), __import_name__("get-insecure-random-bytes"))) -extern void __wasm_import_wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_bytes(int64_t, int32_t); - -__attribute__((__import_module__("wasi:random/insecure@0.2.0-rc-2023-10-18"), __import_name__("get-insecure-random-u64"))) -extern int64_t __wasm_import_wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_u64(void); - -__attribute__((__import_module__("wasi:random/insecure-seed@0.2.0-rc-2023-10-18"), __import_name__("insecure-seed"))) -extern void __wasm_import_wasi_random_0_2_0_rc_2023_10_18_insecure_seed_insecure_seed(int32_t); - -__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-10-18"), __import_name__("get-environment"))) -extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_environment_get_environment(int32_t); - -__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-10-18"), __import_name__("get-arguments"))) -extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_environment_get_arguments(int32_t); - -__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-10-18"), __import_name__("initial-cwd"))) -extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_environment_initial_cwd(int32_t); - -__attribute__((__import_module__("wasi:cli/exit@0.2.0-rc-2023-10-18"), __import_name__("exit"))) -extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_exit_exit(int32_t); - -__attribute__((__import_module__("wasi:cli/stdin@0.2.0-rc-2023-10-18"), __import_name__("get-stdin"))) -extern int32_t __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_stdin_get_stdin(void); - -__attribute__((__import_module__("wasi:cli/stdout@0.2.0-rc-2023-10-18"), __import_name__("get-stdout"))) -extern int32_t __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_stdout_get_stdout(void); - -__attribute__((__import_module__("wasi:cli/stderr@0.2.0-rc-2023-10-18"), __import_name__("get-stderr"))) -extern int32_t __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_stderr_get_stderr(void); - -__attribute__((__import_module__("wasi:cli/terminal-stdin@0.2.0-rc-2023-10-18"), __import_name__("get-terminal-stdin"))) -extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_stdin_get_terminal_stdin(int32_t); - -__attribute__((__import_module__("wasi:cli/terminal-stdout@0.2.0-rc-2023-10-18"), __import_name__("get-terminal-stdout"))) -extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_stdout_get_terminal_stdout(int32_t); - -__attribute__((__import_module__("wasi:cli/terminal-stderr@0.2.0-rc-2023-10-18"), __import_name__("get-terminal-stderr"))) -extern void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_stderr_get_terminal_stderr(int32_t); - -__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 reactor_borrow_pollable_free(reactor_borrow_pollable_t *ptr) { - reactor_pollable_drop_borrow(*ptr); -} - -void reactor_list_borrow_pollable_free(reactor_list_borrow_pollable_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - reactor_borrow_pollable_free(&ptr->ptr[i]); - } - if (ptr->len > 0) { - free(ptr->ptr); - } -} - -void reactor_list_u32_free(reactor_list_u32_t *ptr) { - if (ptr->len > 0) { - free(ptr->ptr); - } -} - -void reactor_own_error_free(reactor_own_error_t *ptr) { - wasi_io_0_2_0_rc_2023_10_18_streams_error_drop_own(*ptr); -} - -void wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_free(wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *ptr) { - switch ((int32_t) ptr->tag) { - case 0: { - reactor_own_error_free(&ptr->val.last_operation_failed); - break; - } - } -} - -void reactor_borrow_error_free(reactor_borrow_error_t *ptr) { - reactor_error_drop_borrow(*ptr); -} - -void reactor_borrow_input_stream_free(reactor_borrow_input_stream_t *ptr) { - reactor_input_stream_drop_borrow(*ptr); -} - -void reactor_list_u8_free(reactor_list_u8_t *ptr) { - if (ptr->len > 0) { - free(ptr->ptr); - } -} - -void reactor_borrow_output_stream_free(reactor_borrow_output_stream_t *ptr) { - reactor_output_stream_drop_borrow(*ptr); -} - -void reactor_own_pollable_free(reactor_own_pollable_t *ptr) { - wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(*ptr); -} - -void reactor_own_input_stream_free(reactor_own_input_stream_t *ptr) { - wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(*ptr); -} - -void wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_free(wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_t *ptr) { - reactor_string_free(&ptr->name); -} - -void wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_free(wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t *ptr) { - reactor_string_free(&ptr->name); -} - -void reactor_borrow_descriptor_free(reactor_borrow_descriptor_t *ptr) { - reactor_descriptor_drop_borrow(*ptr); -} - -void reactor_own_output_stream_free(reactor_own_output_stream_t *ptr) { - wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(*ptr); -} - -void reactor_tuple2_list_u8_bool_free(reactor_tuple2_list_u8_bool_t *ptr) { - reactor_list_u8_free(&ptr->f0); -} - -void reactor_own_directory_entry_stream_free(reactor_own_directory_entry_stream_t *ptr) { - wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_stream_drop_own(*ptr); -} - -void reactor_own_descriptor_free(reactor_own_descriptor_t *ptr) { - wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_drop_own(*ptr); -} - -void reactor_borrow_directory_entry_stream_free(reactor_borrow_directory_entry_stream_t *ptr) { - reactor_directory_entry_stream_drop_borrow(*ptr); -} - -void reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_free(reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t *ptr) { - if (ptr->is_some) { - wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_free(&ptr->val); - } -} - -void reactor_tuple2_own_descriptor_string_free(reactor_tuple2_own_descriptor_string_t *ptr) { - reactor_own_descriptor_free(&ptr->f0); - reactor_string_free(&ptr->f1); -} - -void reactor_list_tuple2_own_descriptor_string_free(reactor_list_tuple2_own_descriptor_string_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - reactor_tuple2_own_descriptor_string_free(&ptr->ptr[i]); - } - if (ptr->len > 0) { - free(ptr->ptr); - } -} - -void reactor_borrow_network_free(reactor_borrow_network_t *ptr) { - reactor_network_drop_borrow(*ptr); -} - -void reactor_own_resolve_address_stream_free(reactor_own_resolve_address_stream_t *ptr) { - wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_address_stream_drop_own(*ptr); -} - -void reactor_borrow_resolve_address_stream_free(reactor_borrow_resolve_address_stream_t *ptr) { - reactor_resolve_address_stream_drop_borrow(*ptr); -} - -void reactor_borrow_tcp_socket_free(reactor_borrow_tcp_socket_t *ptr) { - reactor_tcp_socket_drop_borrow(*ptr); -} - -void reactor_tuple2_own_input_stream_own_output_stream_free(reactor_tuple2_own_input_stream_own_output_stream_t *ptr) { - reactor_own_input_stream_free(&ptr->f0); - reactor_own_output_stream_free(&ptr->f1); -} - -void reactor_own_tcp_socket_free(reactor_own_tcp_socket_t *ptr) { - wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(*ptr); -} - -void reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_free(reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ptr) { - reactor_own_tcp_socket_free(&ptr->f0); - reactor_own_input_stream_free(&ptr->f1); - reactor_own_output_stream_free(&ptr->f2); -} - -void wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_free(wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ptr) { - reactor_list_u8_free(&ptr->data); -} - -void reactor_borrow_udp_socket_free(reactor_borrow_udp_socket_t *ptr) { - reactor_udp_socket_drop_borrow(*ptr); -} - -void reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_free(reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_free(&ptr->ptr[i]); - } - if (ptr->len > 0) { - free(ptr->ptr); - } -} - -void reactor_own_udp_socket_free(reactor_own_udp_socket_t *ptr) { - wasi_sockets_0_2_0_rc_2023_10_18_udp_udp_socket_drop_own(*ptr); -} - -void reactor_own_network_free(reactor_own_network_t *ptr) { - wasi_sockets_0_2_0_rc_2023_10_18_network_network_drop_own(*ptr); -} - -void reactor_tuple2_string_string_free(reactor_tuple2_string_string_t *ptr) { - reactor_string_free(&ptr->f0); - reactor_string_free(&ptr->f1); -} - -void reactor_list_tuple2_string_string_free(reactor_list_tuple2_string_string_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - reactor_tuple2_string_string_free(&ptr->ptr[i]); - } - if (ptr->len > 0) { - free(ptr->ptr); - } -} - -void reactor_list_string_free(reactor_list_string_t *ptr) { - for (size_t i = 0; i < ptr->len; i++) { - reactor_string_free(&ptr->ptr[i]); - } - if (ptr->len > 0) { - free(ptr->ptr); - } -} - -void reactor_own_terminal_input_free(reactor_own_terminal_input_t *ptr) { - wasi_cli_0_2_0_rc_2023_10_18_terminal_input_terminal_input_drop_own(*ptr); -} - -void reactor_own_terminal_output_free(reactor_own_terminal_output_t *ptr) { - wasi_cli_0_2_0_rc_2023_10_18_terminal_output_terminal_output_drop_own(*ptr); -} - -void reactor_string_set(reactor_string_t *ret, char*s) { - ret->ptr = (uint8_t*) s; - ret->len = strlen(s); -} - -void reactor_string_dup(reactor_string_t *ret, const char*s) { - ret->len = strlen(s); - ret->ptr = cabi_realloc(NULL, 0, 1, ret->len * 1); - memcpy(ret->ptr, s, ret->len * 1); -} - -void reactor_string_free(reactor_string_t *ret) { - if (ret->len > 0) { - free(ret->ptr); - } - ret->ptr = NULL; - ret->len = 0; -} - -// Functions for working with resource `wasi:filesystem/types@0.2.0-rc-2023-10-18/directory-entry-stream` -reactor_borrow_directory_entry_stream_t wasi_filesystem_0_2_0_rc_2023_10_18_types_borrow_directory_entry_stream(reactor_own_directory_entry_stream_t arg) { - return (reactor_borrow_directory_entry_stream_t) { arg.__handle }; -} -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]directory-entry-stream"))) -void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_stream_drop_own(int32_t); - -void wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_stream_drop_own(reactor_own_directory_entry_stream_t arg) { - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_stream_drop_own(arg.__handle); -} -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]directory-entry-stream"))) -void __wasm_import_reactor_directory_entry_stream_drop_borrow(int32_t); - -void reactor_directory_entry_stream_drop_borrow(reactor_borrow_directory_entry_stream_t arg) { - __wasm_import_reactor_directory_entry_stream_drop_borrow(arg.__handle); -} - -// Functions for working with resource `wasi:io/streams@0.2.0-rc-2023-10-18/output-stream` -reactor_borrow_output_stream_t wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(reactor_own_output_stream_t arg) { - return (reactor_borrow_output_stream_t) { arg.__handle }; -} -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]output-stream"))) -void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(int32_t); - -void wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(reactor_own_output_stream_t arg) { - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(arg.__handle); -} -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]output-stream"))) -void __wasm_import_reactor_output_stream_drop_borrow(int32_t); - -void reactor_output_stream_drop_borrow(reactor_borrow_output_stream_t arg) { - __wasm_import_reactor_output_stream_drop_borrow(arg.__handle); -} - -// Functions for working with resource `wasi:io/streams@0.2.0-rc-2023-10-18/error` -reactor_borrow_error_t wasi_io_0_2_0_rc_2023_10_18_streams_borrow_error(reactor_own_error_t arg) { - return (reactor_borrow_error_t) { arg.__handle }; -} -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]error"))) -void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_error_drop_own(int32_t); - -void wasi_io_0_2_0_rc_2023_10_18_streams_error_drop_own(reactor_own_error_t arg) { - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_error_drop_own(arg.__handle); -} -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]error"))) -void __wasm_import_reactor_error_drop_borrow(int32_t); - -void reactor_error_drop_borrow(reactor_borrow_error_t arg) { - __wasm_import_reactor_error_drop_borrow(arg.__handle); -} - -// Functions for working with resource `wasi:io/poll@0.2.0-rc-2023-10-18/pollable` -reactor_borrow_pollable_t wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(reactor_own_pollable_t arg) { - return (reactor_borrow_pollable_t) { arg.__handle }; -} -__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]pollable"))) -void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(int32_t); - -void wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(reactor_own_pollable_t arg) { - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(arg.__handle); -} -__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]pollable"))) -void __wasm_import_reactor_pollable_drop_borrow(int32_t); - -void reactor_pollable_drop_borrow(reactor_borrow_pollable_t arg) { - __wasm_import_reactor_pollable_drop_borrow(arg.__handle); -} - -// Functions for working with resource `wasi:sockets/tcp@0.2.0-rc-2023-10-18/tcp-socket` -reactor_borrow_tcp_socket_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(reactor_own_tcp_socket_t arg) { - return (reactor_borrow_tcp_socket_t) { arg.__handle }; -} -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]tcp-socket"))) -void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(int32_t); - -void wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(reactor_own_tcp_socket_t arg) { - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(arg.__handle); -} -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]tcp-socket"))) -void __wasm_import_reactor_tcp_socket_drop_borrow(int32_t); - -void reactor_tcp_socket_drop_borrow(reactor_borrow_tcp_socket_t arg) { - __wasm_import_reactor_tcp_socket_drop_borrow(arg.__handle); -} - -// Functions for working with resource `wasi:cli/terminal-input@0.2.0-rc-2023-10-18/terminal-input` -__attribute__((__import_module__("wasi:cli/terminal-input@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]terminal-input"))) -void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_input_terminal_input_drop_own(int32_t); - -void wasi_cli_0_2_0_rc_2023_10_18_terminal_input_terminal_input_drop_own(reactor_own_terminal_input_t arg) { - __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_input_terminal_input_drop_own(arg.__handle); -} - -// Functions for working with resource `wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18/resolve-address-stream` -reactor_borrow_resolve_address_stream_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_borrow_resolve_address_stream(reactor_own_resolve_address_stream_t arg) { - return (reactor_borrow_resolve_address_stream_t) { arg.__handle }; -} -__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]resolve-address-stream"))) -void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_address_stream_drop_own(int32_t); - -void wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_address_stream_drop_own(reactor_own_resolve_address_stream_t arg) { - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_address_stream_drop_own(arg.__handle); -} -__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]resolve-address-stream"))) -void __wasm_import_reactor_resolve_address_stream_drop_borrow(int32_t); - -void reactor_resolve_address_stream_drop_borrow(reactor_borrow_resolve_address_stream_t arg) { - __wasm_import_reactor_resolve_address_stream_drop_borrow(arg.__handle); -} - -// Functions for working with resource `wasi:cli/terminal-output@0.2.0-rc-2023-10-18/terminal-output` -__attribute__((__import_module__("wasi:cli/terminal-output@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]terminal-output"))) -void __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_output_terminal_output_drop_own(int32_t); - -void wasi_cli_0_2_0_rc_2023_10_18_terminal_output_terminal_output_drop_own(reactor_own_terminal_output_t arg) { - __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_output_terminal_output_drop_own(arg.__handle); -} - -// Functions for working with resource `wasi:sockets/network@0.2.0-rc-2023-10-18/network` -reactor_borrow_network_t wasi_sockets_0_2_0_rc_2023_10_18_network_borrow_network(reactor_own_network_t arg) { - return (reactor_borrow_network_t) { arg.__handle }; -} -__attribute__((__import_module__("wasi:sockets/network@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]network"))) -void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_network_network_drop_own(int32_t); - -void wasi_sockets_0_2_0_rc_2023_10_18_network_network_drop_own(reactor_own_network_t arg) { - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_network_network_drop_own(arg.__handle); -} -__attribute__((__import_module__("wasi:sockets/network@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]network"))) -void __wasm_import_reactor_network_drop_borrow(int32_t); - -void reactor_network_drop_borrow(reactor_borrow_network_t arg) { - __wasm_import_reactor_network_drop_borrow(arg.__handle); -} - -// Functions for working with resource `wasi:io/streams@0.2.0-rc-2023-10-18/input-stream` -reactor_borrow_input_stream_t wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(reactor_own_input_stream_t arg) { - return (reactor_borrow_input_stream_t) { arg.__handle }; -} -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]input-stream"))) -void __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(int32_t); - -void wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(reactor_own_input_stream_t arg) { - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(arg.__handle); -} -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]input-stream"))) -void __wasm_import_reactor_input_stream_drop_borrow(int32_t); - -void reactor_input_stream_drop_borrow(reactor_borrow_input_stream_t arg) { - __wasm_import_reactor_input_stream_drop_borrow(arg.__handle); -} - -// Functions for working with resource `wasi:filesystem/types@0.2.0-rc-2023-10-18/descriptor` -reactor_borrow_descriptor_t wasi_filesystem_0_2_0_rc_2023_10_18_types_borrow_descriptor(reactor_own_descriptor_t arg) { - return (reactor_borrow_descriptor_t) { arg.__handle }; -} -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]descriptor"))) -void __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_drop_own(int32_t); - -void wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_drop_own(reactor_own_descriptor_t arg) { - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_drop_own(arg.__handle); -} -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]descriptor"))) -void __wasm_import_reactor_descriptor_drop_borrow(int32_t); - -void reactor_descriptor_drop_borrow(reactor_borrow_descriptor_t arg) { - __wasm_import_reactor_descriptor_drop_borrow(arg.__handle); -} - -// Functions for working with resource `wasi:sockets/udp@0.2.0-rc-2023-10-18/udp-socket` -reactor_borrow_udp_socket_t wasi_sockets_0_2_0_rc_2023_10_18_udp_borrow_udp_socket(reactor_own_udp_socket_t arg) { - return (reactor_borrow_udp_socket_t) { arg.__handle }; -} -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]udp-socket"))) -void __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_udp_socket_drop_own(int32_t); - -void wasi_sockets_0_2_0_rc_2023_10_18_udp_udp_socket_drop_own(reactor_own_udp_socket_t arg) { - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_udp_socket_drop_own(arg.__handle); -} -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-10-18"), __import_name__("[resource-drop]udp-socket"))) -void __wasm_import_reactor_udp_socket_drop_borrow(int32_t); - -void reactor_udp_socket_drop_borrow(reactor_borrow_udp_socket_t arg) { - __wasm_import_reactor_udp_socket_drop_borrow(arg.__handle); -} - -// Component Adapters - -void wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_now(wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t *ret) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_now(ptr); - *ret = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { - (uint64_t) (*((int64_t*) (ptr + 0))), - (uint32_t) (*((int32_t*) (ptr + 8))), - }; -} - -void wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_resolution(wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t *ret) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_resolution(ptr); - *ret = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { - (uint64_t) (*((int64_t*) (ptr + 0))), - (uint32_t) (*((int32_t*) (ptr + 8))), - }; -} - -void wasi_io_0_2_0_rc_2023_10_18_poll_poll_list(reactor_list_borrow_pollable_t *in, reactor_list_u32_t *ret) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_poll_poll_list((int32_t) (*in).ptr, (int32_t) (*in).len, ptr); - *ret = (reactor_list_u32_t) { (uint32_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; -} - -void wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(reactor_borrow_pollable_t in) { - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_poll_poll_one((in).__handle); -} - -wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_now(void) { - int64_t ret = __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_now(); - return (uint64_t) (ret); -} - -wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_resolution(void) { - int64_t ret = __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_resolution(); - return (uint64_t) (ret); -} - -reactor_own_pollable_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_subscribe(wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t when, bool absolute) { - int32_t ret = __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_subscribe((int64_t) (when), absolute); - return (reactor_own_pollable_t) { ret }; -} - -void wasi_clocks_0_2_0_rc_2023_10_18_timezone_display(wasi_clocks_0_2_0_rc_2023_10_18_timezone_datetime_t *when, wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_t *ret) { - __attribute__((__aligned__(4))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_timezone_display((int64_t) ((*when).seconds), (int32_t) ((*when).nanoseconds), ptr); - *ret = (wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_t) { - *((int32_t*) (ptr + 0)), - (reactor_string_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, - (int32_t) (*((uint8_t*) (ptr + 12))), - }; -} - -int32_t wasi_clocks_0_2_0_rc_2023_10_18_timezone_utc_offset(wasi_clocks_0_2_0_rc_2023_10_18_timezone_datetime_t *when) { - int32_t ret = __wasm_import_wasi_clocks_0_2_0_rc_2023_10_18_timezone_utc_offset((int64_t) ((*when).seconds), (int32_t) ((*when).nanoseconds)); - return ret; -} - -void wasi_io_0_2_0_rc_2023_10_18_streams_method_error_to_debug_string(reactor_borrow_error_t self, reactor_string_t *ret) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_error_to_debug_string((self).__handle, ptr); - *ret = (reactor_string_t) { (uint8_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_read(reactor_borrow_input_stream_t self, uint64_t len, reactor_list_u8_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[12]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_read((self).__handle, (int64_t) (len), ptr); - reactor_result_list_u8_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - result.is_err = true; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - *ret = result.val.ok; - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_read(reactor_borrow_input_stream_t self, uint64_t len, reactor_list_u8_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[12]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_read((self).__handle, (int64_t) (len), ptr); - reactor_result_list_u8_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - case 1: { - result.is_err = true; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - *ret = result.val.ok; - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_skip(reactor_borrow_input_stream_t self, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_skip((self).__handle, (int64_t) (len), ptr); - reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_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; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 12)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - *ret = result.val.ok; - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_skip(reactor_borrow_input_stream_t self, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_skip((self).__handle, (int64_t) (len), ptr); - reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_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; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 12)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - *ret = result.val.ok; - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -reactor_own_pollable_t wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe(reactor_borrow_input_stream_t self) { - int32_t ret = __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe((self).__handle); - return (reactor_own_pollable_t) { ret }; -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_check_write(reactor_borrow_output_stream_t self, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_check_write((self).__handle, ptr); - reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_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; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 12)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - *ret = result.val.ok; - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write(reactor_borrow_output_stream_t self, reactor_list_u8_t *contents, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[12]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write((self).__handle, (int32_t) (*contents).ptr, (int32_t) (*contents).len, ptr); - reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - break; - } - case 1: { - result.is_err = true; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_and_flush(reactor_borrow_output_stream_t self, reactor_list_u8_t *contents, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[12]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_and_flush((self).__handle, (int32_t) (*contents).ptr, (int32_t) (*contents).len, ptr); - reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - break; - } - case 1: { - result.is_err = true; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_flush(reactor_borrow_output_stream_t self, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[12]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_flush((self).__handle, ptr); - reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - break; - } - case 1: { - result.is_err = true; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_flush(reactor_borrow_output_stream_t self, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[12]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_flush((self).__handle, ptr); - reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - break; - } - case 1: { - result.is_err = true; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -reactor_own_pollable_t wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe(reactor_borrow_output_stream_t self) { - int32_t ret = __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe((self).__handle); - return (reactor_own_pollable_t) { ret }; -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write_zeroes(reactor_borrow_output_stream_t self, uint64_t len, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[12]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write_zeroes((self).__handle, (int64_t) (len), ptr); - reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - break; - } - case 1: { - result.is_err = true; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_zeroes_and_flush(reactor_borrow_output_stream_t self, uint64_t len, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[12]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_zeroes_and_flush((self).__handle, (int64_t) (len), ptr); - reactor_result_void_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - break; - } - case 1: { - result.is_err = true; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 8)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_splice(reactor_borrow_output_stream_t self, reactor_own_input_stream_t src, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_splice((self).__handle, (src).__handle, (int64_t) (len), ptr); - reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_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; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 12)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - *ret = result.val.ok; - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_splice(reactor_borrow_output_stream_t self, reactor_own_input_stream_t src, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_splice((self).__handle, (src).__handle, (int64_t) (len), ptr); - reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_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; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 12)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - *ret = result.val.ok; - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_forward(reactor_borrow_output_stream_t self, reactor_own_input_stream_t src, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_forward((self).__handle, (src).__handle, ptr); - reactor_result_u64_wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_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; - wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 8))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.last_operation_failed = (reactor_own_error_t) { *((int32_t*) (ptr + 12)) }; - break; - } - case 1: { - break; - } - } - - result.val.err = variant; - break; - } - } - if (!result.is_err) { - *ret = result.val.ok; - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_via_stream(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, reactor_own_input_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_via_stream((self).__handle, (int64_t) (offset), ptr); - reactor_result_own_input_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_own_input_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write_via_stream(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, reactor_own_output_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write_via_stream((self).__handle, (int64_t) (offset), ptr); - reactor_result_own_output_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_own_output_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_append_via_stream(reactor_borrow_descriptor_t self, reactor_own_output_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_append_via_stream((self).__handle, ptr); - reactor_result_own_output_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_own_output_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_advise(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t length, wasi_filesystem_0_2_0_rc_2023_10_18_types_advice_t advice, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_advise((self).__handle, (int64_t) (offset), (int64_t) (length), (int32_t) advice, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync_data(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync_data((self).__handle, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_flags(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_flags((self).__handle, ptr); - reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_type(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_type((self).__handle, ptr); - reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_size(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t size, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_size((self).__handle, (int64_t) (size), ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_access_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_modification_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t variant; - int64_t variant2; - int32_t variant3; - switch ((int32_t) (*data_access_timestamp).tag) { - case 0: { - variant = 0; - variant2 = 0; - variant3 = 0; - break; - } - case 1: { - variant = 1; - variant2 = 0; - variant3 = 0; - break; - } - case 2: { - const wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t *payload1 = &(*data_access_timestamp).val.timestamp; - variant = 2; - variant2 = (int64_t) ((*payload1).seconds); - variant3 = (int32_t) ((*payload1).nanoseconds); - break; - } - } - int32_t variant7; - int64_t variant8; - int32_t variant9; - switch ((int32_t) (*data_modification_timestamp).tag) { - case 0: { - variant7 = 0; - variant8 = 0; - variant9 = 0; - break; - } - case 1: { - variant7 = 1; - variant8 = 0; - variant9 = 0; - break; - } - case 2: { - const wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t *payload6 = &(*data_modification_timestamp).val.timestamp; - variant7 = 2; - variant8 = (int64_t) ((*payload6).seconds); - variant9 = (int32_t) ((*payload6).nanoseconds); - break; - } - } - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times((self).__handle, variant, variant2, variant3, variant7, variant8, variant9, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t length, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, reactor_tuple2_list_u8_bool_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read((self).__handle, (int64_t) (length), (int64_t) (offset), ptr); - reactor_result_tuple2_list_u8_bool_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_tuple2_list_u8_bool_t) { - (reactor_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }, - (int32_t) (*((uint8_t*) (ptr + 12))), - }; - 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write(reactor_borrow_descriptor_t self, reactor_list_u8_t *buffer, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write((self).__handle, (int32_t) (*buffer).ptr, (int32_t) (*buffer).len, (int64_t) (offset), ptr); - reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_directory(reactor_borrow_descriptor_t self, reactor_own_directory_entry_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_directory((self).__handle, ptr); - reactor_result_own_directory_entry_stream_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_own_directory_entry_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync((self).__handle, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_create_directory_at(reactor_borrow_descriptor_t self, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_create_directory_at((self).__handle, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[104]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat((self).__handle, ptr); - reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t option; - switch ((int32_t) (*((uint8_t*) (ptr + 32)))) { - case 0: { - option.is_some = false; - break; - } - case 1: { - option.is_some = true; - option.val = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { - (uint64_t) (*((int64_t*) (ptr + 40))), - (uint32_t) (*((int32_t*) (ptr + 48))), - }; - break; - } - } - reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t option0; - switch ((int32_t) (*((uint8_t*) (ptr + 56)))) { - case 0: { - option0.is_some = false; - break; - } - case 1: { - option0.is_some = true; - option0.val = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { - (uint64_t) (*((int64_t*) (ptr + 64))), - (uint32_t) (*((int32_t*) (ptr + 72))), - }; - break; - } - } - reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t option1; - switch ((int32_t) (*((uint8_t*) (ptr + 80)))) { - case 0: { - option1.is_some = false; - break; - } - case 1: { - option1.is_some = true; - option1.val = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { - (uint64_t) (*((int64_t*) (ptr + 88))), - (uint32_t) (*((int32_t*) (ptr + 96))), - }; - break; - } - } - - result.val.ok = (wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t) { - (int32_t) (*((uint8_t*) (ptr + 8))), - (uint64_t) (*((int64_t*) (ptr + 16))), - (uint64_t) (*((int64_t*) (ptr + 24))), - option, - option0, - option1, - }; - 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[104]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); - reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t option; - switch ((int32_t) (*((uint8_t*) (ptr + 32)))) { - case 0: { - option.is_some = false; - break; - } - case 1: { - option.is_some = true; - option.val = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { - (uint64_t) (*((int64_t*) (ptr + 40))), - (uint32_t) (*((int32_t*) (ptr + 48))), - }; - break; - } - } - reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t option0; - switch ((int32_t) (*((uint8_t*) (ptr + 56)))) { - case 0: { - option0.is_some = false; - break; - } - case 1: { - option0.is_some = true; - option0.val = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { - (uint64_t) (*((int64_t*) (ptr + 64))), - (uint32_t) (*((int32_t*) (ptr + 72))), - }; - break; - } - } - reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t option1; - switch ((int32_t) (*((uint8_t*) (ptr + 80)))) { - case 0: { - option1.is_some = false; - break; - } - case 1: { - option1.is_some = true; - option1.val = (wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t) { - (uint64_t) (*((int64_t*) (ptr + 88))), - (uint32_t) (*((int32_t*) (ptr + 96))), - }; - break; - } - } - - result.val.ok = (wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t) { - (int32_t) (*((uint8_t*) (ptr + 8))), - (uint64_t) (*((int64_t*) (ptr + 16))), - (uint64_t) (*((int64_t*) (ptr + 24))), - option, - option0, - option1, - }; - 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_access_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_modification_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t variant; - int64_t variant2; - int32_t variant3; - switch ((int32_t) (*data_access_timestamp).tag) { - case 0: { - variant = 0; - variant2 = 0; - variant3 = 0; - break; - } - case 1: { - variant = 1; - variant2 = 0; - variant3 = 0; - break; - } - case 2: { - const wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t *payload1 = &(*data_access_timestamp).val.timestamp; - variant = 2; - variant2 = (int64_t) ((*payload1).seconds); - variant3 = (int32_t) ((*payload1).nanoseconds); - break; - } - } - int32_t variant7; - int64_t variant8; - int32_t variant9; - switch ((int32_t) (*data_modification_timestamp).tag) { - case 0: { - variant7 = 0; - variant8 = 0; - variant9 = 0; - break; - } - case 1: { - variant7 = 1; - variant8 = 0; - variant9 = 0; - break; - } - case 2: { - const wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t *payload6 = &(*data_modification_timestamp).val.timestamp; - variant7 = 2; - variant8 = (int64_t) ((*payload6).seconds); - variant9 = (int32_t) ((*payload6).nanoseconds); - break; - } - } - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, variant, variant2, variant3, variant7, variant8, variant9, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_link_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t old_path_flags, reactor_string_t *old_path, reactor_borrow_descriptor_t new_descriptor, reactor_string_t *new_path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_link_at((self).__handle, old_path_flags, (int32_t) (*old_path).ptr, (int32_t) (*old_path).len, (new_descriptor).__handle, (int32_t) (*new_path).ptr, (int32_t) (*new_path).len, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_open_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_open_flags_t open_flags, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_t flags, wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t modes, reactor_own_descriptor_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_open_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, open_flags, flags, modes, ptr); - reactor_result_own_descriptor_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_own_descriptor_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_readlink_at(reactor_borrow_descriptor_t self, reactor_string_t *path, reactor_string_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[12]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_readlink_at((self).__handle, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); - reactor_result_string_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_string_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_remove_directory_at(reactor_borrow_descriptor_t self, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_remove_directory_at((self).__handle, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_rename_at(reactor_borrow_descriptor_t self, reactor_string_t *old_path, reactor_borrow_descriptor_t new_descriptor, reactor_string_t *new_path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_rename_at((self).__handle, (int32_t) (*old_path).ptr, (int32_t) (*old_path).len, (new_descriptor).__handle, (int32_t) (*new_path).ptr, (int32_t) (*new_path).len, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_symlink_at(reactor_borrow_descriptor_t self, reactor_string_t *old_path, reactor_string_t *new_path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_symlink_at((self).__handle, (int32_t) (*old_path).ptr, (int32_t) (*old_path).len, (int32_t) (*new_path).ptr, (int32_t) (*new_path).len, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_access_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_access_type_t *type, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t variant; - int32_t variant1; - switch ((int32_t) (*type).tag) { - case 0: { - const wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t *payload = &(*type).val.access; - variant = 0; - variant1 = *payload; - break; - } - case 1: { - variant = 1; - variant1 = 0; - break; - } - } - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_access_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, variant, variant1, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlink_file_at(reactor_borrow_descriptor_t self, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlink_file_at((self).__handle, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_file_permissions_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t modes, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_file_permissions_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, modes, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_directory_permissions_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t modes, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_directory_permissions_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, modes, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_shared(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_shared((self).__handle, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_exclusive(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_exclusive((self).__handle, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_shared(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_shared((self).__handle, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_exclusive(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_exclusive((self).__handle, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlock(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlock((self).__handle, ptr); - reactor_result_void_wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_is_same_object(reactor_borrow_descriptor_t self, reactor_borrow_descriptor_t other) { - int32_t ret = __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_is_same_object((self).__handle, (other).__handle); - return ret; -} - -bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[24]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash((self).__handle, ptr); - reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t) { - (uint64_t) (*((int64_t*) (ptr + 8))), - (uint64_t) (*((int64_t*) (ptr + 16))), - }; - 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[24]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash_at((self).__handle, path_flags, (int32_t) (*path).ptr, (int32_t) (*path).len, ptr); - reactor_result_wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t) { - (uint64_t) (*((int64_t*) (ptr + 8))), - (uint64_t) (*((int64_t*) (ptr + 16))), - }; - 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_directory_entry_stream_read_directory_entry(reactor_borrow_directory_entry_stream_t self, reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[20]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_method_directory_entry_stream_read_directory_entry((self).__handle, ptr); - reactor_result_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t option; - switch ((int32_t) (*((uint8_t*) (ptr + 4)))) { - case 0: { - option.is_some = false; - break; - } - case 1: { - option.is_some = true; - option.val = (wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t) { - (int32_t) (*((uint8_t*) (ptr + 8))), - (reactor_string_t) { (uint8_t*)(*((int32_t*) (ptr + 12))), (size_t)(*((int32_t*) (ptr + 16))) }, - }; - break; - } - } - - result.val.ok = option; - 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_filesystem_error_code(reactor_borrow_error_t err, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *ret) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_types_filesystem_error_code((err).__handle, ptr); - reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t option; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - option.is_some = false; - break; - } - case 1: { - option.is_some = true; - option.val = (int32_t) (*((uint8_t*) (ptr + 1))); - break; - } - } - *ret = option.val; - return option.is_some; -} - -void wasi_filesystem_0_2_0_rc_2023_10_18_preopens_get_directories(reactor_list_tuple2_own_descriptor_string_t *ret) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_filesystem_0_2_0_rc_2023_10_18_preopens_get_directories(ptr); - *ret = (reactor_list_tuple2_own_descriptor_string_t) { (reactor_tuple2_own_descriptor_string_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; -} - -reactor_own_network_t wasi_sockets_0_2_0_rc_2023_10_18_instance_network_instance_network(void) { - int32_t ret = __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_instance_network_instance_network(); - return (reactor_own_network_t) { ret }; -} - -bool wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_addresses(reactor_borrow_network_t network, reactor_string_t *name, wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t *maybe_address_family, bool include_unavailable, reactor_own_resolve_address_stream_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t address_family; - address_family.is_some = maybe_address_family != NULL;if (maybe_address_family) { - address_family.val = *maybe_address_family; - } - int32_t option; - int32_t option1; - if ((address_family).is_some) { - const wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t *payload0 = &(address_family).val; - option = 1; - option1 = (int32_t) *payload0; - } else { - option = 0; - option1 = 0; - } - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_addresses((network).__handle, (int32_t) (*name).ptr, (int32_t) (*name).len, option, option1, include_unavailable, ptr); - reactor_result_own_resolve_address_stream_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_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 wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_resolve_next_address(reactor_borrow_resolve_address_stream_t self, reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t *err) { - __attribute__((__aligned__(2))) - uint8_t ret_area[22]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_resolve_next_address((self).__handle, ptr); - reactor_result_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t option; - switch ((int32_t) (*((uint8_t*) (ptr + 2)))) { - case 0: { - option.is_some = false; - break; - } - case 1: { - option.is_some = true; - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.ipv4 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t) { - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 6)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 7)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 8)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 9)))), - }; - break; - } - case 1: { - variant.val.ipv6 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 6)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 10)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 12)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 14)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), - }; - break; - } - } - - option.val = variant; - break; - } - } - - result.val.ok = option; - break; - } - case 1: { - result.is_err = true; - result.val.err = (int32_t) (*((uint8_t*) (ptr + 2))); - break; - } - } - if (!result.is_err) { - *ret = result.val.ok; - return 1; - } else { - *err = result.val.err; - return 0; - } -} - -reactor_own_pollable_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_subscribe(reactor_borrow_resolve_address_stream_t self) { - int32_t ret = __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_subscribe((self).__handle); - return (reactor_own_pollable_t) { ret }; -} - -bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_bind(reactor_borrow_tcp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *local_address, wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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; - } - } - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_bind((self).__handle, (network).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_bind(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_bind((self).__handle, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_connect(reactor_borrow_tcp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *remote_address, wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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; - } - } - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_connect((self).__handle, (network).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_connect(reactor_borrow_tcp_socket_t self, reactor_tuple2_own_input_stream_own_output_stream_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[12]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_connect((self).__handle, ptr); - reactor_result_tuple2_own_input_stream_own_output_stream_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_tuple2_own_input_stream_own_output_stream_t) { - (reactor_own_input_stream_t) { *((int32_t*) (ptr + 4)) }, - (reactor_own_output_stream_t) { *((int32_t*) (ptr + 8)) }, - }; - 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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_listen(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_listen((self).__handle, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_listen(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_listen((self).__handle, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_accept(reactor_borrow_tcp_socket_t self, reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_accept((self).__handle, ptr); - reactor_result_tuple3_own_tcp_socket_own_input_stream_own_output_stream_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t) { - (reactor_own_tcp_socket_t) { *((int32_t*) (ptr + 4)) }, - (reactor_own_input_stream_t) { *((int32_t*) (ptr + 8)) }, - (reactor_own_output_stream_t) { *((int32_t*) (ptr + 12)) }, - }; - 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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_local_address(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[36]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_local_address((self).__handle, ptr); - reactor_result_wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.ipv4 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_socket_address_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), - (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t) { - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 10)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 11)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 12)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 13)))), - }, - }; - break; - } - case 1: { - variant.val.ipv6 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_socket_address_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), - (uint32_t) (*((int32_t*) (ptr + 12))), - (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 22)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 24)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 26)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 28)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 30)))), - }, - (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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_remote_address(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[36]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_remote_address((self).__handle, ptr); - reactor_result_wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.ipv4 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_socket_address_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), - (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t) { - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 10)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 11)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 12)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 13)))), - }, - }; - break; - } - case 1: { - variant.val.ipv6 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_socket_address_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), - (uint32_t) (*((int32_t*) (ptr + 12))), - (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 22)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 24)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 26)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 28)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 30)))), - }, - (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; - } -} - -wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(reactor_borrow_tcp_socket_t self) { - int32_t ret = __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family((self).__handle); - return ret; -} - -bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_ipv6_only(reactor_borrow_tcp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_ipv6_only((self).__handle, ptr); - reactor_result_bool_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_ipv6_only(reactor_borrow_tcp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_ipv6_only((self).__handle, value, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_listen_backlog_size(reactor_borrow_tcp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_listen_backlog_size((self).__handle, (int64_t) (value), ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_keep_alive(reactor_borrow_tcp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_keep_alive((self).__handle, ptr); - reactor_result_bool_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_keep_alive(reactor_borrow_tcp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_keep_alive((self).__handle, value, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_no_delay(reactor_borrow_tcp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_no_delay((self).__handle, ptr); - reactor_result_bool_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_no_delay(reactor_borrow_tcp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_no_delay((self).__handle, value, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_unicast_hop_limit(reactor_borrow_tcp_socket_t self, uint8_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_unicast_hop_limit((self).__handle, ptr); - reactor_result_u8_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_unicast_hop_limit(reactor_borrow_tcp_socket_t self, uint8_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_unicast_hop_limit((self).__handle, (int32_t) (value), ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_receive_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_receive_buffer_size((self).__handle, ptr); - reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_receive_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_receive_buffer_size((self).__handle, (int64_t) (value), ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_send_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_send_buffer_size((self).__handle, ptr); - reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_send_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_send_buffer_size((self).__handle, (int64_t) (value), ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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; - } -} - -reactor_own_pollable_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(reactor_borrow_tcp_socket_t self) { - int32_t ret = __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe((self).__handle); - return (reactor_own_pollable_t) { ret }; -} - -bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_shutdown(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_shutdown_type_t shutdown_type, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_shutdown((self).__handle, (int32_t) shutdown_type, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_create_tcp_socket(wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_ip_address_family_t address_family, reactor_own_tcp_socket_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_create_tcp_socket((int32_t) address_family, ptr); - reactor_result_own_tcp_socket_wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_bind(reactor_borrow_udp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *local_address, wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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; - } - } - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_bind((self).__handle, (network).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_bind(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_bind((self).__handle, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_connect(reactor_borrow_udp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *remote_address, wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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 wasi_sockets_0_2_0_rc_2023_10_18_network_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; - } - } - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_connect((self).__handle, (network).__handle, variant, variant1, variant2, variant3, variant4, variant5, variant6, variant7, variant8, variant9, variant10, variant11, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_connect(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_connect((self).__handle, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive(reactor_borrow_udp_socket_t self, uint64_t max_results, reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[12]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive((self).__handle, (int64_t) (max_results), ptr); - reactor_result_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t) { (wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - 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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send(reactor_borrow_udp_socket_t self, reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *datagrams, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send((self).__handle, (int32_t) (*datagrams).ptr, (int32_t) (*datagrams).len, ptr); - reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_local_address(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[36]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_local_address((self).__handle, ptr); - reactor_result_wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.ipv4 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_socket_address_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), - (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t) { - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 10)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 11)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 12)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 13)))), - }, - }; - break; - } - case 1: { - variant.val.ipv6 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_socket_address_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), - (uint32_t) (*((int32_t*) (ptr + 12))), - (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 22)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 24)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 26)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 28)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 30)))), - }, - (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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_remote_address(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[36]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_remote_address((self).__handle, ptr); - reactor_result_wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t variant; - variant.tag = (int32_t) (*((uint8_t*) (ptr + 4))); - switch ((int32_t) variant.tag) { - case 0: { - variant.val.ipv4 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_socket_address_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), - (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t) { - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 10)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 11)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 12)))), - (uint8_t) ((int32_t) (*((uint8_t*) (ptr + 13)))), - }, - }; - break; - } - case 1: { - variant.val.ipv6 = (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_socket_address_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 8)))), - (uint32_t) (*((int32_t*) (ptr + 12))), - (wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t) { - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 16)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 18)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 20)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 22)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 24)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 26)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 28)))), - (uint16_t) ((int32_t) (*((uint16_t*) (ptr + 30)))), - }, - (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; - } -} - -wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_address_family(reactor_borrow_udp_socket_t self) { - int32_t ret = __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_address_family((self).__handle); - return ret; -} - -bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_ipv6_only(reactor_borrow_udp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_ipv6_only((self).__handle, ptr); - reactor_result_bool_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_ipv6_only(reactor_borrow_udp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_ipv6_only((self).__handle, value, ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_unicast_hop_limit(reactor_borrow_udp_socket_t self, uint8_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_unicast_hop_limit((self).__handle, ptr); - reactor_result_u8_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_unicast_hop_limit(reactor_borrow_udp_socket_t self, uint8_t value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_unicast_hop_limit((self).__handle, (int32_t) (value), ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive_buffer_size(reactor_borrow_udp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive_buffer_size((self).__handle, ptr); - reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_receive_buffer_size(reactor_borrow_udp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_receive_buffer_size((self).__handle, (int64_t) (value), ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send_buffer_size(reactor_borrow_udp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send_buffer_size((self).__handle, ptr); - reactor_result_u64_wasi_sockets_0_2_0_rc_2023_10_18_udp_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_send_buffer_size(reactor_borrow_udp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_send_buffer_size((self).__handle, (int64_t) (value), ptr); - reactor_result_void_wasi_sockets_0_2_0_rc_2023_10_18_udp_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; - } -} - -reactor_own_pollable_t wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_subscribe(reactor_borrow_udp_socket_t self) { - int32_t ret = __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_subscribe((self).__handle); - return (reactor_own_pollable_t) { ret }; -} - -bool wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_create_udp_socket(wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_ip_address_family_t address_family, reactor_own_udp_socket_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_error_code_t *err) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_create_udp_socket((int32_t) address_family, ptr); - reactor_result_own_udp_socket_wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_error_code_t result; - switch ((int32_t) (*((uint8_t*) (ptr + 0)))) { - case 0: { - result.is_err = false; - result.val.ok = (reactor_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; - } -} - -void wasi_random_0_2_0_rc_2023_10_18_random_get_random_bytes(uint64_t len, reactor_list_u8_t *ret) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_random_0_2_0_rc_2023_10_18_random_get_random_bytes((int64_t) (len), ptr); - *ret = (reactor_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; -} - -uint64_t wasi_random_0_2_0_rc_2023_10_18_random_get_random_u64(void) { - int64_t ret = __wasm_import_wasi_random_0_2_0_rc_2023_10_18_random_get_random_u64(); - return (uint64_t) (ret); -} - -void wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_bytes(uint64_t len, reactor_list_u8_t *ret) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_bytes((int64_t) (len), ptr); - *ret = (reactor_list_u8_t) { (uint8_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; -} - -uint64_t wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_u64(void) { - int64_t ret = __wasm_import_wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_u64(); - return (uint64_t) (ret); -} - -void wasi_random_0_2_0_rc_2023_10_18_insecure_seed_insecure_seed(reactor_tuple2_u64_u64_t *ret) { - __attribute__((__aligned__(8))) - uint8_t ret_area[16]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_random_0_2_0_rc_2023_10_18_insecure_seed_insecure_seed(ptr); - *ret = (reactor_tuple2_u64_u64_t) { - (uint64_t) (*((int64_t*) (ptr + 0))), - (uint64_t) (*((int64_t*) (ptr + 8))), - }; -} - -void wasi_cli_0_2_0_rc_2023_10_18_environment_get_environment(reactor_list_tuple2_string_string_t *ret) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_environment_get_environment(ptr); - *ret = (reactor_list_tuple2_string_string_t) { (reactor_tuple2_string_string_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; -} - -void wasi_cli_0_2_0_rc_2023_10_18_environment_get_arguments(reactor_list_string_t *ret) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_environment_get_arguments(ptr); - *ret = (reactor_list_string_t) { (reactor_string_t*)(*((int32_t*) (ptr + 0))), (size_t)(*((int32_t*) (ptr + 4))) }; -} - -bool wasi_cli_0_2_0_rc_2023_10_18_environment_initial_cwd(reactor_string_t *ret) { - __attribute__((__aligned__(4))) - uint8_t ret_area[12]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_environment_initial_cwd(ptr); - reactor_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 = (reactor_string_t) { (uint8_t*)(*((int32_t*) (ptr + 4))), (size_t)(*((int32_t*) (ptr + 8))) }; - break; - } - } - *ret = option.val; - return option.is_some; -} - -void wasi_cli_0_2_0_rc_2023_10_18_exit_exit(reactor_result_void_void_t *status) { - int32_t result; - if ((*status).is_err) { - result = 1; - } else { - result = 0; - } - __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_exit_exit(result); -} - -reactor_own_input_stream_t wasi_cli_0_2_0_rc_2023_10_18_stdin_get_stdin(void) { - int32_t ret = __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_stdin_get_stdin(); - return (reactor_own_input_stream_t) { ret }; -} - -reactor_own_output_stream_t wasi_cli_0_2_0_rc_2023_10_18_stdout_get_stdout(void) { - int32_t ret = __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_stdout_get_stdout(); - return (reactor_own_output_stream_t) { ret }; -} - -reactor_own_output_stream_t wasi_cli_0_2_0_rc_2023_10_18_stderr_get_stderr(void) { - int32_t ret = __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_stderr_get_stderr(); - return (reactor_own_output_stream_t) { ret }; -} - -bool wasi_cli_0_2_0_rc_2023_10_18_terminal_stdin_get_terminal_stdin(reactor_own_terminal_input_t *ret) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_stdin_get_terminal_stdin(ptr); - reactor_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 = (reactor_own_terminal_input_t) { *((int32_t*) (ptr + 4)) }; - break; - } - } - *ret = option.val; - return option.is_some; -} - -bool wasi_cli_0_2_0_rc_2023_10_18_terminal_stdout_get_terminal_stdout(reactor_own_terminal_output_t *ret) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_stdout_get_terminal_stdout(ptr); - reactor_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 = (reactor_own_terminal_output_t) { *((int32_t*) (ptr + 4)) }; - break; - } - } - *ret = option.val; - return option.is_some; -} - -bool wasi_cli_0_2_0_rc_2023_10_18_terminal_stderr_get_terminal_stderr(reactor_own_terminal_output_t *ret) { - __attribute__((__aligned__(4))) - uint8_t ret_area[8]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_cli_0_2_0_rc_2023_10_18_terminal_stderr_get_terminal_stderr(ptr); - reactor_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 = (reactor_own_terminal_output_t) { *((int32_t*) (ptr + 4)) }; - break; - } - } - *ret = option.val; - return option.is_some; -} - -extern void __component_type_object_force_link_reactor(void); -void __component_type_object_force_link_reactor_public_use_in_this_compilation_unit(void) { - __component_type_object_force_link_reactor(); -} diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor_component_type.o b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/reactor_component_type.o deleted file mode 100644 index b1658060910f85d92580c9c92b7b2f4a05bdf095..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 38549 zcmeHQdym{ka_<^)=dq93m!#GEX=!cQ96kJq>^tAd>o~a}mz1$DQHsP&-48 zNRCD$Ls9a5@&ytgKoI1GJ0wAZyWsNtD#@?9$!2qgvyN=T&K>AKtl4IFb#--hRdscB zmvG}D2_eX)9}8jCNG#h_6D#5`{_@kFtS7={Uy+NO^|5( z&k=o4qYr*SdrK768nM?6gI+vY3EUt||CrjM*>e*w@rRy;{_b<1!V1C()oigGd2u)x zCw>@E&7zwVH}>D_4#MtHd~4zk29ErF|90nY=e84dox8X1zUkb#?cBMyBxtV**rRYT zaQ6qEMbsBGA{tHUKGpo7CM;XD__H(c;{*eh#Y7@)#xItox8jlnG%W>MpaoXe)-LKh`z86?ccV7~~dm)y9Zam(P zyOF=|QQaa?Ag9JK48kM~{O&O%v4CezZP17DMDK+Oh^*yt(sjavgV;-+*?~Ls;vGM5 zdhT@KANCU`cAxmcp~DmQ!WJ9+?=z6f>G|NMcVs#70^!37i%`!-(@vn8>f1 zW64045_^gEoD%xlV#$jla3PUjqsO(A12;~baO6cUbB}Z2`U9^=mZ*beVy`DK&8u+& zjvYFxp#UXT{a`f45M{XqMqCTWiCIE@OdZ*=H#lgD*cKN)9ePPW>^+b$I!WmCy#4VZ zLjaMeMg2OBp3@^*p(UPFZn$g>ykH_$ZE+@RZFbuMPCZ()#nsZU`^^130je56Pv$_k z7lDqC{1L5xE@)Lv@}U~*ve>Z2#Zr87mfWO%BO}h101j8O1_dH^x_z&E4-d?plX^T$zcTFK#(Q$*Gb1)dkeL9(Aw-~yrdde2Bd=B)q zVh$4|x>VjKr_oNv1Y3#;fQO#uB9#>K&%7w~VmfV$x647#3|7@Q#(bLmI^DM<<84`S z)IFm*#`K&ohlo||cRf05i|geTbeCDpd`t|VXI?Lh;+PJ?XyQgaI%mzIuJXVZT`@la4*W&4LKLlx^Zi1uL z$U7Vl+{j_b^%zUqOKh>;^H{u(&`7FQODt1Rw|S*6Nq*So>W+^!a){+Kb>eBz-G=&f zXUa}Q-s7w~!N5I?EwM@gwSg;R=^Q}ig&@H4$W8iK zMY2Yl0=wP?Qi+$3vE@DOVv+ezyk-)OgDyUz8RRcSuWGhIP-i?8R>w^q4*yv8o_by2 zg`b#*VF-jQu>}EMce`CLj%i!ey{AynF-z3zNKi zz)Ku&I7+7L{0qz-K7rZ?N3DzjZZrxbAYVrpNiuEYpLpEuXBcqR1Ms*632R~KC#YcB$6y6?Mj-vM%C)Vzl7b0%Q(<hPlRFDsyO8+%0c$=z%j> z+|iq8v0}D(%dlsRKDY%-D|%Z`gOXK@y*7Z12C&NInxc0ywZ2;}*3KU%*3L8d(lIkW zEd1!#*l-PN_g-Km@A62L5wWYuoN>#0w%93|YF<6`Ei`VKjrXy`_!NuGnAZh?(`$w zX*-0H$<_XPGy6Mkv;N8f>^AvtP06w$Nfiy~zd`a8ytoMAO=F3HujrVN8^ z@%Ia8ChZJ#@LPZ$^Yo~lRyM&uK{LI3$uXA#EyL}%%b6g84tiqPOo|CI(er;LO4&+_ zJgF6d_4hTK=eVEk_Rx*7+PK+z_1?&21DRXg*|%4U@f2`7d%j{W|f@=?hu+G6Ee zdKYF;7?zi`N(^9nOH@{^08sDkjhY}Pa5DtZQke9;Xjj0IqBqM%eHd9WTTbErBkUyT zV{rE?rttY^@b%>q!WFCo`hCq_^V}gAM46&4fZ#d$A@y(2(M6!}bGdw#Cj6NY{|X3i zY9xw=YicPd%ORgfY4g!1)L)__R;m_^re6s0Z-8`?`6HfU>yr9qq$x#zXwhqO$C!V< z#cH#B-v|esSTal@+H3I6Zl!1+3Be{%SgXY}ve+Sqo!>g^;|x(BS`faeH)cB?MIH;B z^1fGTZxddxz)L1!bOd+Q@MN}MTuWD5&kKC7CoN8Go^E6&Cd~5j5Cr1AD!g#15!_%2 zjgk{^kaWipWJh-j$^-}4P$tssHEnidhp?8xWwqjMu&7qMO_=Ghbx*jx9-H|NTh9A_ zAU9|2tPn6^i*B(D#P(nuK*?ei!?4~$*8y0Pw@Q(BfJ(iMLJ^dTS;yU%Hux4BQ-={; zZh8l@DTN?|hM)5Z!#<0thso|@@u@=WsM&irj=Zxh09@&Lp8Ygqd4udV+aEo7i~skI zEjIm;la1=Y9r^?8sVoZZ=lGA^1*n;Q2kTJS{4D)XeS9bX*udUYLZ-Tqz^MtgUC!ZK zqQx6J-gSJ|Nc*hAWS4!Uv`>pIu|kopsmo+S)M#jVN-t+2#TPG`Fe>OX*;aGtOSb4R( z9(FL2=gG3@j$AWYSF<%r`&{QfjqQ{CGbbzmIX{cEcZPABakkH)D;+)X&l%t?* zEzBKUPBq#pXBc>pPNjU8@q@9UT4vwFBU)v5rV@@T0$yA#8p~TkG&18e@vy5*=at%q z?{!72+v3$sz-HCcnwfyjJ&YUFx9F%v{xXo+W@PMa+BTJcK`(E$5Vo-ChU=!s3*3Ez zg~p5U1^Zt&XF7v8JeeIk=&2n!as|T$a5Ns3PV9Czbw!q>z3(xtU(#DwoN4K>D=?;< zzuB3V2OT`1l64^uYZgrSDh(|hYIQxhwP39VJ$oMt8y=jvKTdk^0H%&8V6dEYvo!~q z-^VO~83gt|>9%Pzn}n@3*Z}ajq!YLzwheb_4x|Hl9VwAaCo+cG}DoGjGnleqOh~?c8>-j4zA#?qZ{QcdE|M}q5~`jdZm2C4A7``-Ed(T z-NMP$^KewiQ1p(}_|8yt9o{fLH>tL3xQUELW1M~RkzYR?Dboh7ts?cFGa0lXHJWmN z^UYsF#}l*To5l{&Xr0OjI0MZNLww_RO0_;kM31(|#xuxl{yF$D&sX+8&ik^}tE!fn`HZ(%$NvqLwE$v*KH7 z?*$@SY5<(p8E|pNOFpaOCc&(y8FjZLaNx6<`gZd1(6U8$XNTdW)s*5Y9n=o(-Q!Ud z^^zP$K`$+~Ko;nwV+|2@&B4ZGb9#A3xI>@vdA>BWVPAqW%$=42 zfb!NdyHI^bW?!|1mf3}RaO2O)_iKjP-xko0T4tLqbqvt;S;>o9r9$d7B=4#r2fjMV z3)VK^zJ%n>2Q)8v`P=79-m@H41~~}#k&LIozITJYH|lgvo@mA-H>o%M0;UbUe5xTxlb%=GGts_*>7B%pgA>z4DCr%277^-50>&G9o151+hW4%UewIlr2|?{{n3|q>d@n53ljl>*T)$${uzZa{<6T5Le#N!^b$`9#+iN4_!W-W6O9NVMFISa zxW*KHh=nv%nQ=@h4% zqH|nlY84WWlJ&vt9C&w($ZHOR1YmzH2YlPuZp}4H*Bs7Zecq?tWiv#Q@}_w6xOU7x zIG3ZhsK3U}$oosFKxwSc4D*e;LcY_|2)>am^|uAiqAnDeQ8RhE`Ve;m@3GJOws$ph z_XL7$wBvWSNk>J?e2e@Ou_u=%sUxN_Da{V@9F4ZFW4s+CnPkG_`-3M8zUe_IF z+wW2zAkW#^8M*yrhjtS5WKzqF@oo|p4f6r(EsvpxLBm0NcMS}O#}TN^|f2zUj%cCUc_^iQ&z!Y{y7!A_w$^bKT~J<8dKd^l2h^6Cv=1X!d1xR zd{-;2Uq};P6SmkgCF~zi|2+9SAklv?i5}5^qU)po(uDeVA^sbL(jkD0WWAKe4>Jxz zE1n;{b6?mhpQs;aMteU=M#n@EybfFP{G8I|!dXqpWear^f6M~Z+iV;`X3jx{HO8Nu zGA%4!hme*Fdq|HmAuKaP0}fCk1RuZ!{D_v}jk;gMIhK^;&CFVAv2(DFsOH|lqg9JK za>F2LqUTS2E#GXc-3)tB-3*hezPcHvuO%uK?o>C!s+(ce&9LfbSamZj zy)9PV46AO2RX4*pe5<+{_Q1GAQQZt1jz0e`pmrG0F zscwd;i_q20u>7$MgGKZOvg&5ogX~h(RNeT`E-nSkDVGpxE9CZBSv zZiZDi!*GhRJ(%)y**V zh-H2q%7|;JZiZDi!>XHMQkhma!_*zo>Sh?5R@Ke0X8D`VTVvsJs;e|^uh|OI?hKBSnt0o$Mc2kDr;zHp!eM9scOx;kW7N}AS z@RLMUYJp)#zw@siZT{6tEns~UHxJ;H7BxI3o@W%{f?`$zE>YJw@XOMvS+e8?xO!gz zkUGWjz+e#!prjXZvpXTuBM#@e2FX`p@ian}+(2I7tCAa3$qlOH26&>ON^St7cvvMj zP)7nrG!ws#Q6)E!*?I74Yn9v}d$wS=1@w+hUsW}R_`APE) z<;zGbAPs>`3Q4_nPUg8Ya*+wa4IG~n5bzUDIPeXTuke&jXNz7`Jf6hQLT0YiEfT9{ z5uVO#{Q0W%r>=i}d1oFFP8E?}(sd!#V7vZyhBcjTaI^j%}I!%k|mFZM@Qq`^d zW3sSTc~bxXr5tE6tx(b;t1cQpy)6~WjY^?FSL=t#xLU3HPn38I=uK? zWfrS4i)CqfaGE3&Y^GdXWfsexsy6QP-VKl)%@QS!^TCELPM@au|hy$uZ0hOd`KP zFG)qVV9?DfvzUJBJ5N!R-J-@j+?;WOs?1_YPFZCZOQ5)AZrDPS#;cTOQcQ2j{YqyR z+l1t885zL7I?0Q>Wd_`rki7Y_{i2!0wo|`vLChMy +#include typedef enum { TCP_SOCKET_STATE_UNBOUND, @@ -18,14 +18,14 @@ typedef struct {} tcp_socket_state_connecting_t; typedef struct {} tcp_socket_state_listening_t; typedef struct { - reactor_own_input_stream_t input; - reactor_own_pollable_t input_pollable; - reactor_own_output_stream_t output; - reactor_own_pollable_t output_pollable; + streams_own_input_stream_t input; + poll_own_pollable_t input_pollable; + streams_own_output_stream_t output; + poll_own_pollable_t output_pollable; } tcp_socket_state_connected_t; typedef struct { - wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t error_code; + network_error_code_t error_code; } tcp_socket_state_connect_failed_t; typedef union { @@ -38,8 +38,8 @@ typedef union { } tcp_socket_state_t; typedef struct { - reactor_own_tcp_socket_t socket; - reactor_own_pollable_t socket_pollable; + tcp_own_tcp_socket_t socket; + poll_own_pollable_t socket_pollable; bool blocking; tcp_socket_state_tag_t state_tag; tcp_socket_state_t state; @@ -49,7 +49,7 @@ typedef struct { typedef struct { - reactor_own_udp_socket_t socket; + udp_own_udp_socket_t socket; bool blocking; } udp_socket_t; diff --git a/libc-bottom-half/headers/private/preview2.h b/libc-bottom-half/headers/private/preview2.h new file mode 100644 index 000000000..fc2b03852 --- /dev/null +++ b/libc-bottom-half/headers/private/preview2.h @@ -0,0 +1,2481 @@ +// Generated by `wit-bindgen` 0.16.0. DO NOT EDIT! +#ifndef __BINDINGS_IMPORTS_H +#define __BINDINGS_IMPORTS_H +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include +#include + +typedef struct { + uint8_t*ptr; + size_t len; +} imports_string_t; + +typedef struct { + imports_string_t f0; + imports_string_t f1; +} environment_tuple2_string_string_t; + +typedef struct { + environment_tuple2_string_string_t *ptr; + size_t len; +} environment_list_tuple2_string_string_t; + +typedef struct { + imports_string_t *ptr; + size_t len; +} environment_list_string_t; + +typedef struct { + bool is_some; + imports_string_t val; +} environment_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; +} poll_list_u32_t; + +typedef io_error_own_error_t streams_own_error_t; + +// An error for input-stream and output-stream operations. +typedef struct { + 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; +} streams_list_u8_t; + +typedef struct { + bool is_err; + union { + streams_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 wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t { + int32_t __handle; +} wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t; + +typedef struct wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input_t { + int32_t __handle; +} wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input_t; + +typedef struct wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t { + int32_t __handle; +} wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t; + +typedef struct wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output_t { + int32_t __handle; +} wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output_t; + +typedef wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_own_terminal_input_t; + +typedef struct { + bool is_some; + wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_own_terminal_input_t val; +} wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_option_own_terminal_input_t; + +typedef wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_own_terminal_output_t; + +typedef struct { + bool is_some; + wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_own_terminal_output_t val; +} wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_option_own_terminal_output_t; + +typedef wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_own_terminal_output_t; + +typedef struct { + bool is_some; + wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_own_terminal_output_t val; +} wasi_cli_0_2_0_rc_2023_11_10_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 { + 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 { + // 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 { + 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 { + // The type of the file referred to by this directory entry. + filesystem_descriptor_type_t type; + // The name of the object. + imports_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 { + // 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 { + uint8_t *ptr; + size_t len; +} filesystem_list_u8_t; + +typedef struct { + filesystem_list_u8_t f0; + bool f1; +} filesystem_tuple2_list_u8_bool_t; + +typedef struct { + bool is_err; + union { + filesystem_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 { + imports_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; + imports_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 connection was forcefully rejected +#define NETWORK_ERROR_CODE_CONNECTION_REFUSED 14 +// The connection was reset. +#define NETWORK_ERROR_CODE_CONNECTION_RESET 15 +// A connection was aborted. +#define NETWORK_ERROR_CODE_CONNECTION_ABORTED 16 +#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 { + uint8_t f0; + uint8_t f1; + uint8_t f2; + uint8_t f3; +} network_ipv4_address_t; + +typedef struct { + 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 { + 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 { + uint16_t port; + network_ipv4_address_t address; +} network_ipv4_socket_address_t; + +typedef struct { + uint16_t port; + uint32_t flow_info; + network_ipv6_address_t address; + uint32_t scope_id; +} network_ipv6_socket_address_t; + +typedef struct { + 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; + +typedef struct { + uint8_t *ptr; + size_t len; +} udp_list_u8_t; + +// A received datagram. +typedef struct { + // The payload. + // + // Theoretical max size: ~64 KiB. In practice, typically less than 1500 bytes. + udp_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 { + // The payload. + udp_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 { + bool ok; + udp_error_code_t err; + } val; +} udp_result_bool_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 { + uint8_t *ptr; + size_t len; +} random_list_u8_t; + +typedef struct { + uint64_t f0; + uint64_t f1; +} random_insecure_seed_tuple2_u64_u64_t; + +// Imported Functions from `wasi:cli/environment@0.2.0-rc-2023-11-10` +// 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(environment_list_tuple2_string_string_t *ret); +// Get the POSIX-style arguments to the program. +extern void environment_get_arguments(environment_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(imports_string_t *ret); + +// Imported Functions from `wasi:cli/exit@0.2.0-rc-2023-11-10` +// Exit the current instance and any linked instances. +extern void exit_exit(exit_result_void_void_t *status); + +// Imported Functions from `wasi:io/error@0.2.0-rc-2023-11-10` +// 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, imports_string_t *ret); + +// Imported Functions from `wasi:io/poll@0.2.0-rc-2023-11-10` +// 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, poll_list_u32_t *ret); + +// Imported Functions from `wasi:io/streams@0.2.0-rc-2023-11-10` +// Perform a non-blocking read from the stream. +// +// 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, streams_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, streams_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. +// +// 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, streams_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, streams_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-rc-2023-11-10` + extern stdin_own_input_stream_t stdin_get_stdin(void); + + // Imported Functions from `wasi:cli/stdout@0.2.0-rc-2023-11-10` + extern stdout_own_output_stream_t stdout_get_stdout(void); + + // Imported Functions from `wasi:cli/stderr@0.2.0-rc-2023-11-10` + extern stderr_own_output_stream_t stderr_get_stderr(void); + + // Imported Functions from `wasi:cli/terminal-stdin@0.2.0-rc-2023-11-10` + // If stdin is connected to a terminal, return a `terminal-input` handle + // allowing further interaction with it. + extern bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_get_terminal_stdin(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_own_terminal_input_t *ret); + + // Imported Functions from `wasi:cli/terminal-stdout@0.2.0-rc-2023-11-10` + // If stdout is connected to a terminal, return a `terminal-output` handle + // allowing further interaction with it. + extern bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_get_terminal_stdout(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_own_terminal_output_t *ret); + + // Imported Functions from `wasi:cli/terminal-stderr@0.2.0-rc-2023-11-10` + // If stderr is connected to a terminal, return a `terminal-output` handle + // allowing further interaction with it. + extern bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_get_terminal_stderr(wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_own_terminal_output_t *ret); + + // Imported Functions from `wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10` + // 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-rc-2023-11-10` + // 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-rc-2023-11-10` + // 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, filesystem_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, filesystem_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, imports_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, imports_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, imports_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, imports_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, imports_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, imports_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, imports_string_t *path, imports_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, imports_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, imports_string_t *old_path, filesystem_borrow_descriptor_t new_descriptor, imports_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, imports_string_t *old_path, imports_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, imports_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, imports_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-rc-2023-11-10` + // 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-rc-2023-11-10` + // 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-rc-2023-11-10` + // 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. + // + // Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + // + // # Typical `start` errors + // - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) + // - `invalid-state`: The socket is already bound. (EINVAL) + // + // # Typical `finish` errors + // - `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) + // + // # 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`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + // - `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); + // Whether IPv4 compatibility (dual-stack) mode is disabled or not. + // + // Equivalent to the IPV6_V6ONLY socket option. + // + // # Typical errors + // - `not-supported`: (get/set) `this` socket is an IPv4 socket. + // - `invalid-state`: (set) The socket is already bound. + // - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) + extern bool udp_method_udp_socket_ipv6_only(udp_borrow_udp_socket_t self, bool *ret, udp_error_code_t *err); + extern bool udp_method_udp_socket_set_ipv6_only(udp_borrow_udp_socket_t self, bool value, udp_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 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`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + // - `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-rc-2023-11-10` + // Create a new UDP socket. + // + // Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX. + // + // 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-rc-2023-11-10` + // 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. + // + // When a socket is not explicitly bound, the first invocation to a listen or connect operation will + // implicitly bind the socket. + // + // Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. + // + // # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL) + // - `invalid-state`: The socket is already bound. (EINVAL) + // + // # Typical `finish` errors + // - `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) + // + // # 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 + // + // POSIX mentions: + // > If connect() fails, the state of the socket is unspecified. Conforming applications should + // > close the file descriptor and create a new socket before attempting to reconnect. + // + // WASI prescribes the following behavior: + // - If `connect` fails because an input/state validation error, the socket should remain usable. + // - If a connection was actually attempted but failed, the socket should become unusable for further network communication. + // Besides `drop`, any method after such a failure may return an error. + // + // # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL, EADDRNOTAVAIL on Illumos) + // - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + // - `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 Connection state. (EISCONN) + // - `invalid-state`: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows) + // + // # Typical `finish` errors + // - `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) + // + // # 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 Listener state. + // + // Unlike POSIX: + // - this function is async. This enables interactive WASI hosts to inject permission prompts. + // - the socket must already be explicitly bound. + // + // # Typical `start` errors + // - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) + // - `invalid-state`: The socket is already in the Connection state. (EISCONN, EINVAL on BSD) + // - `invalid-state`: The socket is already in the Listener state. + // + // # Typical `finish` errors + // - `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) + // + // # 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 Connection state. The following properties are inherited from the listener socket: + // - `address-family` + // - `ipv6-only` + // - `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 Listener 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 listening for new connections. + // + // 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); + // Whether IPv4 compatibility (dual-stack) mode is disabled or not. + // + // Equivalent to the IPV6_V6ONLY socket option. + // + // # Typical errors + // - `invalid-state`: (set) The socket is already bound. + // - `not-supported`: (get/set) `this` socket is an IPv4 socket. + // - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) + extern bool tcp_method_tcp_socket_ipv6_only(tcp_borrow_tcp_socket_t self, bool *ret, tcp_error_code_t *err); + extern bool tcp_method_tcp_socket_set_ipv6_only(tcp_borrow_tcp_socket_t self, bool value, tcp_error_code_t *err); + // 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 already in the Connection 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. + // - `invalid-state`: (set) The socket is already in the Connection state. + // - `invalid-state`: (set) The socket is already in the Listener state. + 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. + // - `invalid-state`: (set) The socket is already in the Connection state. + // - `invalid-state`: (set) The socket is already in the Listener state. + 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 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 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 more data from the peer. All subsequent read + // operations on the `input-stream` associated with this socket will return an End Of Stream indication. + // Any data still in the receive queue at time of calling `shutdown` will be discarded. + // - send: the socket is not expecting to send any more data to the peer. All subsequent write + // operations on the `output-stream` associated with this socket will return an error. + // - both: same effect as receive & send combined. + // + // The shutdown function does not close (drop) the socket. + // + // # Typical errors + // - `invalid-state`: The socket is not in the Connection 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-rc-2023-11-10` + // Create a new TCP socket. + // + // Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. + // + // 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`/`listen`/`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-rc-2023-11-10` + // 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, imports_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-rc-2023-11-10` + // 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, random_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-rc-2023-11-10` + // 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, random_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-rc-2023-11-10` + // 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(random_insecure_seed_tuple2_u64_u64_t *ret); + + // Helper Functions + + void environment_tuple2_string_string_free(environment_tuple2_string_string_t *ptr); + + void environment_list_tuple2_string_string_free(environment_list_tuple2_string_string_t *ptr); + + void environment_list_string_free(environment_list_string_t *ptr); + + void environment_option_string_free(environment_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 void io_error_error_drop_borrow(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 void poll_pollable_drop_borrow(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 poll_list_u32_free(poll_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 void streams_input_stream_drop_borrow(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 void streams_output_stream_drop_borrow(streams_own_output_stream_t handle); + + extern streams_borrow_output_stream_t streams_borrow_output_stream(streams_own_output_stream_t handle); + + void streams_list_u8_free(streams_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 wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop_own(wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t handle); + extern void wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop_borrow(wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t handle); + + extern wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input_t wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input(wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t handle); + + extern void wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop_own(wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t handle); + extern void wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop_borrow(wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t handle); + + extern wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output_t wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output(wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t handle); + + void wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_option_own_terminal_input_free(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_option_own_terminal_input_t *ptr); + + void wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_option_own_terminal_output_free(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_option_own_terminal_output_t *ptr); + + void wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_option_own_terminal_output_free(wasi_cli_0_2_0_rc_2023_11_10_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 void filesystem_descriptor_drop_borrow(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 void filesystem_directory_entry_stream_drop_borrow(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_list_u8_free(filesystem_list_u8_t *ptr); + + void filesystem_tuple2_list_u8_bool_free(filesystem_tuple2_list_u8_bool_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 void network_network_drop_borrow(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_list_u8_free(udp_list_u8_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 void udp_udp_socket_drop_borrow(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 void udp_incoming_datagram_stream_drop_borrow(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 void udp_outgoing_datagram_stream_drop_borrow(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_bool_error_code_free(udp_result_bool_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 void tcp_tcp_socket_drop_borrow(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 void ip_name_lookup_resolve_address_stream_drop_borrow(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); + + void random_list_u8_free(random_list_u8_t *ptr); + + // Transfers ownership of `s` into the string `ret` + void imports_string_set(imports_string_t *ret, char*s); + + // Creates a copy of the input nul-terminate string `s` and + // stores it into the component model string `ret`. + void imports_string_dup(imports_string_t *ret, const char*s); + + // Deallocates the string pointed to by `ret`, deallocating + // the memory behind the string. + void imports_string_free(imports_string_t *ret); + + #ifdef __cplusplus + } + #endif + #endif + \ No newline at end of file diff --git a/libc-bottom-half/headers/private/reactor.h b/libc-bottom-half/headers/private/reactor.h deleted file mode 100644 index d9a432463..000000000 --- a/libc-bottom-half/headers/private/reactor.h +++ /dev/null @@ -1,2043 +0,0 @@ -// Generated by `wit-bindgen` 0.14.0. DO NOT EDIT! -#ifndef __BINDINGS_REACTOR_H -#define __BINDINGS_REACTOR_H -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#include - -typedef struct { - uint8_t*ptr; - size_t len; -} reactor_string_t; - -typedef struct { - int32_t __handle; -} reactor_borrow_pollable_t; - -typedef struct { - reactor_borrow_pollable_t *ptr; - size_t len; -} reactor_list_borrow_pollable_t; - -typedef struct { - uint32_t *ptr; - size_t len; -} reactor_list_u32_t; - -typedef struct { - int32_t __handle; -} reactor_own_error_t; - -// An error for input-stream and output-stream operations. -typedef struct { - uint8_t tag; - union { - reactor_own_error_t last_operation_failed; - } val; -} wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t; - -// The last operation (a write or flush) failed before completion. -// -// More information is available in the `error` payload. -#define WASI_IO_0_2_0_RC_2023_10_18_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 WASI_IO_0_2_0_RC_2023_10_18_STREAMS_STREAM_ERROR_CLOSED 1 - -typedef struct { - int32_t __handle; -} reactor_borrow_error_t; - -typedef struct { - int32_t __handle; -} reactor_borrow_input_stream_t; - -typedef struct { - uint8_t *ptr; - size_t len; -} reactor_list_u8_t; - -typedef struct { - int32_t __handle; -} reactor_borrow_output_stream_t; - -typedef struct { - int32_t __handle; -} reactor_own_pollable_t; - -typedef struct { - int32_t __handle; -} reactor_own_input_stream_t; - -// A timestamp in nanoseconds. -typedef uint64_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t; - -// A time and date in seconds plus nanoseconds. -typedef struct { - uint64_t seconds; - uint32_t nanoseconds; -} wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t; - -typedef wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t wasi_clocks_0_2_0_rc_2023_10_18_timezone_datetime_t; - -// Information useful for displaying the timezone of a specific `datetime`. -// -// This information may vary within a single `timezone` to reflect daylight -// saving time adjustments. -typedef struct { - // The number of seconds difference between UTC time and the local - // time of the timezone. - // - // The returned value will always be less than 86400 which is the - // number of seconds in a day (24*60*60). - // - // In implementations that do not expose an actual time zone, this - // should return 0. - int32_t utc_offset; - // The abbreviated name of the timezone to display to a user. The name - // `UTC` indicates Coordinated Universal Time. Otherwise, this should - // reference local standards for the name of the time zone. - // - // In implementations that do not expose an actual time zone, this - // should be the string `UTC`. - // - // In time zones that do not have an applicable name, a formatted - // representation of the UTC offset may be returned, such as `-04:00`. - reactor_string_t name; - // Whether daylight saving time is active. - // - // In implementations that do not expose an actual time zone, this - // should return false. - bool in_daylight_saving_time; -} wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_t; - -typedef wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t; - -// File size or length of a region within a file. -typedef uint64_t wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_t; - -// The type of the descriptor or file is unknown or is different from -// any of the other types specified. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_UNKNOWN 0 -// The descriptor refers to a block device inode. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_BLOCK_DEVICE 1 -// The descriptor refers to a character device inode. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_CHARACTER_DEVICE 2 -// The descriptor refers to a directory inode. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_DIRECTORY 3 -// The descriptor refers to a named pipe. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_FIFO 4 -// The file refers to a symbolic link inode. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_SYMBOLIC_LINK 5 -// The descriptor refers to a regular file inode. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_REGULAR_FILE 6 -// The descriptor refers to a socket. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_TYPE_SOCKET 7 - -// Descriptor flags. -// -// Note: This was called `fdflags` in earlier versions of WASI. -typedef uint8_t wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_t; - -// Read mode: Data can be read. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_FLAGS_READ (1 << 0) -// Write mode: Data can be written to. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_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 WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_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 WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_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 WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_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 WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_DESCRIPTOR_FLAGS_MUTATE_DIRECTORY (1 << 5) - -// Flags determining the method of how paths are resolved. -typedef uint8_t wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t; - -// As long as the resolved path corresponds to a symbolic link, it is -// expanded. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_PATH_FLAGS_SYMLINK_FOLLOW (1 << 0) - -// Open flags used by `open-at`. -typedef uint8_t wasi_filesystem_0_2_0_rc_2023_10_18_types_open_flags_t; - -// Create file if it does not exist, similar to `O_CREAT` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_OPEN_FLAGS_CREATE (1 << 0) -// Fail if not a directory, similar to `O_DIRECTORY` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_OPEN_FLAGS_DIRECTORY (1 << 1) -// Fail if file already exists, similar to `O_EXCL` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_OPEN_FLAGS_EXCLUSIVE (1 << 2) -// Truncate file to size 0, similar to `O_TRUNC` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_OPEN_FLAGS_TRUNCATE (1 << 3) - -// Permissions mode used by `open-at`, `change-file-permissions-at`, and -// similar. -typedef uint8_t wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t; - -// True if the resource is considered readable by the containing -// filesystem. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_MODES_READABLE (1 << 0) -// True if the resource is considered writable by the containing -// filesystem. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_MODES_WRITABLE (1 << 1) -// True if the resource is considered executable by the containing -// filesystem. This does not apply to directories. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_MODES_EXECUTABLE (1 << 2) - -// Access type used by `access-at`. -typedef struct { - uint8_t tag; - union { - wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t access; - } val; -} wasi_filesystem_0_2_0_rc_2023_10_18_types_access_type_t; - -// Test for readability, writeability, or executability. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ACCESS_TYPE_ACCESS 0 -// Test whether the path exists. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ACCESS_TYPE_EXISTS 1 - -// Number of hard links to an inode. -typedef uint64_t wasi_filesystem_0_2_0_rc_2023_10_18_types_link_count_t; - -typedef struct { - bool is_some; - wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t val; -} reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t; - -// File attributes. -// -// Note: This was called `filestat` in earlier versions of WASI. -typedef struct { - // File type. - wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_t type; - // Number of hard links to the file. - wasi_filesystem_0_2_0_rc_2023_10_18_types_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. - wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t size; - // Last data access timestamp. - // - // If the `option` is none, the platform doesn't maintain an access - // timestamp for this file. - reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_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. - reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_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. - reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t status_change_timestamp; -} wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t; - -// When setting a timestamp, this gives the value to set it to. -typedef struct { - uint8_t tag; - union { - wasi_filesystem_0_2_0_rc_2023_10_18_types_datetime_t timestamp; - } val; -} wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t; - -// Leave the timestamp set to its previous value. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_NEW_TIMESTAMP_NO_CHANGE 0 -// Set the timestamp to the current time of the system clock associated -// with the filesystem. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_NEW_TIMESTAMP_NOW 1 -// Set the timestamp to the given value. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_NEW_TIMESTAMP_TIMESTAMP 2 - -// A directory entry. -typedef struct { - // The type of the file referred to by this directory entry. - wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_t type; - // The name of the object. - reactor_string_t name; -} wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t; - -// Permission denied, similar to `EACCES` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_ACCESS 0 -// Resource unavailable, or operation would block, similar to `EAGAIN` and `EWOULDBLOCK` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_WOULD_BLOCK 1 -// Connection already in progress, similar to `EALREADY` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_ALREADY 2 -// Bad descriptor, similar to `EBADF` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_BAD_DESCRIPTOR 3 -// Device or resource busy, similar to `EBUSY` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_BUSY 4 -// Resource deadlock would occur, similar to `EDEADLK` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_DEADLOCK 5 -// Storage quota exceeded, similar to `EDQUOT` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_QUOTA 6 -// File exists, similar to `EEXIST` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_EXIST 7 -// File too large, similar to `EFBIG` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_FILE_TOO_LARGE 8 -// Illegal byte sequence, similar to `EILSEQ` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE 9 -// Operation in progress, similar to `EINPROGRESS` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_IN_PROGRESS 10 -// Interrupted function, similar to `EINTR` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_INTERRUPTED 11 -// Invalid argument, similar to `EINVAL` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_INVALID 12 -// I/O error, similar to `EIO` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_IO 13 -// Is a directory, similar to `EISDIR` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_IS_DIRECTORY 14 -// Too many levels of symbolic links, similar to `ELOOP` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_LOOP 15 -// Too many links, similar to `EMLINK` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_TOO_MANY_LINKS 16 -// Message too large, similar to `EMSGSIZE` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_MESSAGE_SIZE 17 -// Filename too long, similar to `ENAMETOOLONG` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NAME_TOO_LONG 18 -// No such device, similar to `ENODEV` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NO_DEVICE 19 -// No such file or directory, similar to `ENOENT` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NO_ENTRY 20 -// No locks available, similar to `ENOLCK` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NO_LOCK 21 -// Not enough space, similar to `ENOMEM` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_INSUFFICIENT_MEMORY 22 -// No space left on device, similar to `ENOSPC` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_INSUFFICIENT_SPACE 23 -// Not a directory or a symbolic link to a directory, similar to `ENOTDIR` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NOT_DIRECTORY 24 -// Directory not empty, similar to `ENOTEMPTY` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NOT_EMPTY 25 -// State not recoverable, similar to `ENOTRECOVERABLE` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NOT_RECOVERABLE 26 -// Not supported, similar to `ENOTSUP` and `ENOSYS` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_UNSUPPORTED 27 -// Inappropriate I/O control operation, similar to `ENOTTY` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NO_TTY 28 -// No such device or address, similar to `ENXIO` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NO_SUCH_DEVICE 29 -// Value too large to be stored in data type, similar to `EOVERFLOW` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_OVERFLOW 30 -// Operation not permitted, similar to `EPERM` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_NOT_PERMITTED 31 -// Broken pipe, similar to `EPIPE` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_PIPE 32 -// Read-only file system, similar to `EROFS` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_READ_ONLY 33 -// Invalid seek, similar to `ESPIPE` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_INVALID_SEEK 34 -// Text file busy, similar to `ETXTBSY` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_TEXT_FILE_BUSY 35 -// Cross-device link, similar to `EXDEV` in POSIX. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ERROR_CODE_CROSS_DEVICE 36 - -// File or memory access pattern advisory information. -typedef uint8_t wasi_filesystem_0_2_0_rc_2023_10_18_types_advice_t; - -// The application has no advice to give on its behavior with respect -// to the specified data. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ADVICE_NORMAL 0 -// The application expects to access the specified data sequentially -// from lower offsets to higher offsets. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ADVICE_SEQUENTIAL 1 -// The application expects to access the specified data in a random -// order. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ADVICE_RANDOM 2 -// The application expects to access the specified data in the near -// future. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ADVICE_WILL_NEED 3 -// The application expects that it will not access the specified data -// in the near future. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ADVICE_DONT_NEED 4 -// The application expects to access the specified data once and then -// not reuse it thereafter. -#define WASI_FILESYSTEM_0_2_0_RC_2023_10_18_TYPES_ADVICE_NO_REUSE 5 - -// A 128-bit hash value, split into parts because wasm doesn't have a -// 128-bit integer type. -typedef struct { - // 64 bits of a 128-bit hash value. - uint64_t lower; - // Another 64 bits of a 128-bit hash value. - uint64_t upper; -} wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t; - -typedef struct { - int32_t __handle; -} reactor_borrow_descriptor_t; - -typedef struct { - int32_t __handle; -} reactor_own_output_stream_t; - -typedef struct { - reactor_list_u8_t f0; - bool f1; -} reactor_tuple2_list_u8_bool_t; - -typedef struct { - int32_t __handle; -} reactor_own_directory_entry_stream_t; - -typedef struct { - int32_t __handle; -} reactor_own_descriptor_t; - -typedef struct { - int32_t __handle; -} reactor_borrow_directory_entry_stream_t; - -typedef struct { - bool is_some; - wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t val; -} reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t; - -typedef struct { - reactor_own_descriptor_t f0; - reactor_string_t f1; -} reactor_tuple2_own_descriptor_string_t; - -typedef struct { - reactor_tuple2_own_descriptor_string_t *ptr; - size_t len; -} reactor_list_tuple2_own_descriptor_string_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 wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t; - -// Unknown error -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_UNKNOWN 0 -// Access denied. -// -// POSIX equivalent: EACCES, EPERM -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_ACCESS_DENIED 1 -// The operation is not supported. -// -// POSIX equivalent: EOPNOTSUPP -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NOT_SUPPORTED 2 -// One of the arguments is invalid. -// -// POSIX equivalent: EINVAL -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_INVALID_ARGUMENT 3 -// Not enough memory to complete the operation. -// -// POSIX equivalent: ENOMEM, ENOBUFS, EAI_MEMORY -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_OUT_OF_MEMORY 4 -// The operation timed out before it could finish completely. -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_TIMEOUT 5 -// This operation is incompatible with another asynchronous operation that is already in progress. -// -// POSIX equivalent: EALREADY -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_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 WASI_SOCKETS_0_2_0_RC_2023_10_18_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 WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_WOULD_BLOCK 8 -// The operation is not valid in the socket's current state. -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_INVALID_STATE 9 -// A new socket resource could not be created because of a system limit. -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_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 WASI_SOCKETS_0_2_0_RC_2023_10_18_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 WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_ADDRESS_IN_USE 12 -// The remote address is not reachable -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_REMOTE_UNREACHABLE 13 -// The connection was forcefully rejected -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONNECTION_REFUSED 14 -// The connection was reset. -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONNECTION_RESET 15 -// A connection was aborted. -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_CONNECTION_ABORTED 16 -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_DATAGRAM_TOO_LARGE 17 -// Name does not exist or has no suitable associated IP addresses. -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_NAME_UNRESOLVABLE 18 -// A temporary failure in name resolution occurred. -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE 19 -// A permanent failure in name resolution occurred. -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE 20 - -typedef uint8_t wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t; - -// Similar to `AF_INET` in POSIX. -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV4 0 -// Similar to `AF_INET6` in POSIX. -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_FAMILY_IPV6 1 - -typedef struct { - uint8_t f0; - uint8_t f1; - uint8_t f2; - uint8_t f3; -} wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t; - -typedef struct { - uint16_t f0; - uint16_t f1; - uint16_t f2; - uint16_t f3; - uint16_t f4; - uint16_t f5; - uint16_t f6; - uint16_t f7; -} wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t; - -typedef struct { - uint8_t tag; - union { - wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t ipv4; - wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t ipv6; - } val; -} wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_t; - -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_IPV4 0 -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_ADDRESS_IPV6 1 - -typedef struct { - uint16_t port; - wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_address_t address; -} wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_socket_address_t; - -typedef struct { - uint16_t port; - uint32_t flow_info; - wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_address_t address; - uint32_t scope_id; -} wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_socket_address_t; - -typedef struct { - uint8_t tag; - union { - wasi_sockets_0_2_0_rc_2023_10_18_network_ipv4_socket_address_t ipv4; - wasi_sockets_0_2_0_rc_2023_10_18_network_ipv6_socket_address_t ipv6; - } val; -} wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t; - -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV4 0 -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_NETWORK_IP_SOCKET_ADDRESS_IPV6 1 - -typedef wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_error_code_t; - -typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t; - -typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t; - -typedef struct { - int32_t __handle; -} reactor_borrow_network_t; - -typedef struct { - int32_t __handle; -} reactor_own_resolve_address_stream_t; - -typedef struct { - int32_t __handle; -} reactor_borrow_resolve_address_stream_t; - -typedef struct { - bool is_some; - wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t val; -} reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t; - -typedef wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t; - -typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t; - -typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_address_family_t; - -typedef uint8_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_shutdown_type_t; - -// Similar to `SHUT_RD` in POSIX. -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_TCP_SHUTDOWN_TYPE_RECEIVE 0 -// Similar to `SHUT_WR` in POSIX. -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_TCP_SHUTDOWN_TYPE_SEND 1 -// Similar to `SHUT_RDWR` in POSIX. -#define WASI_SOCKETS_0_2_0_RC_2023_10_18_TCP_SHUTDOWN_TYPE_BOTH 2 - -typedef struct { - int32_t __handle; -} reactor_borrow_tcp_socket_t; - -typedef struct { - reactor_own_input_stream_t f0; - reactor_own_output_stream_t f1; -} reactor_tuple2_own_input_stream_own_output_stream_t; - -typedef struct { - int32_t __handle; -} reactor_own_tcp_socket_t; - -typedef struct { - reactor_own_tcp_socket_t f0; - reactor_own_input_stream_t f1; - reactor_own_output_stream_t f2; -} reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t; - -typedef wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t; - -typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_ip_address_family_t; - -typedef wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t; - -typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_socket_address_t wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t; - -typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_address_family_t; - -typedef struct { - reactor_list_u8_t data; - wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t remote_address; -} wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t; - -typedef struct { - int32_t __handle; -} reactor_borrow_udp_socket_t; - -typedef struct { - wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ptr; - size_t len; -} reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t; - -typedef wasi_sockets_0_2_0_rc_2023_10_18_network_error_code_t wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_error_code_t; - -typedef wasi_sockets_0_2_0_rc_2023_10_18_network_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_ip_address_family_t; - -typedef struct { - int32_t __handle; -} reactor_own_udp_socket_t; - -typedef struct { - int32_t __handle; -} reactor_own_network_t; - -typedef struct { - uint64_t f0; - uint64_t f1; -} reactor_tuple2_u64_u64_t; - -typedef struct { - reactor_string_t f0; - reactor_string_t f1; -} reactor_tuple2_string_string_t; - -typedef struct { - reactor_tuple2_string_string_t *ptr; - size_t len; -} reactor_list_tuple2_string_string_t; - -typedef struct { - reactor_string_t *ptr; - size_t len; -} reactor_list_string_t; - -typedef struct { - bool is_err; -} reactor_result_void_void_t; - -typedef struct { - int32_t __handle; -} reactor_own_terminal_input_t; - -typedef struct { - int32_t __handle; -} reactor_own_terminal_output_t; - -// Imported Functions from `wasi:clocks/wall-clock@0.2.0-rc-2023-10-18` -// 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 wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_now(wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t *ret); -// Query the resolution of the clock. -// -// The nanoseconds field of the output is always less than 1000000000. -extern void wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_resolution(wasi_clocks_0_2_0_rc_2023_10_18_wall_clock_datetime_t *ret); - -// Imported Functions from `wasi:io/poll@0.2.0-rc-2023-10-18` -// 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 wasi_io_0_2_0_rc_2023_10_18_poll_poll_list(reactor_list_borrow_pollable_t *in, reactor_list_u32_t *ret); -// Poll for completion on a single pollable. -// -// This function is similar to `poll-list`, but operates on only a single -// pollable. When it returns, the handle is ready for I/O. -extern void wasi_io_0_2_0_rc_2023_10_18_poll_poll_one(reactor_borrow_pollable_t in); - -// Imported Functions from `wasi:clocks/monotonic-clock@0.2.0-rc-2023-10-18` -// 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 wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_now(void); -// Query the resolution of the clock. -extern wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_resolution(void); -// Create a `pollable` which will resolve once the specified time has been -// reached. -extern reactor_own_pollable_t wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_subscribe(wasi_clocks_0_2_0_rc_2023_10_18_monotonic_clock_instant_t when, bool absolute); - -// Imported Functions from `wasi:clocks/timezone@0.2.0-rc-2023-10-18` -// Return information needed to display the given `datetime`. This includes -// the UTC offset, the time zone name, and a flag indicating whether -// daylight saving time is active. -// -// If the timezone cannot be determined for the given `datetime`, return a -// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight -// saving time. -extern void wasi_clocks_0_2_0_rc_2023_10_18_timezone_display(wasi_clocks_0_2_0_rc_2023_10_18_timezone_datetime_t *when, wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_t *ret); -// The same as `display`, but only return the UTC offset. -extern int32_t wasi_clocks_0_2_0_rc_2023_10_18_timezone_utc_offset(wasi_clocks_0_2_0_rc_2023_10_18_timezone_datetime_t *when); - -// Imported Functions from `wasi:io/streams@0.2.0-rc-2023-10-18` -// Returns a string that's suitable to assist humans in debugging this -// error. -// -// The returned string will change across platforms and hosts which -// means that parsing it, for example, would be a -// platform-compatibility hazard. -extern void wasi_io_0_2_0_rc_2023_10_18_streams_method_error_to_debug_string(reactor_borrow_error_t self, reactor_string_t *ret); -// Perform a non-blocking read from the stream. -// -// This function returns a list of bytes containing the data that was -// read, along with a `stream-status` which, indicates whether further -// reads are expected to produce data. The returned list will contain up to -// `len` bytes; it may return fewer than requested, but not more. An -// empty list and `stream-status:open` indicates no more data is -// available at this time, and that the pollable given by `subscribe` -// will be ready when more data is available. -// -// Once a stream has reached the end, subsequent calls to `read` or -// `skip` will always report `stream-status:ended` rather than producing more -// data. -// -// When the caller gives a `len` of 0, it represents a request to read 0 -// bytes. This read should always succeed and return an empty list and -// the current `stream-status`. -// -// 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 wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_read(reactor_borrow_input_stream_t self, uint64_t len, reactor_list_u8_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); -// Read bytes from a stream, after blocking until at least one byte can -// be read. Except for blocking, identical to `read`. -extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_read(reactor_borrow_input_stream_t self, uint64_t len, reactor_list_u8_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); -// Skip bytes from a stream. -// -// This is similar to the `read` function, but avoids copying the -// bytes into the instance. -// -// Once a stream has reached the end, subsequent calls to read or -// `skip` will always report end-of-stream rather than producing more -// data. -// -// This function returns the number of bytes skipped, along with a -// `stream-status` indicating whether the end of the stream was -// reached. The returned value will be at most `len`; it may be less. -extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_skip(reactor_borrow_input_stream_t self, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_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 wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_blocking_skip(reactor_borrow_input_stream_t self, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_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 reactor_own_pollable_t wasi_io_0_2_0_rc_2023_10_18_streams_method_input_stream_subscribe(reactor_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 wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_check_write(reactor_borrow_output_stream_t self, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); -// Perform a write. This function never blocks. -// -// 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 wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write(reactor_borrow_output_stream_t self, reactor_list_u8_t *contents, wasi_io_0_2_0_rc_2023_10_18_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 - // poll-one(pollable); - // 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` - // poll-one(pollable); - // // Check for any errors that arose during `flush` - // let _ = this.check-write(); // eliding error handling - // ``` - extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_and_flush(reactor_borrow_output_stream_t self, reactor_list_u8_t *contents, wasi_io_0_2_0_rc_2023_10_18_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 wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_flush(reactor_borrow_output_stream_t self, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); - // Request to flush buffered output, and block until flush completes - // and stream is ready for writing again. - extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_flush(reactor_borrow_output_stream_t self, wasi_io_0_2_0_rc_2023_10_18_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 reactor_own_pollable_t wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_subscribe(reactor_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 wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_write_zeroes(reactor_borrow_output_stream_t self, uint64_t len, wasi_io_0_2_0_rc_2023_10_18_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 - // poll-one(pollable); - // 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` - // poll-one(pollable); - // // Check for any errors that arose during `flush` - // let _ = this.check-write(); // eliding error handling - // ``` - extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_write_zeroes_and_flush(reactor_borrow_output_stream_t self, uint64_t len, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); - // Read from one stream and write to another. - // - // This function returns the number of bytes transferred; it may be less - // than `len`. - // - // Unlike other I/O functions, this function blocks until all the data - // read from the input stream has been written to the output stream. - extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_splice(reactor_borrow_output_stream_t self, reactor_own_input_stream_t src, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_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 at least - // one byte can be read. - extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_blocking_splice(reactor_borrow_output_stream_t self, reactor_own_input_stream_t src, uint64_t len, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); - // Forward the entire contents of an input stream to an output stream. - // - // This function repeatedly reads from the input stream and writes - // the data to the output stream, until the end of the input stream - // is reached, or an error is encountered. - // - // Unlike other I/O functions, this function blocks until the end - // of the input stream is seen and all the data has been written to - // the output stream. - // - // This function returns the number of bytes transferred, and the status of - // the output stream. - extern bool wasi_io_0_2_0_rc_2023_10_18_streams_method_output_stream_forward(reactor_borrow_output_stream_t self, reactor_own_input_stream_t src, uint64_t *ret, wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *err); - - // Imported Functions from `wasi:filesystem/types@0.2.0-rc-2023-10-18` - // 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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_via_stream(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, reactor_own_input_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write_via_stream(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, reactor_own_output_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_append_via_stream(reactor_borrow_descriptor_t self, reactor_own_output_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); - // Provide file advisory information on a descriptor. - // - // This is similar to `posix_fadvise` in POSIX. - extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_advise(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t length, wasi_filesystem_0_2_0_rc_2023_10_18_types_advice_t advice, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync_data(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_flags(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_get_type(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_type_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_size(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t size, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_access_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_modification_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t length, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, reactor_tuple2_list_u8_bool_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_write(reactor_borrow_descriptor_t self, reactor_list_u8_t *buffer, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t offset, wasi_filesystem_0_2_0_rc_2023_10_18_types_filesize_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_read_directory(reactor_borrow_descriptor_t self, reactor_own_directory_entry_stream_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_sync(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); - // Create a directory. - // - // Note: This is similar to `mkdirat` in POSIX. - extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_create_directory_at(reactor_borrow_descriptor_t self, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_stat_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_stat_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_set_times_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_access_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_new_timestamp_t *data_modification_timestamp, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); - // Create a hard link. - // - // Note: This is similar to `linkat` in POSIX. - extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_link_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t old_path_flags, reactor_string_t *old_path, reactor_borrow_descriptor_t new_descriptor, reactor_string_t *new_path, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_open_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_open_flags_t open_flags, wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_flags_t flags, wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t modes, reactor_own_descriptor_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_readlink_at(reactor_borrow_descriptor_t self, reactor_string_t *path, reactor_string_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_remove_directory_at(reactor_borrow_descriptor_t self, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); - // Rename a filesystem object. - // - // Note: This is similar to `renameat` in POSIX. - extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_rename_at(reactor_borrow_descriptor_t self, reactor_string_t *old_path, reactor_borrow_descriptor_t new_descriptor, reactor_string_t *new_path, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_symlink_at(reactor_borrow_descriptor_t self, reactor_string_t *old_path, reactor_string_t *new_path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); - // Check accessibility of a filesystem path. - // - // Check whether the given filesystem path names an object which is - // readable, writable, or executable, or whether it exists. - // - // This does not a guarantee that subsequent accesses will succeed, as - // filesystem permissions may be modified asynchronously by external - // entities. - // - // Note: This is similar to `faccessat` with the `AT_EACCESS` flag in POSIX. - extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_access_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_access_type_t *type, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlink_file_at(reactor_borrow_descriptor_t self, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); - // Change the permissions of a filesystem object that is not a directory. - // - // Note that the ultimate meanings of these permissions is - // filesystem-specific. - // - // Note: This is similar to `fchmodat` in POSIX. - extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_file_permissions_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t modes, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); - // Change the permissions of a directory. - // - // Note that the ultimate meanings of these permissions is - // filesystem-specific. - // - // Unlike in POSIX, the `executable` flag is not reinterpreted as a "search" - // flag. `read` on a directory implies readability and searchability, and - // `execute` is not valid for directories. - // - // Note: This is similar to `fchmodat` in POSIX. - extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_change_directory_permissions_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_modes_t modes, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); - // Request a shared advisory lock for an open file. - // - // This requests a *shared* lock; more than one shared lock can be held for - // a file at the same time. - // - // If the open file has an exclusive lock, this function downgrades the lock - // to a shared lock. If it has a shared lock, this function has no effect. - // - // This requests an *advisory* lock, meaning that the file could be accessed - // by other programs that don't hold the lock. - // - // It is unspecified how shared locks interact with locks acquired by - // non-WASI programs. - // - // This function blocks until the lock can be acquired. - // - // Not all filesystems support locking; on filesystems which don't support - // locking, this function returns `error-code::unsupported`. - // - // Note: This is similar to `flock(fd, LOCK_SH)` in Unix. - extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_shared(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); - // Request an exclusive advisory lock for an open file. - // - // This requests an *exclusive* lock; no other locks may be held for the - // file while an exclusive lock is held. - // - // If the open file has a shared lock and there are no exclusive locks held - // for the file, this function upgrades the lock to an exclusive lock. If the - // open file already has an exclusive lock, this function has no effect. - // - // This requests an *advisory* lock, meaning that the file could be accessed - // by other programs that don't hold the lock. - // - // It is unspecified whether this function succeeds if the file descriptor - // is not opened for writing. It is unspecified how exclusive locks interact - // with locks acquired by non-WASI programs. - // - // This function blocks until the lock can be acquired. - // - // Not all filesystems support locking; on filesystems which don't support - // locking, this function returns `error-code::unsupported`. - // - // Note: This is similar to `flock(fd, LOCK_EX)` in Unix. - extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_lock_exclusive(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); - // Request a shared advisory lock for an open file. - // - // This requests a *shared* lock; more than one shared lock can be held for - // a file at the same time. - // - // If the open file has an exclusive lock, this function downgrades the lock - // to a shared lock. If it has a shared lock, this function has no effect. - // - // This requests an *advisory* lock, meaning that the file could be accessed - // by other programs that don't hold the lock. - // - // It is unspecified how shared locks interact with locks acquired by - // non-WASI programs. - // - // This function returns `error-code::would-block` if the lock cannot be - // acquired. - // - // Not all filesystems support locking; on filesystems which don't support - // locking, this function returns `error-code::unsupported`. - // - // Note: This is similar to `flock(fd, LOCK_SH | LOCK_NB)` in Unix. - extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_shared(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); - // Request an exclusive advisory lock for an open file. - // - // This requests an *exclusive* lock; no other locks may be held for the - // file while an exclusive lock is held. - // - // If the open file has a shared lock and there are no exclusive locks held - // for the file, this function upgrades the lock to an exclusive lock. If the - // open file already has an exclusive lock, this function has no effect. - // - // This requests an *advisory* lock, meaning that the file could be accessed - // by other programs that don't hold the lock. - // - // It is unspecified whether this function succeeds if the file descriptor - // is not opened for writing. It is unspecified how exclusive locks interact - // with locks acquired by non-WASI programs. - // - // This function returns `error-code::would-block` if the lock cannot be - // acquired. - // - // Not all filesystems support locking; on filesystems which don't support - // locking, this function returns `error-code::unsupported`. - // - // Note: This is similar to `flock(fd, LOCK_EX | LOCK_NB)` in Unix. - extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_try_lock_exclusive(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); - // Release a shared or exclusive lock on an open file. - // - // Note: This is similar to `flock(fd, LOCK_UN)` in Unix. - extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_unlock(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_is_same_object(reactor_borrow_descriptor_t self, reactor_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_method_descriptor_metadata_hash_at(reactor_borrow_descriptor_t self, wasi_filesystem_0_2_0_rc_2023_10_18_types_path_flags_t path_flags, reactor_string_t *path, wasi_filesystem_0_2_0_rc_2023_10_18_types_metadata_hash_value_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *err); - // Read a single directory entry from a `directory-entry-stream`. - extern bool wasi_filesystem_0_2_0_rc_2023_10_18_types_method_directory_entry_stream_read_directory_entry(reactor_borrow_directory_entry_stream_t self, reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t *ret, wasi_filesystem_0_2_0_rc_2023_10_18_types_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 wasi_filesystem_0_2_0_rc_2023_10_18_types_filesystem_error_code(reactor_borrow_error_t err, wasi_filesystem_0_2_0_rc_2023_10_18_types_error_code_t *ret); - - // Imported Functions from `wasi:filesystem/preopens@0.2.0-rc-2023-10-18` - // Return the set of preopened directories, and their path. - extern void wasi_filesystem_0_2_0_rc_2023_10_18_preopens_get_directories(reactor_list_tuple2_own_descriptor_string_t *ret); - - // Imported Functions from `wasi:sockets/instance-network@0.2.0-rc-2023-10-18` - // Get a handle to the default network. - extern reactor_own_network_t wasi_sockets_0_2_0_rc_2023_10_18_instance_network_instance_network(void); - - // Imported Functions from `wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18` - // Resolve an internet host name to a list of IP addresses. - // - // See the wasi-socket proposal README.md for a comparison with getaddrinfo. - // - // # Parameters - // - `name`: The name to look up. IP addresses are not allowed. Unicode domain names are automatically converted - // to ASCII using IDNA encoding. - // - `address-family`: If provided, limit the results to addresses of this specific address family. - // - `include-unavailable`: When set to true, this function will also return addresses of which the runtime - // thinks (or knows) can't be connected to at the moment. For example, this will return IPv6 addresses on - // systems without an active IPv6 interface. Notes: - // - Even when no public IPv6 interfaces are present or active, names like "localhost" can still resolve to an IPv6 address. - // - Whatever is "available" or "unavailable" is volatile and can change everytime a network cable is unplugged. - // - // 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. - // - // At the moment, the stream never completes successfully with 0 items. Ie. the first call - // to `resolve-next-address` never returns `ok(none)`. This may change in the future. - // - // # Typical errors - // - `invalid-argument`: `name` is a syntactically invalid domain name. - // - `invalid-argument`: `name` is an IP address. - // - `not-supported`: The specified `address-family` is not supported. (EAI_FAMILY) - // - // # References: - // - - // - - // - - // - - extern bool wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_addresses(reactor_borrow_network_t network, reactor_string_t *name, wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_family_t *maybe_address_family, bool include_unavailable, reactor_own_resolve_address_stream_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_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 wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_resolve_next_address(reactor_borrow_resolve_address_stream_t self, reactor_option_wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_ip_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_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 reactor_own_pollable_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_method_resolve_address_stream_subscribe(reactor_borrow_resolve_address_stream_t self); - - // Imported Functions from `wasi:sockets/tcp@0.2.0-rc-2023-10-18` - // 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. - // - // When a socket is not explicitly bound, the first invocation to a listen or connect operation will - // implicitly bind the socket. - // - // Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. - // - // # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL) - // - `invalid-state`: The socket is already bound. (EINVAL) - // - // # Typical `finish` errors - // - `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) - // - // # References - // - - // - - // - - // - - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_bind(reactor_borrow_tcp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *local_address, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_bind(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_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 - // - // POSIX mentions: - // > If connect() fails, the state of the socket is unspecified. Conforming applications should - // > close the file descriptor and create a new socket before attempting to reconnect. - // - // WASI prescribes the following behavior: - // - If `connect` fails because an input/state validation error, the socket should remain usable. - // - If a connection was actually attempted but failed, the socket should become unusable for further network communication. - // Besides `drop`, any method after such a failure may return an error. - // - // # Typical `start` 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, but the socket has `ipv6-only` enabled. (EINVAL, EADDRNOTAVAIL on Illumos) - // - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) - // - `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 Connection state. (EISCONN) - // - `invalid-state`: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows) - // - // # Typical `finish` errors - // - `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) - // - `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) - // - // # References - // - - // - - // - - // - - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_connect(reactor_borrow_tcp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *remote_address, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_connect(reactor_borrow_tcp_socket_t self, reactor_tuple2_own_input_stream_own_output_stream_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - // Start listening for new connections. - // - // Transitions the socket into the Listener state. - // - // Unlike POSIX: - // - this function is async. This enables interactive WASI hosts to inject permission prompts. - // - the socket must already be explicitly bound. - // - // # Typical `start` errors - // - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) - // - `invalid-state`: The socket is already in the Connection state. (EISCONN, EINVAL on BSD) - // - `invalid-state`: The socket is already in the Listener state. - // - // # Typical `finish` errors - // - `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) - // - // # References - // - - // - - // - - // - - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_start_listen(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_finish_listen(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - // Accept a new client socket. - // - // The returned socket is bound and in the Connection state. The following properties are inherited from the listener socket: - // - `address-family` - // - `ipv6-only` - // - `keep-alive` - // - `no-delay` - // - `unicast-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 Listener 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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_accept(reactor_borrow_tcp_socket_t self, reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_local_address(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_remote_address(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - // Whether this is a IPv4 or IPv6 socket. - // - // Equivalent to the SO_DOMAIN socket option. - extern wasi_sockets_0_2_0_rc_2023_10_18_tcp_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_address_family(reactor_borrow_tcp_socket_t self); - // Whether IPv4 compatibility (dual-stack) mode is disabled or not. - // - // Equivalent to the IPV6_V6ONLY socket option. - // - // # Typical errors - // - `invalid-state`: (set) The socket is already bound. - // - `not-supported`: (get/set) `this` socket is an IPv4 socket. - // - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_ipv6_only(reactor_borrow_tcp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_ipv6_only(reactor_borrow_tcp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - // Hints the desired listen queue size. Implementations are free to ignore this. - // - // # Typical errors - // - `not-supported`: (set) The platform does not support changing the backlog size after the initial listen. - // - `invalid-state`: (set) The socket is already in the Connection state. - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_listen_backlog_size(reactor_borrow_tcp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - // Equivalent to the SO_KEEPALIVE socket option. - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_keep_alive(reactor_borrow_tcp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_keep_alive(reactor_borrow_tcp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - // Equivalent to the TCP_NODELAY socket option. - // - // The default value is `false`. - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_no_delay(reactor_borrow_tcp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_no_delay(reactor_borrow_tcp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - // Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. - // - // # Typical errors - // - `invalid-argument`: (set) The TTL value must be 1 or higher. - // - `invalid-state`: (set) The socket is already in the Connection state. - // - `invalid-state`: (set) The socket is already in the Listener state. - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_unicast_hop_limit(reactor_borrow_tcp_socket_t self, uint8_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_unicast_hop_limit(reactor_borrow_tcp_socket_t self, uint8_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - // The kernel buffer space reserved for sends/receives on this socket. - // - // Note #1: an implementation may choose to cap or round the buffer size when setting the value. - // In other words, after setting a value, reading the same setting back may return a different value. - // - // Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of - // actual data to be sent/received by the application, because the kernel might also use the buffer space - // for internal metadata structures. - // - // Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. - // - // # Typical errors - // - `invalid-state`: (set) The socket is already in the Connection state. - // - `invalid-state`: (set) The socket is already in the Listener state. - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_receive_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_receive_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_send_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_send_buffer_size(reactor_borrow_tcp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_tcp_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 reactor_own_pollable_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_subscribe(reactor_borrow_tcp_socket_t self); - // Initiate a graceful shutdown. - // - // - receive: the socket is not expecting to receive any more data from the peer. All subsequent read - // operations on the `input-stream` associated with this socket will return an End Of Stream indication. - // Any data still in the receive queue at time of calling `shutdown` will be discarded. - // - send: the socket is not expecting to send any more data to the peer. All subsequent write - // operations on the `output-stream` associated with this socket will return an error. - // - both: same effect as receive & send combined. - // - // The shutdown function does not close (drop) the socket. - // - // # Typical errors - // - `invalid-state`: The socket is not in the Connection state. (ENOTCONN) - // - // # References - // - - // - - // - - // - - extern bool wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_shutdown(reactor_borrow_tcp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_tcp_shutdown_type_t shutdown_type, wasi_sockets_0_2_0_rc_2023_10_18_tcp_error_code_t *err); - - // Imported Functions from `wasi:sockets/tcp-create-socket@0.2.0-rc-2023-10-18` - // Create a new TCP socket. - // - // Similar to `socket(AF_INET or AF_INET6, SOCK_STREAM, IPPROTO_TCP)` in POSIX. - // - // 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`/`listen`/`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 wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_create_tcp_socket(wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_ip_address_family_t address_family, reactor_own_tcp_socket_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_tcp_create_socket_error_code_t *err); - - // Imported Functions from `wasi:sockets/udp@0.2.0-rc-2023-10-18` - // 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. - // - // When a socket is not explicitly bound, the first invocation to connect will implicitly bind the socket. - // - // Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. - // - // # Typical `start` errors - // - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) - // - `invalid-state`: The socket is already bound. (EINVAL) - // - // # Typical `finish` errors - // - `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) - // - // # References - // - - // - - // - - // - - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_bind(reactor_borrow_udp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *local_address, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_bind(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); - // Set the destination address. - // - // The local-address is updated based on the best network path to `remote-address`. - // - // When a destination address is set: - // - all receive operations will only return datagrams sent from the provided `remote-address`. - // - the `send` function can only be used to send to this destination. - // - // Note that this function does not generate any network traffic and the peer is not aware of this "connection". - // - // Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. - // - // # Typical `start` errors - // - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - // - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) - // - `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 already bound to a different network. The `network` passed to `connect` must be identical to the one passed to `bind`. - // - // # Typical `finish` errors - // - `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) - // - // # References - // - - // - - // - - // - - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_start_connect(reactor_borrow_udp_socket_t self, reactor_borrow_network_t network, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *remote_address, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_finish_connect(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); - // 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. - // If `max-results` is 0, this function returns successfully with an empty list. - // - // # Typical errors - // - `invalid-state`: The socket is not bound to any local address. (EINVAL) - // - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN) - // - `would-block`: There is no pending data available to be read at the moment. (EWOULDBLOCK, EAGAIN) - // - // # References - // - - // - - // - - // - - // - - // - - // - - // - - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive(reactor_borrow_udp_socket_t self, uint64_t max_results, reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_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 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)`. - // - // The remote address option is required. To send a message to the "connected" peer, - // call `remote-address` to get their address. - // - // # Typical errors - // - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - // - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) - // - `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 the `datagram.remote-address` does not match the address passed to `connect`. (EISCONN) - // - `invalid-state`: The socket is not bound to any local address. Unlike POSIX, this function does not perform an implicit bind. - // - `remote-unreachable`: The remote address is not reachable. (ECONNREFUSED, ECONNRESET, ENETRESET on Windows, EHOSTUNREACH, EHOSTDOWN, ENETUNREACH, ENETDOWN) - // - `datagram-too-large`: The datagram is too large. (EMSGSIZE) - // - `would-block`: The send buffer is currently full. (EWOULDBLOCK, EAGAIN) - // - // # References - // - - // - - // - - // - - // - - // - - // - - // - - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send(reactor_borrow_udp_socket_t self, reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *datagrams, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_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 wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_local_address(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); - // Get the address set with `connect`. - // - // # Typical errors - // - `invalid-state`: The socket is not connected to a remote address. (ENOTCONN) - // - // # References - // - - // - - // - - // - - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_remote_address(reactor_borrow_udp_socket_t self, wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_socket_address_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); - // Whether this is a IPv4 or IPv6 socket. - // - // Equivalent to the SO_DOMAIN socket option. - extern wasi_sockets_0_2_0_rc_2023_10_18_udp_ip_address_family_t wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_address_family(reactor_borrow_udp_socket_t self); - // Whether IPv4 compatibility (dual-stack) mode is disabled or not. - // - // Equivalent to the IPV6_V6ONLY socket option. - // - // # Typical errors - // - `not-supported`: (get/set) `this` socket is an IPv4 socket. - // - `invalid-state`: (set) The socket is already bound. - // - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_ipv6_only(reactor_borrow_udp_socket_t self, bool *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_ipv6_only(reactor_borrow_udp_socket_t self, bool value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); - // Equivalent to the IP_TTL & IPV6_UNICAST_HOPS socket options. - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_unicast_hop_limit(reactor_borrow_udp_socket_t self, uint8_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_unicast_hop_limit(reactor_borrow_udp_socket_t self, uint8_t value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); - // The kernel buffer space reserved for sends/receives on this socket. - // - // Note #1: an implementation may choose to cap or round the buffer size when setting the value. - // In other words, after setting a value, reading the same setting back may return a different value. - // - // Note #2: there is not necessarily a direct relationship between the kernel buffer size and the bytes of - // actual data to be sent/received by the application, because the kernel might also use the buffer space - // for internal metadata structures. - // - // Equivalent to the SO_RCVBUF and SO_SNDBUF socket options. - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_receive_buffer_size(reactor_borrow_udp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_receive_buffer_size(reactor_borrow_udp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_send_buffer_size(reactor_borrow_udp_socket_t self, uint64_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_error_code_t *err); - extern bool wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_set_send_buffer_size(reactor_borrow_udp_socket_t self, uint64_t value, wasi_sockets_0_2_0_rc_2023_10_18_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 reactor_own_pollable_t wasi_sockets_0_2_0_rc_2023_10_18_udp_method_udp_socket_subscribe(reactor_borrow_udp_socket_t self); - - // Imported Functions from `wasi:sockets/udp-create-socket@0.2.0-rc-2023-10-18` - // Create a new UDP socket. - // - // Similar to `socket(AF_INET or AF_INET6, SOCK_DGRAM, IPPROTO_UDP)` in POSIX. - // - // 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 wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_create_udp_socket(wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_ip_address_family_t address_family, reactor_own_udp_socket_t *ret, wasi_sockets_0_2_0_rc_2023_10_18_udp_create_socket_error_code_t *err); - - // Imported Functions from `wasi:random/random@0.2.0-rc-2023-10-18` - // 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 wasi_random_0_2_0_rc_2023_10_18_random_get_random_bytes(uint64_t len, reactor_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 wasi_random_0_2_0_rc_2023_10_18_random_get_random_u64(void); - - // Imported Functions from `wasi:random/insecure@0.2.0-rc-2023-10-18` - // 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 wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_bytes(uint64_t len, reactor_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 wasi_random_0_2_0_rc_2023_10_18_insecure_get_insecure_random_u64(void); - - // Imported Functions from `wasi:random/insecure-seed@0.2.0-rc-2023-10-18` - // 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 wasi_random_0_2_0_rc_2023_10_18_insecure_seed_insecure_seed(reactor_tuple2_u64_u64_t *ret); - - // Imported Functions from `wasi:cli/environment@0.2.0-rc-2023-10-18` - // 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 wasi_cli_0_2_0_rc_2023_10_18_environment_get_environment(reactor_list_tuple2_string_string_t *ret); - // Get the POSIX-style arguments to the program. - extern void wasi_cli_0_2_0_rc_2023_10_18_environment_get_arguments(reactor_list_string_t *ret); - // Return a path that programs should use as their initial current working - // directory, interpreting `.` as shorthand for this. - extern bool wasi_cli_0_2_0_rc_2023_10_18_environment_initial_cwd(reactor_string_t *ret); - - // Imported Functions from `wasi:cli/exit@0.2.0-rc-2023-10-18` - // Exit the current instance and any linked instances. - extern void wasi_cli_0_2_0_rc_2023_10_18_exit_exit(reactor_result_void_void_t *status); - - // Imported Functions from `wasi:cli/stdin@0.2.0-rc-2023-10-18` - extern reactor_own_input_stream_t wasi_cli_0_2_0_rc_2023_10_18_stdin_get_stdin(void); - - // Imported Functions from `wasi:cli/stdout@0.2.0-rc-2023-10-18` - extern reactor_own_output_stream_t wasi_cli_0_2_0_rc_2023_10_18_stdout_get_stdout(void); - - // Imported Functions from `wasi:cli/stderr@0.2.0-rc-2023-10-18` - extern reactor_own_output_stream_t wasi_cli_0_2_0_rc_2023_10_18_stderr_get_stderr(void); - - // Imported Functions from `wasi:cli/terminal-stdin@0.2.0-rc-2023-10-18` - // If stdin is connected to a terminal, return a `terminal-input` handle - // allowing further interaction with it. - extern bool wasi_cli_0_2_0_rc_2023_10_18_terminal_stdin_get_terminal_stdin(reactor_own_terminal_input_t *ret); - - // Imported Functions from `wasi:cli/terminal-stdout@0.2.0-rc-2023-10-18` - // If stdout is connected to a terminal, return a `terminal-output` handle - // allowing further interaction with it. - extern bool wasi_cli_0_2_0_rc_2023_10_18_terminal_stdout_get_terminal_stdout(reactor_own_terminal_output_t *ret); - - // Imported Functions from `wasi:cli/terminal-stderr@0.2.0-rc-2023-10-18` - // If stderr is connected to a terminal, return a `terminal-output` handle - // allowing further interaction with it. - extern bool wasi_cli_0_2_0_rc_2023_10_18_terminal_stderr_get_terminal_stderr(reactor_own_terminal_output_t *ret); - - // Helper Functions - - void reactor_borrow_pollable_free(reactor_borrow_pollable_t *ptr); - void reactor_list_borrow_pollable_free(reactor_list_borrow_pollable_t *ptr); - void reactor_list_u32_free(reactor_list_u32_t *ptr); - void reactor_own_error_free(reactor_own_error_t *ptr); - void wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_free(wasi_io_0_2_0_rc_2023_10_18_streams_stream_error_t *ptr); - void reactor_borrow_error_free(reactor_borrow_error_t *ptr); - void reactor_borrow_input_stream_free(reactor_borrow_input_stream_t *ptr); - void reactor_list_u8_free(reactor_list_u8_t *ptr); - void reactor_borrow_output_stream_free(reactor_borrow_output_stream_t *ptr); - void reactor_own_pollable_free(reactor_own_pollable_t *ptr); - void reactor_own_input_stream_free(reactor_own_input_stream_t *ptr); - void wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_free(wasi_clocks_0_2_0_rc_2023_10_18_timezone_timezone_display_t *ptr); - void wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_free(wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t *ptr); - void reactor_borrow_descriptor_free(reactor_borrow_descriptor_t *ptr); - void reactor_own_output_stream_free(reactor_own_output_stream_t *ptr); - void reactor_tuple2_list_u8_bool_free(reactor_tuple2_list_u8_bool_t *ptr); - void reactor_own_directory_entry_stream_free(reactor_own_directory_entry_stream_t *ptr); - void reactor_own_descriptor_free(reactor_own_descriptor_t *ptr); - void reactor_borrow_directory_entry_stream_free(reactor_borrow_directory_entry_stream_t *ptr); - void reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_free(reactor_option_wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_t *ptr); - void reactor_tuple2_own_descriptor_string_free(reactor_tuple2_own_descriptor_string_t *ptr); - void reactor_list_tuple2_own_descriptor_string_free(reactor_list_tuple2_own_descriptor_string_t *ptr); - void reactor_borrow_network_free(reactor_borrow_network_t *ptr); - void reactor_own_resolve_address_stream_free(reactor_own_resolve_address_stream_t *ptr); - void reactor_borrow_resolve_address_stream_free(reactor_borrow_resolve_address_stream_t *ptr); - void reactor_borrow_tcp_socket_free(reactor_borrow_tcp_socket_t *ptr); - void reactor_tuple2_own_input_stream_own_output_stream_free(reactor_tuple2_own_input_stream_own_output_stream_t *ptr); - void reactor_own_tcp_socket_free(reactor_own_tcp_socket_t *ptr); - void reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_free(reactor_tuple3_own_tcp_socket_own_input_stream_own_output_stream_t *ptr); - void wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_free(wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ptr); - void reactor_borrow_udp_socket_free(reactor_borrow_udp_socket_t *ptr); - void reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_free(reactor_list_wasi_sockets_0_2_0_rc_2023_10_18_udp_datagram_t *ptr); - void reactor_own_udp_socket_free(reactor_own_udp_socket_t *ptr); - void reactor_own_network_free(reactor_own_network_t *ptr); - void reactor_tuple2_string_string_free(reactor_tuple2_string_string_t *ptr); - void reactor_list_tuple2_string_string_free(reactor_list_tuple2_string_string_t *ptr); - void reactor_list_string_free(reactor_list_string_t *ptr); - void reactor_own_terminal_input_free(reactor_own_terminal_input_t *ptr); - void reactor_own_terminal_output_free(reactor_own_terminal_output_t *ptr); - // Transfers ownership of `s` into the string `ret` - void reactor_string_set(reactor_string_t *ret, char*s); - - // Creates a copy of the input nul-terminate string `s` and - // stores it into the component model string `ret`. - void reactor_string_dup(reactor_string_t *ret, const char*s); - - // Deallocates the string pointed to by `ret`, deallocating - // the memory behind the string. - void reactor_string_free(reactor_string_t *ret); - - // Functions for working with resource `wasi:filesystem/types@0.2.0-rc-2023-10-18/directory-entry-stream` - reactor_borrow_directory_entry_stream_t wasi_filesystem_0_2_0_rc_2023_10_18_types_borrow_directory_entry_stream(reactor_own_directory_entry_stream_t); - void wasi_filesystem_0_2_0_rc_2023_10_18_types_directory_entry_stream_drop_own(reactor_own_directory_entry_stream_t); - extern void reactor_directory_entry_stream_drop_borrow(reactor_borrow_directory_entry_stream_t); - - // Functions for working with resource `wasi:io/streams@0.2.0-rc-2023-10-18/output-stream` - reactor_borrow_output_stream_t wasi_io_0_2_0_rc_2023_10_18_streams_borrow_output_stream(reactor_own_output_stream_t); - void wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(reactor_own_output_stream_t); - extern void reactor_output_stream_drop_borrow(reactor_borrow_output_stream_t); - - // Functions for working with resource `wasi:io/streams@0.2.0-rc-2023-10-18/error` - reactor_borrow_error_t wasi_io_0_2_0_rc_2023_10_18_streams_borrow_error(reactor_own_error_t); - void wasi_io_0_2_0_rc_2023_10_18_streams_error_drop_own(reactor_own_error_t); - extern void reactor_error_drop_borrow(reactor_borrow_error_t); - - // Functions for working with resource `wasi:io/poll@0.2.0-rc-2023-10-18/pollable` - reactor_borrow_pollable_t wasi_io_0_2_0_rc_2023_10_18_poll_borrow_pollable(reactor_own_pollable_t); - void wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(reactor_own_pollable_t); - extern void reactor_pollable_drop_borrow(reactor_borrow_pollable_t); - - // Functions for working with resource `wasi:sockets/tcp@0.2.0-rc-2023-10-18/tcp-socket` - reactor_borrow_tcp_socket_t wasi_sockets_0_2_0_rc_2023_10_18_tcp_borrow_tcp_socket(reactor_own_tcp_socket_t); - void wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(reactor_own_tcp_socket_t); - extern void reactor_tcp_socket_drop_borrow(reactor_borrow_tcp_socket_t); - - // Functions for working with resource `wasi:cli/terminal-input@0.2.0-rc-2023-10-18/terminal-input` - void wasi_cli_0_2_0_rc_2023_10_18_terminal_input_terminal_input_drop_own(reactor_own_terminal_input_t); - - // Functions for working with resource `wasi:sockets/ip-name-lookup@0.2.0-rc-2023-10-18/resolve-address-stream` - reactor_borrow_resolve_address_stream_t wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_borrow_resolve_address_stream(reactor_own_resolve_address_stream_t); - void wasi_sockets_0_2_0_rc_2023_10_18_ip_name_lookup_resolve_address_stream_drop_own(reactor_own_resolve_address_stream_t); - extern void reactor_resolve_address_stream_drop_borrow(reactor_borrow_resolve_address_stream_t); - - // Functions for working with resource `wasi:cli/terminal-output@0.2.0-rc-2023-10-18/terminal-output` - void wasi_cli_0_2_0_rc_2023_10_18_terminal_output_terminal_output_drop_own(reactor_own_terminal_output_t); - - // Functions for working with resource `wasi:sockets/network@0.2.0-rc-2023-10-18/network` - reactor_borrow_network_t wasi_sockets_0_2_0_rc_2023_10_18_network_borrow_network(reactor_own_network_t); - void wasi_sockets_0_2_0_rc_2023_10_18_network_network_drop_own(reactor_own_network_t); - extern void reactor_network_drop_borrow(reactor_borrow_network_t); - - // Functions for working with resource `wasi:io/streams@0.2.0-rc-2023-10-18/input-stream` - reactor_borrow_input_stream_t wasi_io_0_2_0_rc_2023_10_18_streams_borrow_input_stream(reactor_own_input_stream_t); - void wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(reactor_own_input_stream_t); - extern void reactor_input_stream_drop_borrow(reactor_borrow_input_stream_t); - - // Functions for working with resource `wasi:filesystem/types@0.2.0-rc-2023-10-18/descriptor` - reactor_borrow_descriptor_t wasi_filesystem_0_2_0_rc_2023_10_18_types_borrow_descriptor(reactor_own_descriptor_t); - void wasi_filesystem_0_2_0_rc_2023_10_18_types_descriptor_drop_own(reactor_own_descriptor_t); - extern void reactor_descriptor_drop_borrow(reactor_borrow_descriptor_t); - - // Functions for working with resource `wasi:sockets/udp@0.2.0-rc-2023-10-18/udp-socket` - reactor_borrow_udp_socket_t wasi_sockets_0_2_0_rc_2023_10_18_udp_borrow_udp_socket(reactor_own_udp_socket_t); - void wasi_sockets_0_2_0_rc_2023_10_18_udp_udp_socket_drop_own(reactor_own_udp_socket_t); - extern void reactor_udp_socket_drop_borrow(reactor_borrow_udp_socket_t); - - #ifdef __cplusplus - } - #endif - #endif - \ No newline at end of file diff --git a/libc-bottom-half/sources/__wasilibc_fd_renumber.c b/libc-bottom-half/sources/__wasilibc_fd_renumber.c index 8b6071e3a..f934c78d1 100644 --- a/libc-bottom-half/sources/__wasilibc_fd_renumber.c +++ b/libc-bottom-half/sources/__wasilibc_fd_renumber.c @@ -29,17 +29,17 @@ void drop_tcp_socket(tcp_socket_t socket) { case TCP_SOCKET_STATE_CONNECTED: { tcp_socket_state_connected_t connection = socket.state.connected; - wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(connection.input_pollable); - wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(connection.output_pollable); - wasi_io_0_2_0_rc_2023_10_18_streams_input_stream_drop_own(connection.input); - wasi_io_0_2_0_rc_2023_10_18_streams_output_stream_drop_own(connection.output); + poll_pollable_drop_own(connection.input_pollable); + poll_pollable_drop_own(connection.output_pollable); + streams_input_stream_drop_own(connection.input); + streams_output_stream_drop_own(connection.output); break; } default: /* unreachable */ abort(); } - wasi_io_0_2_0_rc_2023_10_18_poll_pollable_drop_own(socket.socket_pollable); - wasi_sockets_0_2_0_rc_2023_10_18_tcp_tcp_socket_drop_own(socket.socket); + poll_pollable_drop_own(socket.socket_pollable); + tcp_tcp_socket_drop_own(socket.socket); } void drop_udp_socket(udp_socket_t socket) { From 879d53378267e3cda1fed2d8c0fe9f95f5d043f6 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Tue, 5 Dec 2023 21:52:08 +0100 Subject: [PATCH 18/63] TCP_NODELAY was removed in rc-2023-11-10 --- libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c index 4ee16e6a9..babdd9360 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -297,15 +297,6 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt case SOL_TCP: switch (optname) { - case TCP_NODELAY: { - if (wasi_sockets_0_2_0_rc_2023_10_18_tcp_method_tcp_socket_set_no_delay(socket_borrow, intval != 0, &error)) { - return 0; - } else { - errno = __wasi_sockets_utils__map_error(error); - return -1; - } - } - case TCP_KEEPIDLE: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. case TCP_KEEPINTVL: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. case TCP_KEEPCNT: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. From 9ab49f3b6235e665c4ddfc9c4173d62fa3c02aa5 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Wed, 6 Dec 2023 08:29:51 +0100 Subject: [PATCH 19/63] Update to rc-2023-12-05 --- .../src/libc/sys/wasi_preview2/preview2.c | 88 +++++++++--------- .../wasi_preview2/preview2_component_type.o | Bin 26798 -> 26798 bytes libc-bottom-half/headers/private/preview2.h | 74 +++++++-------- 3 files changed, 81 insertions(+), 81 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c index e0cf47fee..634b9a5fe 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c @@ -2,16 +2,16 @@ #include "preview2.h" -__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-11-10"), __import_name__("get-environment"))) +__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-12-05"), __import_name__("get-environment"))) extern void __wasm_import_environment_get_environment(int32_t); -__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-11-10"), __import_name__("get-arguments"))) +__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-12-05"), __import_name__("get-arguments"))) extern void __wasm_import_environment_get_arguments(int32_t); -__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-11-10"), __import_name__("initial-cwd"))) +__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-12-05"), __import_name__("initial-cwd"))) extern void __wasm_import_environment_initial_cwd(int32_t); -__attribute__((__import_module__("wasi:cli/exit@0.2.0-rc-2023-11-10"), __import_name__("exit"))) +__attribute__((__import_module__("wasi:cli/exit@0.2.0-rc-2023-12-05"), __import_name__("exit"))) extern void __wasm_import_exit_exit(int32_t); __attribute__((__import_module__("wasi:io/error@0.2.0-rc-2023-11-10"), __import_name__("[method]error.to-debug-string"))) @@ -71,23 +71,23 @@ extern void __wasm_import_streams_method_output_stream_splice(int32_t, int32_t, __attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.blocking-splice"))) extern void __wasm_import_streams_method_output_stream_blocking_splice(int32_t, int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.2.0-rc-2023-11-10"), __import_name__("get-stdin"))) +__attribute__((__import_module__("wasi:cli/stdin@0.2.0-rc-2023-12-05"), __import_name__("get-stdin"))) extern int32_t __wasm_import_stdin_get_stdin(void); -__attribute__((__import_module__("wasi:cli/stdout@0.2.0-rc-2023-11-10"), __import_name__("get-stdout"))) +__attribute__((__import_module__("wasi:cli/stdout@0.2.0-rc-2023-12-05"), __import_name__("get-stdout"))) extern int32_t __wasm_import_stdout_get_stdout(void); -__attribute__((__import_module__("wasi:cli/stderr@0.2.0-rc-2023-11-10"), __import_name__("get-stderr"))) +__attribute__((__import_module__("wasi:cli/stderr@0.2.0-rc-2023-12-05"), __import_name__("get-stderr"))) extern int32_t __wasm_import_stderr_get_stderr(void); -__attribute__((__import_module__("wasi:cli/terminal-stdin@0.2.0-rc-2023-11-10"), __import_name__("get-terminal-stdin"))) -extern void __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_get_terminal_stdin(int32_t); +__attribute__((__import_module__("wasi:cli/terminal-stdin@0.2.0-rc-2023-12-05"), __import_name__("get-terminal-stdin"))) +extern void __wasm_import_terminal_stdin_get_terminal_stdin(int32_t); -__attribute__((__import_module__("wasi:cli/terminal-stdout@0.2.0-rc-2023-11-10"), __import_name__("get-terminal-stdout"))) -extern void __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_get_terminal_stdout(int32_t); +__attribute__((__import_module__("wasi:cli/terminal-stdout@0.2.0-rc-2023-12-05"), __import_name__("get-terminal-stdout"))) +extern void __wasm_import_terminal_stdout_get_terminal_stdout(int32_t); -__attribute__((__import_module__("wasi:cli/terminal-stderr@0.2.0-rc-2023-11-10"), __import_name__("get-terminal-stderr"))) -extern void __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_get_terminal_stderr(int32_t); +__attribute__((__import_module__("wasi:cli/terminal-stderr@0.2.0-rc-2023-12-05"), __import_name__("get-terminal-stderr"))) +extern void __wasm_import_terminal_stderr_get_terminal_stderr(int32_t); __attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10"), __import_name__("now"))) extern int64_t __wasm_import_monotonic_clock_now(void); @@ -539,47 +539,47 @@ void streams_result_void_stream_error_free(streams_result_void_stream_error_t *p } } -__attribute__((__import_module__("wasi:cli/terminal-input@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]terminal-input"))) -extern void __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop(int32_t handle); +__attribute__((__import_module__("wasi:cli/terminal-input@0.2.0-rc-2023-12-05"), __import_name__("[resource-drop]terminal-input"))) +extern void __wasm_import_terminal_input_terminal_input_drop(int32_t handle); -void wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop_own(wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t handle) { - __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop(handle.__handle); +void terminal_input_terminal_input_drop_own(terminal_input_own_terminal_input_t handle) { + __wasm_import_terminal_input_terminal_input_drop(handle.__handle); } -void wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop_borrow(wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t handle) { - __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop(handle.__handle); +void terminal_input_terminal_input_drop_borrow(terminal_input_own_terminal_input_t handle) { + __wasm_import_terminal_input_terminal_input_drop(handle.__handle); } -wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input_t wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input(wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t arg) { - return (wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input_t) { arg.__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.2.0-rc-2023-11-10"), __import_name__("[resource-drop]terminal-output"))) -extern void __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop(int32_t handle); +__attribute__((__import_module__("wasi:cli/terminal-output@0.2.0-rc-2023-12-05"), __import_name__("[resource-drop]terminal-output"))) +extern void __wasm_import_terminal_output_terminal_output_drop(int32_t handle); -void wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop_own(wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t handle) { - __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop(handle.__handle); +void terminal_output_terminal_output_drop_own(terminal_output_own_terminal_output_t handle) { + __wasm_import_terminal_output_terminal_output_drop(handle.__handle); } -void wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop_borrow(wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t handle) { - __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop(handle.__handle); +void terminal_output_terminal_output_drop_borrow(terminal_output_own_terminal_output_t handle) { + __wasm_import_terminal_output_terminal_output_drop(handle.__handle); } -wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output_t wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output(wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t arg) { - return (wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output_t) { arg.__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 wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_option_own_terminal_input_free(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_option_own_terminal_input_t *ptr) { +void terminal_stdin_option_own_terminal_input_free(terminal_stdin_option_own_terminal_input_t *ptr) { if (ptr->is_some) { } } -void wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_option_own_terminal_output_free(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_option_own_terminal_output_t *ptr) { +void terminal_stdout_option_own_terminal_output_free(terminal_stdout_option_own_terminal_output_t *ptr) { if (ptr->is_some) { } } -void wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_option_own_terminal_output_free(wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_option_own_terminal_output_t *ptr) { +void terminal_stderr_option_own_terminal_output_free(terminal_stderr_option_own_terminal_output_t *ptr) { if (ptr->is_some) { } } @@ -1672,12 +1672,12 @@ stderr_own_output_stream_t stderr_get_stderr(void) { return (stderr_own_output_stream_t) { ret }; } -bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_get_terminal_stdin(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_own_terminal_input_t *ret) { +bool terminal_stdin_get_terminal_stdin(terminal_stdin_own_terminal_input_t *ret) { __attribute__((__aligned__(4))) uint8_t ret_area[8]; int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_get_terminal_stdin(ptr); - wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_option_own_terminal_input_t option; + __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; @@ -1685,7 +1685,7 @@ bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_get_terminal_stdin(wasi_cli_0_2 } case 1: { option.is_some = true; - option.val = (wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_own_terminal_input_t) { *((int32_t*) (ptr + 4)) }; + option.val = (terminal_stdin_own_terminal_input_t) { *((int32_t*) (ptr + 4)) }; break; } } @@ -1693,12 +1693,12 @@ bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_get_terminal_stdin(wasi_cli_0_2 return option.is_some; } -bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_get_terminal_stdout(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_own_terminal_output_t *ret) { +bool terminal_stdout_get_terminal_stdout(terminal_stdout_own_terminal_output_t *ret) { __attribute__((__aligned__(4))) uint8_t ret_area[8]; int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_get_terminal_stdout(ptr); - wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_option_own_terminal_output_t option; + __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; @@ -1706,7 +1706,7 @@ bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_get_terminal_stdout(wasi_cli_0 } case 1: { option.is_some = true; - option.val = (wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_own_terminal_output_t) { *((int32_t*) (ptr + 4)) }; + option.val = (terminal_stdout_own_terminal_output_t) { *((int32_t*) (ptr + 4)) }; break; } } @@ -1714,12 +1714,12 @@ bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_get_terminal_stdout(wasi_cli_0 return option.is_some; } -bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_get_terminal_stderr(wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_own_terminal_output_t *ret) { +bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t *ret) { __attribute__((__aligned__(4))) uint8_t ret_area[8]; int32_t ptr = (int32_t) &ret_area; - __wasm_import_wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_get_terminal_stderr(ptr); - wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_option_own_terminal_output_t option; + __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; @@ -1727,7 +1727,7 @@ bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_get_terminal_stderr(wasi_cli_0 } case 1: { option.is_some = true; - option.val = (wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_own_terminal_output_t) { *((int32_t*) (ptr + 4)) }; + option.val = (terminal_stderr_own_terminal_output_t) { *((int32_t*) (ptr + 4)) }; break; } } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2_component_type.o b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2_component_type.o index 1d3af745676a6b4af5eaf7ede6129dfa4e793936..37590f0c22ad6905a28fe69fd6203f8fd61fee10 100644 GIT binary patch delta 372 zcmZ2?k#XHc#tA1_jC2i5C!Prh)05R1-N1~^g^cqVAuJK*rBK#hmSqsuVv56``(>J#!YO(_W44_&b diff --git a/libc-bottom-half/headers/private/preview2.h b/libc-bottom-half/headers/private/preview2.h index fc2b03852..f7581c715 100644 --- a/libc-bottom-half/headers/private/preview2.h +++ b/libc-bottom-half/headers/private/preview2.h @@ -136,42 +136,42 @@ typedef streams_own_output_stream_t stdout_own_output_stream_t; typedef streams_own_output_stream_t stderr_own_output_stream_t; -typedef struct wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t { +typedef struct terminal_input_own_terminal_input_t { int32_t __handle; -} wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t; +} terminal_input_own_terminal_input_t; -typedef struct wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input_t { +typedef struct terminal_input_borrow_terminal_input_t { int32_t __handle; -} wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input_t; +} terminal_input_borrow_terminal_input_t; -typedef struct wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t { +typedef struct terminal_output_own_terminal_output_t { int32_t __handle; -} wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t; +} terminal_output_own_terminal_output_t; -typedef struct wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output_t { +typedef struct terminal_output_borrow_terminal_output_t { int32_t __handle; -} wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output_t; +} terminal_output_borrow_terminal_output_t; -typedef wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_own_terminal_input_t; +typedef terminal_input_own_terminal_input_t terminal_stdin_own_terminal_input_t; typedef struct { bool is_some; - wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_own_terminal_input_t val; -} wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_option_own_terminal_input_t; + terminal_stdin_own_terminal_input_t val; +} terminal_stdin_option_own_terminal_input_t; -typedef wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_own_terminal_output_t; +typedef terminal_output_own_terminal_output_t terminal_stdout_own_terminal_output_t; typedef struct { bool is_some; - wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_own_terminal_output_t val; -} wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_option_own_terminal_output_t; + terminal_stdout_own_terminal_output_t val; +} terminal_stdout_option_own_terminal_output_t; -typedef wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_own_terminal_output_t; +typedef terminal_output_own_terminal_output_t terminal_stderr_own_terminal_output_t; typedef struct { bool is_some; - wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_own_terminal_output_t val; -} wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_option_own_terminal_output_t; + 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 @@ -1081,7 +1081,7 @@ typedef struct { uint64_t f1; } random_insecure_seed_tuple2_u64_u64_t; -// Imported Functions from `wasi:cli/environment@0.2.0-rc-2023-11-10` +// Imported Functions from `wasi:cli/environment@0.2.0-rc-2023-12-05` // Get the POSIX-style environment variables. // // Each environment variable is provided as a pair of string variable names @@ -1097,7 +1097,7 @@ extern void environment_get_arguments(environment_list_string_t *ret); // directory, interpreting `.` as shorthand for this. extern bool environment_initial_cwd(imports_string_t *ret); -// Imported Functions from `wasi:cli/exit@0.2.0-rc-2023-11-10` +// Imported Functions from `wasi:cli/exit@0.2.0-rc-2023-12-05` // Exit the current instance and any linked instances. extern void exit_exit(exit_result_void_void_t *status); @@ -1304,29 +1304,29 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // 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-rc-2023-11-10` + // Imported Functions from `wasi:cli/stdin@0.2.0-rc-2023-12-05` extern stdin_own_input_stream_t stdin_get_stdin(void); - // Imported Functions from `wasi:cli/stdout@0.2.0-rc-2023-11-10` + // Imported Functions from `wasi:cli/stdout@0.2.0-rc-2023-12-05` extern stdout_own_output_stream_t stdout_get_stdout(void); - // Imported Functions from `wasi:cli/stderr@0.2.0-rc-2023-11-10` + // Imported Functions from `wasi:cli/stderr@0.2.0-rc-2023-12-05` extern stderr_own_output_stream_t stderr_get_stderr(void); - // Imported Functions from `wasi:cli/terminal-stdin@0.2.0-rc-2023-11-10` + // Imported Functions from `wasi:cli/terminal-stdin@0.2.0-rc-2023-12-05` // If stdin is connected to a terminal, return a `terminal-input` handle // allowing further interaction with it. - extern bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_get_terminal_stdin(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_own_terminal_input_t *ret); + extern bool terminal_stdin_get_terminal_stdin(terminal_stdin_own_terminal_input_t *ret); - // Imported Functions from `wasi:cli/terminal-stdout@0.2.0-rc-2023-11-10` + // Imported Functions from `wasi:cli/terminal-stdout@0.2.0-rc-2023-12-05` // If stdout is connected to a terminal, return a `terminal-output` handle // allowing further interaction with it. - extern bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_get_terminal_stdout(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_own_terminal_output_t *ret); + extern bool terminal_stdout_get_terminal_stdout(terminal_stdout_own_terminal_output_t *ret); - // Imported Functions from `wasi:cli/terminal-stderr@0.2.0-rc-2023-11-10` + // Imported Functions from `wasi:cli/terminal-stderr@0.2.0-rc-2023-12-05` // If stderr is connected to a terminal, return a `terminal-output` handle // allowing further interaction with it. - extern bool wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_get_terminal_stderr(wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_own_terminal_output_t *ret); + extern bool terminal_stderr_get_terminal_stderr(terminal_stderr_own_terminal_output_t *ret); // Imported Functions from `wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10` // Read the current value of the clock. @@ -2295,21 +2295,21 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se void streams_result_void_stream_error_free(streams_result_void_stream_error_t *ptr); - extern void wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop_own(wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t handle); - extern void wasi_cli_0_2_0_rc_2023_11_10_terminal_input_terminal_input_drop_borrow(wasi_cli_0_2_0_rc_2023_11_10_terminal_input_own_terminal_input_t handle); + extern void terminal_input_terminal_input_drop_own(terminal_input_own_terminal_input_t handle); + extern void terminal_input_terminal_input_drop_borrow(terminal_input_own_terminal_input_t handle); - extern wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input_t wasi_cli_0_2_0_rc_2023_11_10_terminal_input_borrow_terminal_input(wasi_cli_0_2_0_rc_2023_11_10_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 wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop_own(wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t handle); - extern void wasi_cli_0_2_0_rc_2023_11_10_terminal_output_terminal_output_drop_borrow(wasi_cli_0_2_0_rc_2023_11_10_terminal_output_own_terminal_output_t handle); + extern void terminal_output_terminal_output_drop_own(terminal_output_own_terminal_output_t handle); + extern void terminal_output_terminal_output_drop_borrow(terminal_output_own_terminal_output_t handle); - extern wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output_t wasi_cli_0_2_0_rc_2023_11_10_terminal_output_borrow_terminal_output(wasi_cli_0_2_0_rc_2023_11_10_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 wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_option_own_terminal_input_free(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdin_option_own_terminal_input_t *ptr); + void terminal_stdin_option_own_terminal_input_free(terminal_stdin_option_own_terminal_input_t *ptr); - void wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_option_own_terminal_output_free(wasi_cli_0_2_0_rc_2023_11_10_terminal_stdout_option_own_terminal_output_t *ptr); + void terminal_stdout_option_own_terminal_output_free(terminal_stdout_option_own_terminal_output_t *ptr); - void wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_option_own_terminal_output_free(wasi_cli_0_2_0_rc_2023_11_10_terminal_stderr_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); From eb3602d2f413e5c6f73f85fe460df93c292f50aa Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Wed, 6 Dec 2023 09:45:37 +0100 Subject: [PATCH 20/63] Implement remaining socket options introduced in rc-2023-11-10 --- .../cloudlibc/src/libc/sys/socket/sockopt.c | 93 +++++++++++++++++-- 1 file changed, 85 insertions(+), 8 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c index babdd9360..81ca778a9 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -12,6 +13,8 @@ #include #include "__utils.h" +const uint64_t NS_PER_S = 1000000000; + int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, void* restrict optval, socklen_t* restrict optlen) { @@ -48,8 +51,9 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, break; } case SO_ACCEPTCONN: { - // TODO wasi-sockets: use 2023-11-10 snapshot to call out to tcp-socket::is-listening ? - value = socket->state_tag == TCP_SOCKET_STATE_LISTENING; + bool is_listening = socket->state_tag == TCP_SOCKET_STATE_LISTENING; + assert(is_listening == tcp_method_tcp_socket_is_listening(socket_borrow)); // Sanity check. + value = is_listening; break; } case SO_KEEPALIVE: { @@ -163,9 +167,59 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, case SOL_TCP: switch (optname) { - case TCP_KEEPIDLE: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. - case TCP_KEEPINTVL: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. - case TCP_KEEPCNT: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. + case TCP_KEEPIDLE: { + tcp_duration_t result_ns; + if (!tcp_method_tcp_socket_keep_alive_idle_time(socket_borrow, &result_ns, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + uint64_t result_s = result_ns / NS_PER_S; + if (result_s == 0) { + result_s = 1; // Value was rounded down to zero. Round it up instead, because 0 is an invalid value for this socket option. + } + + if (result_s > INT_MAX) { + abort(); + } + + value = result_s; + break; + } + case TCP_KEEPINTVL: { + tcp_duration_t result_ns; + if (!tcp_method_tcp_socket_keep_alive_interval(socket_borrow, &result_ns, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + uint64_t result_s = result_ns / NS_PER_S; + if (result_s == 0) { + result_s = 1; // Value was rounded down to zero. Round it up instead, because 0 is an invalid value for this socket option. + } + + if (result_s > INT_MAX) { + abort(); + } + + value = result_s; + break; + } + case TCP_KEEPCNT: { + uint32_t result; + if (!tcp_method_tcp_socket_keep_alive_count(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + if (result > INT_MAX) { + abort(); + } + + value = result; + break; + break; + } default: errno = ENOPROTOOPT; return -1; @@ -297,9 +351,32 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt case SOL_TCP: switch (optname) { - case TCP_KEEPIDLE: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. - case TCP_KEEPINTVL: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. - case TCP_KEEPCNT: // TODO wasi-sockets: implement using the 2023-11-10 preview2 snapshot. + case TCP_KEEPIDLE: { + tcp_duration_t duration = intval * NS_PER_S; + if (!tcp_method_tcp_socket_set_keep_alive_idle_time(socket_borrow, duration, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } + case TCP_KEEPINTVL: { + tcp_duration_t duration = intval * NS_PER_S; + if (!tcp_method_tcp_socket_set_keep_alive_interval(socket_borrow, duration, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } + case TCP_KEEPCNT: { + if (!tcp_method_tcp_socket_set_keep_alive_count(socket_borrow, intval, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } default: errno = ENOPROTOOPT; return -1; From 91b0a927b07e3f9f14ce8835facf596ddaeed1e5 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Wed, 6 Dec 2023 10:58:03 +0100 Subject: [PATCH 21/63] Represent tagged unions as a single type instead of three. The tag and union always need to be updated in tandem. Having them close together helps to clarify the relationship between the two types. --- .../cloudlibc/src/libc/sys/socket/__utils.c | 5 +- .../cloudlibc/src/libc/sys/socket/accept.c | 30 +++++----- .../cloudlibc/src/libc/sys/socket/bind.c | 4 +- .../cloudlibc/src/libc/sys/socket/connect.c | 14 ++--- .../src/libc/sys/socket/getsockpeername.c | 8 +-- .../cloudlibc/src/libc/sys/socket/listen.c | 13 ++--- .../cloudlibc/src/libc/sys/socket/recv.c | 6 +- .../cloudlibc/src/libc/sys/socket/send.c | 6 +- .../cloudlibc/src/libc/sys/socket/shutdown.c | 6 +- .../cloudlibc/src/libc/sys/socket/socket.c | 16 ++---- .../cloudlibc/src/libc/sys/socket/sockopt.c | 12 ++-- .../headers/private/descriptor_table.h | 56 +++++++++---------- .../sources/__wasilibc_fd_renumber.c | 6 +- 13 files changed, 84 insertions(+), 98 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c index 3c8fe692e..ec6218690 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c @@ -212,7 +212,7 @@ network_ip_socket_address_t __wasi_sockets_utils__any_addr(network_ip_address_fa int __wasi_sockets_utils__tcp_bind(tcp_socket_t* socket, network_ip_socket_address_t* address) { tcp_socket_state_unbound_t unbound; - if (socket->state_tag == TCP_SOCKET_STATE_UNBOUND) { + if (socket->state.tag == TCP_SOCKET_STATE_UNBOUND) { unbound = socket->state.unbound; } else { errno = EINVAL; @@ -241,7 +241,6 @@ int __wasi_sockets_utils__tcp_bind(tcp_socket_t* socket, network_ip_socket_addre // Bind successful. - socket->state_tag = TCP_SOCKET_STATE_BOUND; - socket->state = (tcp_socket_state_t){ .bound = { /* No additional state */ } }; + socket->state = (tcp_socket_state_t){ .tag = TCP_SOCKET_STATE_BOUND, .bound = { /* No additional state */ } }; return 0; } \ No newline at end of file diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c index 01e8481f9..55e467a5e 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c @@ -8,7 +8,7 @@ bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, network_ip_socket_address_t* out_address, int* out_errno) { tcp_socket_state_listening_t listener; - if (socket->state_tag == TCP_SOCKET_STATE_LISTENING) { + if (socket->state.tag == TCP_SOCKET_STATE_LISTENING) { listener = socket->state.listening; } else { *out_errno = EINVAL; @@ -54,21 +54,17 @@ bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, n } } - descriptor_table_entry_t client_entry = { - .tag = DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, - .value = { .tcp_socket = { - .socket = client, - .socket_pollable = client_pollable, - .blocking = client_blocking, - .state_tag = TCP_SOCKET_STATE_CONNECTED, - .state = { .connected = { - .input = input, - .input_pollable = input_pollable, - .output = output, - .output_pollable = output_pollable, - } }, + descriptor_table_entry_t client_entry = { .tag = DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, .tcp_socket = { + .socket = client, + .socket_pollable = client_pollable, + .blocking = client_blocking, + .state = { .tag = TCP_SOCKET_STATE_CONNECTED, .connected = { + .input = input, + .input_pollable = input_pollable, + .output = output, + .output_pollable = output_pollable, } }, - }; + } }; if (!descriptor_table_insert(client_entry, out_clientfd)) { *out_errno = EMFILE; @@ -120,13 +116,13 @@ int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addr switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - if (!tcp_accept(&entry->value.tcp_socket, client_blocking, &client_fd, out_address_ptr, &err)) { + if (!tcp_accept(&entry->tcp_socket, client_blocking, &client_fd, out_address_ptr, &err)) { errno = err; return -1; } break; case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - if (!udp_accept(&entry->value.udp_socket, client_blocking, &client_fd, out_address_ptr, &err)) { + if (!udp_accept(&entry->udp_socket, client_blocking, &client_fd, out_address_ptr, &err)) { errno = err; return -1; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c index 4758fc749..251902530 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c @@ -32,9 +32,9 @@ int bind(int socket, const struct sockaddr* addr, socklen_t addrlen) { switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - return tcp_bind(&entry->value.tcp_socket, &ip_address); + return tcp_bind(&entry->tcp_socket, &ip_address); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - return udp_bind(&entry->value.udp_socket, &ip_address); + return udp_bind(&entry->udp_socket, &ip_address); default: errno = EOPNOTSUPP; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c index 4e7efe923..d0b7a1339 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c @@ -7,7 +7,7 @@ int tcp_connect(tcp_socket_t* socket, network_ip_socket_address_t* address) { - switch (socket->state_tag) { + switch (socket->state.tag) { case TCP_SOCKET_STATE_UNBOUND: case TCP_SOCKET_STATE_BOUND: // These can initiate a connect. @@ -35,8 +35,7 @@ int tcp_connect(tcp_socket_t* socket, network_ip_socket_address_t* address) } // Connect has successfully started. - socket->state_tag = TCP_SOCKET_STATE_CONNECTING; - socket->state = (tcp_socket_state_t){ .connecting = { /* No additional state */ } }; + socket->state = (tcp_socket_state_t){ .tag = TCP_SOCKET_STATE_CONNECTING, .connecting = { /* No additional state */ } }; // Attempt to finish it: tcp_tuple2_own_input_stream_own_output_stream_t io; @@ -50,7 +49,7 @@ int tcp_connect(tcp_socket_t* socket, network_ip_socket_address_t* address) return -1; } } else { - socket->state_tag = TCP_SOCKET_STATE_CONNECT_FAILED; + socket->state.tag = TCP_SOCKET_STATE_CONNECT_FAILED; socket->state = (tcp_socket_state_t){ .connect_failed = { .error_code = error, } }; @@ -70,8 +69,7 @@ int tcp_connect(tcp_socket_t* socket, network_ip_socket_address_t* address) streams_borrow_output_stream_t output_borrow = streams_borrow_output_stream(output); poll_own_pollable_t output_pollable = streams_method_output_stream_subscribe(output_borrow); - socket->state_tag = TCP_SOCKET_STATE_CONNECTED; - socket->state = (tcp_socket_state_t){ .connected = { + socket->state = (tcp_socket_state_t){ .tag = TCP_SOCKET_STATE_CONNECTED, .connected = { .input = input, .input_pollable = input_pollable, .output = output, @@ -105,9 +103,9 @@ int connect(int fd, const struct sockaddr* address, socklen_t len) switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - return tcp_connect(&entry->value.tcp_socket, &ip_address); + return tcp_connect(&entry->tcp_socket, &ip_address); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - return udp_connect(&entry->value.udp_socket, &ip_address); + return udp_connect(&entry->udp_socket, &ip_address); default: errno = EOPNOTSUPP; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c index 6e34b8797..d3976526f 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c @@ -60,13 +60,13 @@ int getsockname(int socket, struct sockaddr *__restrict addr, socklen_t *__restr switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - if (!tcp_getsockname(&entry->value.tcp_socket, &out_address)) { + if (!tcp_getsockname(&entry->tcp_socket, &out_address)) { // errno is set by tcp_getsockname return -1; } break; case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - if (!udp_getsockname(&entry->value.udp_socket, &out_address)) { + if (!udp_getsockname(&entry->udp_socket, &out_address)) { // errno is set by udp_getsockname return -1; } @@ -103,13 +103,13 @@ int getpeername(int socket, struct sockaddr *__restrict addr, socklen_t *__restr switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - if (!tcp_getpeername(&entry->value.tcp_socket, &out_address)) { + if (!tcp_getpeername(&entry->tcp_socket, &out_address)) { // errno is set by tcp_getpeername return -1; } break; case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - if (!udp_getpeername(&entry->value.udp_socket, &out_address)) { + if (!udp_getpeername(&entry->udp_socket, &out_address)) { // errno is set by udp_getpeername return -1; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c index f0f4f6710..d026e9c26 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c @@ -10,7 +10,7 @@ int tcp_listen(tcp_socket_t* socket, int backlog) { network_error_code_t error; tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); - switch (socket->state_tag) { + switch (socket->state.tag) { case TCP_SOCKET_STATE_UNBOUND: { // Socket is not explicitly bound by the user. We'll do it for them: @@ -21,7 +21,7 @@ int tcp_listen(tcp_socket_t* socket, int backlog) { return result; } - assert(socket->state_tag == TCP_SOCKET_STATE_BOUND); + assert(socket->state.tag == TCP_SOCKET_STATE_BOUND); // Great! We'll continue below. break; } @@ -43,7 +43,7 @@ int tcp_listen(tcp_socket_t* socket, int backlog) { abort(); // Our own state checks should've prevented this from happening. } - if (socket->state_tag == TCP_SOCKET_STATE_LISTENING) { + if (socket->state.tag == TCP_SOCKET_STATE_LISTENING) { // Updating the backlog is all we had to do. return 0; } @@ -67,8 +67,7 @@ int tcp_listen(tcp_socket_t* socket, int backlog) { // Listen successful. - socket->state_tag = TCP_SOCKET_STATE_LISTENING; - socket->state = (tcp_socket_state_t){ .listening = { /* No additional state */ } }; + socket->state = (tcp_socket_state_t){ .tag = TCP_SOCKET_STATE_LISTENING, .listening = { /* No additional state */ } }; return 0; } @@ -97,9 +96,9 @@ int listen(int socket, int backlog) { switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - return tcp_listen(&entry->value.tcp_socket, backlog); + return tcp_listen(&entry->tcp_socket, backlog); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - return udp_listen(&entry->value.udp_socket, backlog); + return udp_listen(&entry->udp_socket, backlog); default: errno = EOPNOTSUPP; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index 74e730495..de7dba72b 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -26,7 +26,7 @@ ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int } tcp_socket_state_connected_t connection; - if (socket->state_tag == TCP_SOCKET_STATE_CONNECTED) { + if (socket->state.tag == TCP_SOCKET_STATE_CONNECTED) { connection = socket->state.connected; } else { errno = ENOTCONN; @@ -86,9 +86,9 @@ ssize_t recv(int socket, void* restrict buffer, size_t length, int flags) switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - return tcp_recv(&entry->value.tcp_socket, buffer, length, flags); + return tcp_recv(&entry->tcp_socket, buffer, length, flags); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - return udp_recv(&entry->value.udp_socket, buffer, length, flags); + return udp_recv(&entry->udp_socket, buffer, length, flags); default: errno = EOPNOTSUPP; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c index 61850292e..e6c66589a 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c @@ -20,7 +20,7 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int fl } tcp_socket_state_connected_t connection; - if (socket->state_tag == TCP_SOCKET_STATE_CONNECTED) { + if (socket->state.tag == TCP_SOCKET_STATE_CONNECTED) { connection = socket->state.connected; } else { errno = ENOTCONN; @@ -92,9 +92,9 @@ ssize_t send(int socket, const void* buffer, size_t length, int flags) switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - return tcp_send(&entry->value.tcp_socket, buffer, length, flags); + return tcp_send(&entry->tcp_socket, buffer, length, flags); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - return udp_send(&entry->value.udp_socket, buffer, length, flags); + return udp_send(&entry->udp_socket, buffer, length, flags); default: errno = EOPNOTSUPP; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c index 1528fdce3..195d0e876 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c @@ -34,7 +34,7 @@ int tcp_shutdown(tcp_socket_t* socket, int posix_how) } tcp_socket_state_connected_t connection; - if (socket->state_tag == TCP_SOCKET_STATE_CONNECTED) { + if (socket->state.tag == TCP_SOCKET_STATE_CONNECTED) { connection = socket->state.connected; } else { errno = ENOTCONN; @@ -77,9 +77,9 @@ int shutdown(int socket, int how) { switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - return tcp_shutdown(&entry->value.tcp_socket, how); + return tcp_shutdown(&entry->tcp_socket, how); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - return udp_shutdown(&entry->value.udp_socket, how); + return udp_shutdown(&entry->udp_socket, how); default: errno = EOPNOTSUPP; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c index 6702ad893..d1871b4f2 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c @@ -16,16 +16,12 @@ int tcp_socket(network_ip_address_family_t family, bool blocking) tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket); poll_own_pollable_t socket_pollable = tcp_method_tcp_socket_subscribe(socket_borrow); - descriptor_table_entry_t entry = { - .tag = DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, - .value = { .tcp_socket = { - .socket = socket, - .socket_pollable = socket_pollable, - .blocking = blocking, - .state_tag = TCP_SOCKET_STATE_UNBOUND, - .state = { .unbound = { /* No additional state. */ } }, - } }, - }; + descriptor_table_entry_t entry = { .tag = DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, .tcp_socket = { + .socket = socket, + .socket_pollable = socket_pollable, + .blocking = blocking, + .state = { .tag = TCP_SOCKET_STATE_UNBOUND, .unbound = { /* No additional state. */ } }, + } }; int fd; if (!descriptor_table_insert(entry, &fd)) { diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c index 81ca778a9..89eab0652 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -42,7 +42,7 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, break; } case SO_ERROR: { - if (socket->state_tag == TCP_SOCKET_STATE_CONNECT_FAILED) { + if (socket->state.tag == TCP_SOCKET_STATE_CONNECT_FAILED) { value = __wasi_sockets_utils__map_error(socket->state.connect_failed.error_code); socket->state.connect_failed.error_code = 0; } else { @@ -51,7 +51,7 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, break; } case SO_ACCEPTCONN: { - bool is_listening = socket->state_tag == TCP_SOCKET_STATE_LISTENING; + bool is_listening = socket->state.tag == TCP_SOCKET_STATE_LISTENING; assert(is_listening == tcp_method_tcp_socket_is_listening(socket_borrow)); // Sanity check. value = is_listening; break; @@ -511,9 +511,9 @@ int getsockopt(int sockfd, int level, int optname, switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - return tcp_getsockopt(&entry->value.tcp_socket, level, optname, optval, optlen); + return tcp_getsockopt(&entry->tcp_socket, level, optname, optval, optlen); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - return udp_getsockopt(&entry->value.udp_socket, level, optname, optval, optlen); + return udp_getsockopt(&entry->udp_socket, level, optname, optval, optlen); default: errno = ENOPROTOOPT; return -1; @@ -537,9 +537,9 @@ int setsockopt(int sockfd, int level, int optname, const void* optval, socklen_t switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - return tcp_setsockopt(&entry->value.tcp_socket, level, optname, optval, optlen); + return tcp_setsockopt(&entry->tcp_socket, level, optname, optval, optlen); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - return udp_setsockopt(&entry->value.udp_socket, level, optname, optval, optlen); + return udp_setsockopt(&entry->udp_socket, level, optname, optval, optlen); default: errno = ENOPROTOOPT; return -1; diff --git a/libc-bottom-half/headers/private/descriptor_table.h b/libc-bottom-half/headers/private/descriptor_table.h index 9c3f84172..d5bbf905e 100644 --- a/libc-bottom-half/headers/private/descriptor_table.h +++ b/libc-bottom-half/headers/private/descriptor_table.h @@ -3,15 +3,6 @@ #include -typedef enum { - TCP_SOCKET_STATE_UNBOUND, - TCP_SOCKET_STATE_BOUND, - TCP_SOCKET_STATE_CONNECTING, - TCP_SOCKET_STATE_CONNECTED, - TCP_SOCKET_STATE_CONNECT_FAILED, - TCP_SOCKET_STATE_LISTENING, -} tcp_socket_state_tag_t; - typedef struct {} tcp_socket_state_unbound_t; typedef struct {} tcp_socket_state_bound_t; typedef struct {} tcp_socket_state_connecting_t; @@ -28,20 +19,30 @@ typedef struct { network_error_code_t error_code; } tcp_socket_state_connect_failed_t; -typedef union { - tcp_socket_state_unbound_t unbound; - tcp_socket_state_bound_t bound; - tcp_socket_state_connecting_t connecting; - tcp_socket_state_connected_t connected; - tcp_socket_state_connect_failed_t connect_failed; - tcp_socket_state_listening_t listening; +// This is a tagged union. When adding/removing/renaming cases, be sure to keep the tag and union definitions in sync. +typedef struct { + enum { + TCP_SOCKET_STATE_UNBOUND, + TCP_SOCKET_STATE_BOUND, + TCP_SOCKET_STATE_CONNECTING, + TCP_SOCKET_STATE_CONNECTED, + TCP_SOCKET_STATE_CONNECT_FAILED, + TCP_SOCKET_STATE_LISTENING, + } tag; + union { + tcp_socket_state_unbound_t unbound; + tcp_socket_state_bound_t bound; + tcp_socket_state_connecting_t connecting; + tcp_socket_state_connected_t connected; + tcp_socket_state_connect_failed_t connect_failed; + tcp_socket_state_listening_t listening; + }; } tcp_socket_state_t; typedef struct { tcp_own_tcp_socket_t socket; poll_own_pollable_t socket_pollable; bool blocking; - tcp_socket_state_tag_t state_tag; tcp_socket_state_t state; } tcp_socket_t; @@ -54,19 +55,16 @@ typedef struct { } udp_socket_t; -typedef enum { - DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, - DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET, -} descriptor_table_entry_tag_t; - -typedef union { - tcp_socket_t tcp_socket; - udp_socket_t udp_socket; -} descriptor_table_entry_value_t; - +// This is a tagged union. When adding/removing/renaming cases, be sure to keep the tag and union definitions in sync. typedef struct { - descriptor_table_entry_tag_t tag; - descriptor_table_entry_value_t value; + enum { + DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, + DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET, + } tag; + union { + tcp_socket_t tcp_socket; + udp_socket_t udp_socket; + }; } descriptor_table_entry_t; bool descriptor_table_insert(descriptor_table_entry_t entry, int* fd); diff --git a/libc-bottom-half/sources/__wasilibc_fd_renumber.c b/libc-bottom-half/sources/__wasilibc_fd_renumber.c index f934c78d1..ed41f781c 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) { } void drop_tcp_socket(tcp_socket_t socket) { - switch (socket.state_tag) { + switch (socket.state.tag) { case TCP_SOCKET_STATE_UNBOUND: case TCP_SOCKET_STATE_BOUND: case TCP_SOCKET_STATE_CONNECTING: @@ -56,10 +56,10 @@ int close(int fd) { switch (entry.tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - drop_tcp_socket(entry.value.tcp_socket); + drop_tcp_socket(entry.tcp_socket); break; case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - drop_udp_socket(entry.value.udp_socket); + drop_udp_socket(entry.udp_socket); break; default: /* unreachable */ abort(); } From 1e97c2ea2d33af7fb229420ab0ee9b048bbc6e52 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Wed, 6 Dec 2023 11:23:55 +0100 Subject: [PATCH 22/63] Open & close UDP sockets --- .../cloudlibc/src/libc/sys/socket/socket.c | 26 ++++++++++++-- .../headers/private/descriptor_table.h | 34 +++++++++++++++++++ .../sources/__wasilibc_fd_renumber.c | 24 ++++++++++++- 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c index d1871b4f2..d6027e0d2 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c @@ -33,9 +33,29 @@ int tcp_socket(network_ip_address_family_t family, bool blocking) int udp_socket(network_ip_address_family_t family, bool blocking) { - // TODO wasi-sockets: implement - errno = EPROTONOSUPPORT; - return -1; + udp_create_socket_error_code_t error; + udp_own_udp_socket_t socket; + if (!udp_create_socket_create_udp_socket(family, &socket, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + udp_borrow_udp_socket_t socket_borrow = udp_borrow_udp_socket(socket); + poll_own_pollable_t socket_pollable = udp_method_udp_socket_subscribe(socket_borrow); + + descriptor_table_entry_t entry = { .tag = DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET, .udp_socket = { + .socket = socket, + .socket_pollable = socket_pollable, + .blocking = blocking, + .state = { .tag = UDP_SOCKET_STATE_UNBOUND, .unbound = { /* No additional state. */ } }, + } }; + + int fd; + if (!descriptor_table_insert(entry, &fd)) { + errno = EMFILE; + return -1; + } + return fd; } diff --git a/libc-bottom-half/headers/private/descriptor_table.h b/libc-bottom-half/headers/private/descriptor_table.h index d5bbf905e..b18259223 100644 --- a/libc-bottom-half/headers/private/descriptor_table.h +++ b/libc-bottom-half/headers/private/descriptor_table.h @@ -49,12 +49,46 @@ typedef struct { +typedef struct { + udp_own_incoming_datagram_stream_t incoming; + poll_own_pollable_t incoming_pollable; + udp_own_outgoing_datagram_stream_t outgoing; + poll_own_pollable_t outgoing_pollable; +} udp_socket_streams_t; + +typedef struct {} udp_socket_state_unbound_t; + +typedef struct { + udp_socket_streams_t streams; +} udp_socket_state_bound_t; + +typedef struct { + udp_socket_streams_t streams; +} udp_socket_state_connected_t; + +// This is a tagged union. When adding/removing/renaming cases, be sure to keep the tag and union definitions in sync. +typedef struct { + enum { + UDP_SOCKET_STATE_UNBOUND, + UDP_SOCKET_STATE_BOUND, + UDP_SOCKET_STATE_CONNECTED, + } tag; + union { + udp_socket_state_unbound_t unbound; + udp_socket_state_bound_t bound; + udp_socket_state_connected_t connected; + }; +} udp_socket_state_t; + typedef struct { udp_own_udp_socket_t socket; + poll_own_pollable_t socket_pollable; bool blocking; + udp_socket_state_t state; } udp_socket_t; + // This is a tagged union. When adding/removing/renaming cases, be sure to keep the tag and union definitions in sync. typedef struct { enum { diff --git a/libc-bottom-half/sources/__wasilibc_fd_renumber.c b/libc-bottom-half/sources/__wasilibc_fd_renumber.c index ed41f781c..8a2c9ca74 100644 --- a/libc-bottom-half/sources/__wasilibc_fd_renumber.c +++ b/libc-bottom-half/sources/__wasilibc_fd_renumber.c @@ -42,8 +42,30 @@ void drop_tcp_socket(tcp_socket_t socket) { tcp_tcp_socket_drop_own(socket.socket); } +void drop_udp_socket_streams(udp_socket_streams_t streams) { + poll_pollable_drop_own(streams.incoming_pollable); + poll_pollable_drop_own(streams.outgoing_pollable); + udp_incoming_datagram_stream_drop_own(streams.incoming); + udp_outgoing_datagram_stream_drop_own(streams.outgoing); +} + void drop_udp_socket(udp_socket_t socket) { - abort(); // TODO + switch (socket.state.tag) { + case UDP_SOCKET_STATE_UNBOUND: + // No additional resources to drop. + break; + case UDP_SOCKET_STATE_BOUND: + drop_udp_socket_streams(socket.state.bound.streams); + break; + case UDP_SOCKET_STATE_CONNECTED: { + drop_udp_socket_streams(socket.state.connected.streams); + break; + } + default: /* unreachable */ abort(); + } + + poll_pollable_drop_own(socket.socket_pollable); + udp_udp_socket_drop_own(socket.socket); } int close(int fd) { From e0f43141700bb754011fee8863f5456986960550 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Wed, 6 Dec 2023 12:00:44 +0100 Subject: [PATCH 23/63] UDP socket options --- .../cloudlibc/src/libc/sys/socket/sockopt.c | 172 ++++++++++++++++-- 1 file changed, 157 insertions(+), 15 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c index 89eab0652..94c1b32e0 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -395,19 +395,55 @@ int udp_getsockopt(udp_socket_t* socket, int level, int optname, { int value; + network_error_code_t error; + udp_borrow_udp_socket_t socket_borrow = udp_borrow_udp_socket(socket->socket); + switch (level) { case SOL_SOCKET: switch (optname) { - case SO_TYPE: - value = SOCK_STREAM; + case SO_TYPE: { + value = SOCK_DGRAM; break; - case SO_PROTOCOL: - value = IPPROTO_TCP; + } + case SO_PROTOCOL: { + value = IPPROTO_UDP; + break; + } + case SO_DOMAIN: { + value = __wasi_sockets_utils__posix_family( + udp_method_udp_socket_address_family(socket_borrow) + ); + break; + } + case SO_RCVBUF: { + uint64_t result; + if (!udp_method_udp_socket_receive_buffer_size(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + if (result > INT_MAX) { + abort(); + } + + value = result; + break; + } + case SO_SNDBUF: { + uint64_t result; + if (!udp_method_udp_socket_send_buffer_size(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + if (result > INT_MAX) { + abort(); + } + + value = result; break; - case SO_DOMAIN: // TODO wasi-sockets: implement - case SO_RCVBUF: // TODO wasi-sockets: implement - case SO_SNDBUF: // TODO wasi-sockets: implement + } case SO_RCVTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself case SO_SNDTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself default: @@ -419,7 +455,23 @@ int udp_getsockopt(udp_socket_t* socket, int level, int optname, case SOL_IP: switch (optname) { - case IP_TTL: // TODO wasi-sockets: implement + case IP_TTL: { + if (udp_method_udp_socket_address_family(socket_borrow) + != NETWORK_IP_ADDRESS_FAMILY_IPV4) + { + errno = EAFNOSUPPORT; + return -1; + } + + uint8_t result; + if (!udp_method_udp_socket_unicast_hop_limit(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + value = result; + break; + } default: errno = ENOPROTOOPT; return -1; @@ -429,8 +481,33 @@ int udp_getsockopt(udp_socket_t* socket, int level, int optname, case SOL_IPV6: switch (optname) { - case IPV6_V6ONLY: // TODO wasi-sockets: implement - case IPV6_UNICAST_HOPS: // TODO wasi-sockets: implement + case IPV6_UNICAST_HOPS: { + if (udp_method_udp_socket_address_family(socket_borrow) + != NETWORK_IP_ADDRESS_FAMILY_IPV6) + { + errno = EAFNOSUPPORT; + return -1; + } + + uint8_t result; + if (!udp_method_udp_socket_unicast_hop_limit(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + value = result; + break; + } + case IPV6_V6ONLY: { + bool result; + if (!udp_method_udp_socket_ipv6_only(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + value = result; + break; + } default: errno = ENOPROTOOPT; return -1; @@ -451,12 +528,32 @@ int udp_getsockopt(udp_socket_t* socket, int level, int optname, } int udp_setsockopt(udp_socket_t* socket, int level, int optname, const void* optval, socklen_t optlen) { + + int intval = *(int*)optval; + + network_error_code_t error; + udp_borrow_udp_socket_t socket_borrow = udp_borrow_udp_socket(socket->socket); + switch (level) { case SOL_SOCKET: switch (optname) { - case SO_RCVBUF: // TODO wasi-sockets: implement - case SO_SNDBUF: // TODO wasi-sockets: implement + case SO_RCVBUF: { + if (!udp_method_udp_socket_set_receive_buffer_size(socket_borrow, intval, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } + case SO_SNDBUF: { + if (!udp_method_udp_socket_set_send_buffer_size(socket_borrow, intval, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } case SO_RCVTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself case SO_SNDTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself default: @@ -468,7 +565,26 @@ int udp_setsockopt(udp_socket_t* socket, int level, int optname, const void* opt case SOL_IP: switch (optname) { - case IP_TTL: // TODO wasi-sockets: implement + case IP_TTL: { + if (udp_method_udp_socket_address_family(socket_borrow) + != NETWORK_IP_ADDRESS_FAMILY_IPV4) + { + errno = EAFNOSUPPORT; + return -1; + } + + if (intval < 0 || intval > UINT8_MAX) { + errno = EINVAL; + return -1; + } + + if (!udp_method_udp_socket_set_unicast_hop_limit(socket_borrow, intval, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } default: errno = ENOPROTOOPT; return -1; @@ -478,8 +594,34 @@ int udp_setsockopt(udp_socket_t* socket, int level, int optname, const void* opt case SOL_IPV6: switch (optname) { - case IPV6_V6ONLY: // TODO wasi-sockets: implement - case IPV6_UNICAST_HOPS: // TODO wasi-sockets: implement + case IPV6_UNICAST_HOPS: { + if (udp_method_udp_socket_address_family(socket_borrow) + != NETWORK_IP_ADDRESS_FAMILY_IPV6) + { + errno = EAFNOSUPPORT; + return -1; + } + + if (intval < 0 || intval > UINT8_MAX) { + errno = EINVAL; + return -1; + } + + if (!udp_method_udp_socket_set_unicast_hop_limit(socket_borrow, intval, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } + case IPV6_V6ONLY: { + if (!udp_method_udp_socket_set_ipv6_only(socket_borrow, intval != 0, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + return 0; + } default: errno = ENOPROTOOPT; return -1; From c11533a4096be987b822933653331c8c833bc63c Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Wed, 6 Dec 2023 12:47:15 +0100 Subject: [PATCH 24/63] Keep track of the address family ourselves, because we'll need it quite often for input validation. --- .../cloudlibc/src/libc/sys/socket/accept.c | 1 + .../cloudlibc/src/libc/sys/socket/listen.c | 3 +- .../cloudlibc/src/libc/sys/socket/socket.c | 2 ++ .../cloudlibc/src/libc/sys/socket/sockopt.c | 32 ++++++------------- .../headers/private/descriptor_table.h | 2 ++ 5 files changed, 16 insertions(+), 24 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c index 55e467a5e..be8e7f7d5 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c @@ -58,6 +58,7 @@ bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, n .socket = client, .socket_pollable = client_pollable, .blocking = client_blocking, + .family = socket->family, .state = { .tag = TCP_SOCKET_STATE_CONNECTED, .connected = { .input = input, .input_pollable = input_pollable, diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c index d026e9c26..8e5884a27 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/listen.c @@ -14,8 +14,7 @@ int tcp_listen(tcp_socket_t* socket, int backlog) { case TCP_SOCKET_STATE_UNBOUND: { // Socket is not explicitly bound by the user. We'll do it for them: - tcp_ip_address_family_t family = tcp_method_tcp_socket_address_family(socket_borrow); - network_ip_socket_address_t any = __wasi_sockets_utils__any_addr(family); + network_ip_socket_address_t any = __wasi_sockets_utils__any_addr(socket->family); int result = __wasi_sockets_utils__tcp_bind(socket, &any); if (result != 0) { return result; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c index d6027e0d2..b477297cf 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c @@ -20,6 +20,7 @@ int tcp_socket(network_ip_address_family_t family, bool blocking) .socket = socket, .socket_pollable = socket_pollable, .blocking = blocking, + .family = family, .state = { .tag = TCP_SOCKET_STATE_UNBOUND, .unbound = { /* No additional state. */ } }, } }; @@ -47,6 +48,7 @@ int udp_socket(network_ip_address_family_t family, bool blocking) .socket = socket, .socket_pollable = socket_pollable, .blocking = blocking, + .family = family, .state = { .tag = UDP_SOCKET_STATE_UNBOUND, .unbound = { /* No additional state. */ } }, } }; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c index 94c1b32e0..8319584f6 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -36,9 +36,7 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, break; } case SO_DOMAIN: { - value = __wasi_sockets_utils__posix_family( - tcp_method_tcp_socket_address_family(socket_borrow) - ); + value = __wasi_sockets_utils__posix_family(socket->family); break; } case SO_ERROR: { @@ -106,8 +104,7 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, case SOL_IP: switch (optname) { case IP_TTL: { - if (tcp_method_tcp_socket_address_family(socket_borrow) - != NETWORK_IP_ADDRESS_FAMILY_IPV4) + if (socket->family != NETWORK_IP_ADDRESS_FAMILY_IPV4) { errno = EAFNOSUPPORT; return -1; @@ -132,8 +129,7 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, case SOL_IPV6: switch (optname) { case IPV6_UNICAST_HOPS: { - if (tcp_method_tcp_socket_address_family(socket_borrow) - != NETWORK_IP_ADDRESS_FAMILY_IPV6) + if (socket->family != NETWORK_IP_ADDRESS_FAMILY_IPV6) { errno = EAFNOSUPPORT; return -1; @@ -286,8 +282,7 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt case SOL_IP: switch (optname) { case IP_TTL: { - if (tcp_method_tcp_socket_address_family(socket_borrow) - != NETWORK_IP_ADDRESS_FAMILY_IPV4) + if (socket->family != NETWORK_IP_ADDRESS_FAMILY_IPV4) { errno = EAFNOSUPPORT; return -1; @@ -315,8 +310,7 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt case SOL_IPV6: switch (optname) { case IPV6_UNICAST_HOPS: { - if (tcp_method_tcp_socket_address_family(socket_borrow) - != NETWORK_IP_ADDRESS_FAMILY_IPV6) + if (socket->family != NETWORK_IP_ADDRESS_FAMILY_IPV6) { errno = EAFNOSUPPORT; return -1; @@ -411,9 +405,7 @@ int udp_getsockopt(udp_socket_t* socket, int level, int optname, break; } case SO_DOMAIN: { - value = __wasi_sockets_utils__posix_family( - udp_method_udp_socket_address_family(socket_borrow) - ); + value = __wasi_sockets_utils__posix_family(socket->family); break; } case SO_RCVBUF: { @@ -456,8 +448,7 @@ int udp_getsockopt(udp_socket_t* socket, int level, int optname, case SOL_IP: switch (optname) { case IP_TTL: { - if (udp_method_udp_socket_address_family(socket_borrow) - != NETWORK_IP_ADDRESS_FAMILY_IPV4) + if (socket->family != NETWORK_IP_ADDRESS_FAMILY_IPV4) { errno = EAFNOSUPPORT; return -1; @@ -482,8 +473,7 @@ int udp_getsockopt(udp_socket_t* socket, int level, int optname, case SOL_IPV6: switch (optname) { case IPV6_UNICAST_HOPS: { - if (udp_method_udp_socket_address_family(socket_borrow) - != NETWORK_IP_ADDRESS_FAMILY_IPV6) + if (socket->family != NETWORK_IP_ADDRESS_FAMILY_IPV6) { errno = EAFNOSUPPORT; return -1; @@ -566,8 +556,7 @@ int udp_setsockopt(udp_socket_t* socket, int level, int optname, const void* opt case SOL_IP: switch (optname) { case IP_TTL: { - if (udp_method_udp_socket_address_family(socket_borrow) - != NETWORK_IP_ADDRESS_FAMILY_IPV4) + if (socket->family != NETWORK_IP_ADDRESS_FAMILY_IPV4) { errno = EAFNOSUPPORT; return -1; @@ -595,8 +584,7 @@ int udp_setsockopt(udp_socket_t* socket, int level, int optname, const void* opt case SOL_IPV6: switch (optname) { case IPV6_UNICAST_HOPS: { - if (udp_method_udp_socket_address_family(socket_borrow) - != NETWORK_IP_ADDRESS_FAMILY_IPV6) + if (socket->family != NETWORK_IP_ADDRESS_FAMILY_IPV6) { errno = EAFNOSUPPORT; return -1; diff --git a/libc-bottom-half/headers/private/descriptor_table.h b/libc-bottom-half/headers/private/descriptor_table.h index b18259223..8db7a5ae8 100644 --- a/libc-bottom-half/headers/private/descriptor_table.h +++ b/libc-bottom-half/headers/private/descriptor_table.h @@ -43,6 +43,7 @@ typedef struct { tcp_own_tcp_socket_t socket; poll_own_pollable_t socket_pollable; bool blocking; + network_ip_address_family_t family; tcp_socket_state_t state; } tcp_socket_t; @@ -84,6 +85,7 @@ typedef struct { udp_own_udp_socket_t socket; poll_own_pollable_t socket_pollable; bool blocking; + network_ip_address_family_t family; udp_socket_state_t state; } udp_socket_t; From 4fc628c06a4a263e8d3e352f4db4bbd337598bb2 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Wed, 6 Dec 2023 15:26:32 +0100 Subject: [PATCH 25/63] Refactor sockaddr validation: - On input addresses: check against the expected address family and return EAFNOSUPPORT when mismatch - On output addresses: perform validations _before_ making the actual syscall. --- .../cloudlibc/src/libc/sys/socket/__utils.c | 116 ++++++++++++------ .../cloudlibc/src/libc/sys/socket/__utils.h | 18 ++- .../cloudlibc/src/libc/sys/socket/accept.c | 82 +++++-------- .../cloudlibc/src/libc/sys/socket/bind.c | 25 ++-- .../cloudlibc/src/libc/sys/socket/connect.c | 26 ++-- .../src/libc/sys/socket/getsockpeername.c | 102 +++++++-------- 6 files changed, 188 insertions(+), 181 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c index ec6218690..656e551b6 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c @@ -1,3 +1,4 @@ +#include #include #include "__utils.h" @@ -50,18 +51,22 @@ int __wasi_sockets_utils__map_error(network_error_code_t wasi_error) { } } -bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen_t len, network_ip_socket_address_t* output, int* error) +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) { - *error = 0; - - socklen_t smallest_sockaddr_size = sizeof(struct sockaddr); - if (address == NULL || len < smallest_sockaddr_size) { + if (address == NULL || len < sizeof(struct sockaddr)) { *error = EINVAL; return false; } + + switch (expected_family) + { + case NETWORK_IP_ADDRESS_FAMILY_IPV4: { + + if (address->sa_family != AF_INET) { + *error = EAFNOSUPPORT; + return false; + } - switch (address->sa_family) { - case AF_INET: { if (len < sizeof(struct sockaddr_in)) { *error = EINVAL; return false; @@ -70,7 +75,7 @@ bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen struct sockaddr_in* ipv4 = (struct sockaddr_in*)address; unsigned ip = ipv4->sin_addr.s_addr; unsigned short port = ipv4->sin_port; - *output = (network_ip_socket_address_t){ + *result = (network_ip_socket_address_t){ .tag = NETWORK_IP_SOCKET_ADDRESS_IPV4, .val = { .ipv4 = { .port = ntohs(port), // (port << 8) | (port >> 8), @@ -79,7 +84,13 @@ bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen }; return true; } - case AF_INET6: { + case NETWORK_IP_ADDRESS_FAMILY_IPV6: { + + if (address->sa_family != AF_INET6) { + *error = EAFNOSUPPORT; + return false; + } + if (len < sizeof(struct sockaddr_in6)) { *error = EINVAL; return false; @@ -88,7 +99,7 @@ bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)address; unsigned char* ip = (unsigned char*)&(ipv6->sin6_addr.s6_addr); unsigned short port = ipv6->sin6_port; - *output = (network_ip_socket_address_t){ + *result = (network_ip_socket_address_t){ .tag = NETWORK_IP_SOCKET_ADDRESS_IPV6, .val = { .ipv6 = { .port = ntohs(port), @@ -109,52 +120,77 @@ bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen }; return true; } - default: - *error = EAFNOSUPPORT; - return false; + default: /* unreachable */ abort(); } } -bool __wasi_sockets_utils__format_address(const network_ip_socket_address_t* address, struct sockaddr* output_addr, socklen_t* output_addrlen, int* error) { - *error = 0; +bool __wasi_sockets_utils__output_addr_validate(network_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. - if (output_addr == NULL || output_addrlen == NULL) { - *error = EINVAL; + if (addr == NULL && addrlen == NULL) { + *result = (output_sockaddr_t){ .tag = OUTPUT_SOCKADDR_NULL, .null = {} }; + return true; + + } else if (addr != NULL && addrlen != NULL) { + + if (expected_family == NETWORK_IP_ADDRESS_FAMILY_IPV4) { + if (*addrlen < sizeof(struct sockaddr_in)) { + return false; + } + + *result = (output_sockaddr_t){ .tag = OUTPUT_SOCKADDR_V4, .v4 = { + .addr = (struct sockaddr_in*)addr, + .addrlen = addrlen, + } }; + return true; + + } else if (expected_family == NETWORK_IP_ADDRESS_FAMILY_IPV6) { + if (*addrlen < sizeof(struct sockaddr_in6)) { + return false; + } + + *result = (output_sockaddr_t){ .tag = OUTPUT_SOCKADDR_V6, .v6 = { + .addr = (struct sockaddr_in6*)addr, + .addrlen = addrlen, + } }; + return true; + + } else { + abort(); + } + + } else { return false; } +} - switch (address->tag) +void __wasi_sockets_utils__output_addr_write(const network_ip_socket_address_t input, output_sockaddr_t* output) { + switch (input.tag) { case NETWORK_IP_SOCKET_ADDRESS_IPV4: { - if (*output_addrlen < sizeof(struct sockaddr_in)) { - *error = EINVAL; - return false; - } - *output_addrlen = sizeof(struct sockaddr_in); - struct sockaddr_in* ipv4 = (struct sockaddr_in*)output_addr; + assert(output->tag == OUTPUT_SOCKADDR_V4); - network_ipv4_address_t ip = address->val.ipv4.address; + network_ipv4_socket_address_t input_v4 = input.val.ipv4; + network_ipv4_address_t ip = input_v4.address; - *ipv4 = (struct sockaddr_in) { + *output->v4.addrlen = sizeof(struct sockaddr_in); + *output->v4.addr = (struct sockaddr_in) { .sin_family = AF_INET, - .sin_port = htons(address->val.ipv4.port), + .sin_port = htons(input_v4.port), .sin_addr = { .s_addr = ip.f0 | (ip.f1 << 8) | (ip.f2 << 16) | (ip.f3 << 24) }, }; - return true; + return; } case NETWORK_IP_SOCKET_ADDRESS_IPV6: { - if (*output_addrlen < sizeof(struct sockaddr_in6)) { - *error = EINVAL; - return false; - } - *output_addrlen = sizeof(struct sockaddr_in6); - struct sockaddr_in6* ipv6 = (struct sockaddr_in6*)output_addr; + assert(output->tag == OUTPUT_SOCKADDR_V6); - network_ipv6_address_t ip = address->val.ipv6.address; + network_ipv6_socket_address_t input_v6 = input.val.ipv6; + network_ipv6_address_t ip = input_v6.address; - *ipv6 = (struct sockaddr_in6) { + *output->v6.addrlen = sizeof(struct sockaddr_in6); + *output->v6.addr = (struct sockaddr_in6) { .sin6_family = AF_INET, - .sin6_port = htons(address->val.ipv6.port), + .sin6_port = htons(input_v6.port), .sin6_addr = { .s6_addr = { ip.f0 >> 8, ip.f0 & 0xFF, ip.f1 >> 8, ip.f1 & 0xFF, @@ -166,10 +202,10 @@ bool __wasi_sockets_utils__format_address(const network_ip_socket_address_t* add ip.f7 >> 8, ip.f7 & 0xFF, } }, // TODO wasi-sockets: do these need to be endian-reversed? - .sin6_flowinfo = address->val.ipv6.flow_info, - .sin6_scope_id = address->val.ipv6.scope_id, + .sin6_flowinfo = input_v6.flow_info, + .sin6_scope_id = input_v6.scope_id, }; - return true; + return; } default: /* unreachable */ abort(); } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h index 051b28932..0c92c478e 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h @@ -5,10 +5,24 @@ #include +typedef struct { + enum { + OUTPUT_SOCKADDR_NULL, + OUTPUT_SOCKADDR_V4, + OUTPUT_SOCKADDR_V6, + } tag; + union { + struct {} null; + struct { struct sockaddr_in* addr; socklen_t* addrlen; } v4; + struct { struct sockaddr_in6* addr; socklen_t* addrlen; } v6; + }; +} output_sockaddr_t; + network_borrow_network_t __wasi_sockets_utils__borrow_network(); int __wasi_sockets_utils__map_error(network_error_code_t wasi_error); -bool __wasi_sockets_utils__parse_address(const struct sockaddr* address, socklen_t len, network_ip_socket_address_t* output, int* error); -bool __wasi_sockets_utils__format_address(const network_ip_socket_address_t* address, struct sockaddr* output_addr, socklen_t* output_addrlen, int* error); +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); +bool __wasi_sockets_utils__output_addr_validate(network_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); int __wasi_sockets_utils__tcp_bind(tcp_socket_t* socket, network_ip_socket_address_t* address); diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c index be8e7f7d5..85cee68b4 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c @@ -5,14 +5,20 @@ #include #include "__utils.h" -bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, network_ip_socket_address_t* out_address, int* out_errno) { +int tcp_accept(tcp_socket_t* socket, bool client_blocking, struct sockaddr* addr, socklen_t* addrlen) { + + output_sockaddr_t output_addr; + if (!__wasi_sockets_utils__output_addr_validate(socket->family, addr, addrlen, &output_addr)) { + errno = EINVAL; + return -1; + } tcp_socket_state_listening_t listener; if (socket->state.tag == TCP_SOCKET_STATE_LISTENING) { listener = socket->state.listening; } else { - *out_errno = EINVAL; - return false; + errno = EINVAL; + return -1; } tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); @@ -25,12 +31,12 @@ bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, n poll_borrow_pollable_t pollable_borrow = poll_borrow_pollable(socket->socket_pollable); poll_method_pollable_block(pollable_borrow); } else { - *out_errno = EWOULDBLOCK; - return false; + errno = EWOULDBLOCK; + return -1; } } else { - *out_errno = __wasi_sockets_utils__map_error(error); - return false; + errno = __wasi_sockets_utils__map_error(error); + return -1; } } @@ -47,11 +53,14 @@ bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, n streams_borrow_output_stream_t output_borrow = streams_borrow_output_stream(output); poll_own_pollable_t output_pollable = streams_method_output_stream_subscribe(output_borrow); - if (out_address != NULL) { - if (!tcp_method_tcp_socket_remote_address(client_borrow, out_address, &error)) { + if (output_addr.tag != OUTPUT_SOCKADDR_NULL) { + network_ip_socket_address_t remote_address; + if (!tcp_method_tcp_socket_remote_address(client_borrow, &remote_address, &error)) { // TODO wasi-sockets: How to recover from this in a POSIX compatible way? abort(); } + + __wasi_sockets_utils__output_addr_write(remote_address, &output_addr); } descriptor_table_entry_t client_entry = { .tag = DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, .tcp_socket = { @@ -67,21 +76,21 @@ bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, n } }, } }; - if (!descriptor_table_insert(client_entry, out_clientfd)) { - *out_errno = EMFILE; - return false; + int client_fd; + if (!descriptor_table_insert(client_entry, &client_fd)) { + errno = EMFILE; + return -1; } - return true; + return client_fd; } -bool udp_accept(udp_socket_t* socket, bool client_blocking, int* out_clientfd, network_ip_socket_address_t* out_address, int* out_errno) { +int udp_accept(udp_socket_t* socket, bool client_blocking, struct sockaddr* addr, socklen_t* addrlen) { // UDP doesn't support accept - *out_errno = EOPNOTSUPP; - return false; + errno = EOPNOTSUPP; + return -1; } - int accept(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen) { return accept4(socket, addr, addrlen, 0); } @@ -94,52 +103,17 @@ int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addr return -1; } - if (addr != NULL) { - if (addrlen == NULL || *addrlen == 0) { - errno = EINVAL; - return -1; - } - } else { - if (addrlen != NULL && *addrlen == 0) { - errno = EINVAL; - return -1; - } - } - bool client_blocking = (flags & SOCK_NONBLOCK) == 0; // Ignore SOCK_CLOEXEC flag. That concept does not exist in WASI. - network_ip_socket_address_t out_address; - network_ip_socket_address_t* out_address_ptr = addr != NULL ? &out_address : NULL; - - int client_fd; - int err; switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - if (!tcp_accept(&entry->tcp_socket, client_blocking, &client_fd, out_address_ptr, &err)) { - errno = err; - return -1; - } - break; + return tcp_accept(&entry->tcp_socket, client_blocking, addr, addrlen); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - if (!udp_accept(&entry->udp_socket, client_blocking, &client_fd, out_address_ptr, &err)) { - errno = err; - return -1; - } - break; + return udp_accept(&entry->udp_socket, client_blocking, addr, addrlen); default: errno = EOPNOTSUPP; return -1; } - - if (addr != NULL) { - assert(out_address_ptr != NULL); - - if (!__wasi_sockets_utils__format_address(&out_address, addr, addrlen, &err)) { - abort(); // TODO wasi-sockets: validate provided buffer length _before_ doing the actual accept wasi call. - } - } - - return client_fd; } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c index 251902530..29f13c760 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c @@ -4,11 +4,19 @@ #include #include "__utils.h" -int tcp_bind(tcp_socket_t* socket, network_ip_socket_address_t* address) { - return __wasi_sockets_utils__tcp_bind(socket, address); +int tcp_bind(tcp_socket_t* socket, const struct sockaddr* addr, socklen_t addrlen) { + + network_ip_socket_address_t local_address; + int parse_err; + if (!__wasi_sockets_utils__parse_address(socket->family, addr, addrlen, &local_address, &parse_err)) { + errno = parse_err; + return -1; + } + + return __wasi_sockets_utils__tcp_bind(socket, &local_address); } -int udp_bind(udp_socket_t* socket, network_ip_socket_address_t* address) { +int udp_bind(udp_socket_t* socket, const struct sockaddr* addr, socklen_t addrlen) { // TODO wasi-sockets: implement errno = EOPNOTSUPP; return -1; @@ -22,19 +30,12 @@ int bind(int socket, const struct sockaddr* addr, socklen_t addrlen) { return -1; } - network_ip_socket_address_t ip_address; - int parse_err; - if (!__wasi_sockets_utils__parse_address(addr, addrlen, &ip_address, &parse_err)) { - errno = parse_err; - return -1; - } - switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - return tcp_bind(&entry->tcp_socket, &ip_address); + return tcp_bind(&entry->tcp_socket, addr, addrlen); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - return udp_bind(&entry->udp_socket, &ip_address); + return udp_bind(&entry->udp_socket, addr, addrlen); default: errno = EOPNOTSUPP; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c index d0b7a1339..c49c39067 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c @@ -5,8 +5,15 @@ #include "__utils.h" -int tcp_connect(tcp_socket_t* socket, network_ip_socket_address_t* address) +int tcp_connect(tcp_socket_t* socket, const struct sockaddr* addr, socklen_t addrlen) { + network_ip_socket_address_t remote_address; + int parse_err; + if (!__wasi_sockets_utils__parse_address(socket->family, addr, addrlen, &remote_address, &parse_err)) { + errno = parse_err; + return -1; + } + switch (socket->state.tag) { case TCP_SOCKET_STATE_UNBOUND: case TCP_SOCKET_STATE_BOUND: @@ -29,7 +36,7 @@ int tcp_connect(tcp_socket_t* socket, network_ip_socket_address_t* address) network_borrow_network_t network_borrow = __wasi_sockets_utils__borrow_network(); tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); - if (!tcp_method_tcp_socket_start_connect(socket_borrow, network_borrow, address, &error)) { + if (!tcp_method_tcp_socket_start_connect(socket_borrow, network_borrow, &remote_address, &error)) { errno = __wasi_sockets_utils__map_error(error); return -1; } @@ -78,14 +85,14 @@ int tcp_connect(tcp_socket_t* socket, network_ip_socket_address_t* address) return 0; } -int udp_connect(udp_socket_t* socket, network_ip_socket_address_t* address) +int udp_connect(udp_socket_t* socket, const struct sockaddr* addr, socklen_t addrlen) { // TODO wasi-sockets: implement errno = EOPNOTSUPP; return -1; } -int connect(int fd, const struct sockaddr* address, socklen_t len) +int connect(int fd, const struct sockaddr* addr, socklen_t addrlen) { descriptor_table_entry_t* entry; if (!descriptor_table_get_ref(fd, &entry)) { @@ -93,19 +100,12 @@ int connect(int fd, const struct sockaddr* address, socklen_t len) return -1; } - network_ip_socket_address_t ip_address; - int parse_err; - if (!__wasi_sockets_utils__parse_address(address, len, &ip_address, &parse_err)) { - errno = parse_err; - return -1; - } - switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - return tcp_connect(&entry->tcp_socket, &ip_address); + return tcp_connect(&entry->tcp_socket, addr, addrlen); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - return udp_connect(&entry->udp_socket, &ip_address); + return udp_connect(&entry->udp_socket, addr, addrlen); default: errno = EOPNOTSUPP; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c index d3976526f..e5b3c7999 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c @@ -4,38 +4,66 @@ #include #include "__utils.h" -bool tcp_getsockname(tcp_socket_t* socket, network_ip_socket_address_t* out_address) +int tcp_getsockname(tcp_socket_t* socket, struct sockaddr* addr, socklen_t* addrlen) { + output_sockaddr_t output_addr; + if (!__wasi_sockets_utils__output_addr_validate(socket->family, addr, addrlen, &output_addr)) { + errno = EINVAL; + return -1; + } + + if (output_addr.tag == OUTPUT_SOCKADDR_NULL) { + errno = EINVAL; + return -1; + } + network_error_code_t error; + network_ip_socket_address_t result; tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); - if (!tcp_method_tcp_socket_local_address(socket_borrow, out_address, &error)) { + if (!tcp_method_tcp_socket_local_address(socket_borrow, &result, &error)) { errno = __wasi_sockets_utils__map_error(error); - return false; + return -1; } - return true; + __wasi_sockets_utils__output_addr_write(result, &output_addr); + + return 0; } -bool tcp_getpeername(tcp_socket_t* socket, network_ip_socket_address_t* out_address) +int tcp_getpeername(tcp_socket_t* socket, struct sockaddr* addr, socklen_t* addrlen) { + output_sockaddr_t output_addr; + if (!__wasi_sockets_utils__output_addr_validate(socket->family, addr, addrlen, &output_addr)) { + errno = EINVAL; + return -1; + } + + if (output_addr.tag == OUTPUT_SOCKADDR_NULL) { + errno = EINVAL; + return -1; + } + network_error_code_t error; + network_ip_socket_address_t result; tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); - if (!tcp_method_tcp_socket_remote_address(socket_borrow, out_address, &error)) { + if (!tcp_method_tcp_socket_remote_address(socket_borrow, &result, &error)) { errno = __wasi_sockets_utils__map_error(error); - return false; + return -1; } - return true; + __wasi_sockets_utils__output_addr_write(result, &output_addr); + + return 0; } -bool udp_getsockname(udp_socket_t* socket, network_ip_socket_address_t* out_address) +int udp_getsockname(udp_socket_t* socket, struct sockaddr* addr, socklen_t* addrlen) { // TODO wasi-sockets: implement errno = EOPNOTSUPP; return -1; } -bool udp_getpeername(udp_socket_t* socket, network_ip_socket_address_t* out_address) +int udp_getpeername(udp_socket_t* socket, struct sockaddr* addr, socklen_t* addrlen) { // TODO wasi-sockets: implement errno = EOPNOTSUPP; @@ -50,39 +78,16 @@ int getsockname(int socket, struct sockaddr *__restrict addr, socklen_t *__restr return -1; } - if (addr == NULL || addrlen == NULL || *addrlen == 0) { - errno = EINVAL; - return -1; - } - - network_ip_socket_address_t out_address; - switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - if (!tcp_getsockname(&entry->tcp_socket, &out_address)) { - // errno is set by tcp_getsockname - return -1; - } - break; + return tcp_getsockname(&entry->tcp_socket, addr, addrlen); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - if (!udp_getsockname(&entry->udp_socket, &out_address)) { - // errno is set by udp_getsockname - return -1; - } - break; + return udp_getsockname(&entry->udp_socket, addr, addrlen); default: errno = EOPNOTSUPP; return -1; } - - int err; - if (!__wasi_sockets_utils__format_address(&out_address, addr, addrlen, &err)) { - errno = err; - return -1; - } - - return 0; } int getpeername(int socket, struct sockaddr *__restrict addr, socklen_t *__restrict addrlen) @@ -93,37 +98,14 @@ int getpeername(int socket, struct sockaddr *__restrict addr, socklen_t *__restr return -1; } - if (addr == NULL || addrlen == NULL || *addrlen == 0) { - errno = EINVAL; - return -1; - } - - network_ip_socket_address_t out_address; - switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - if (!tcp_getpeername(&entry->tcp_socket, &out_address)) { - // errno is set by tcp_getpeername - return -1; - } - break; + return tcp_getpeername(&entry->tcp_socket, addr, addrlen); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - if (!udp_getpeername(&entry->udp_socket, &out_address)) { - // errno is set by udp_getpeername - return -1; - } - break; + return udp_getpeername(&entry->udp_socket, addr, addrlen); default: errno = EOPNOTSUPP; return -1; } - - int err; - if (!__wasi_sockets_utils__format_address(&out_address, addr, addrlen, &err)) { - errno = err; - return -1; - } - - return 0; } From ebb3e3f61cab4ace5693de21b5e47a1d03277fbd Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 6 Dec 2023 17:25:47 -0700 Subject: [PATCH 26/63] add basic `TCP_NODELAY` support to `setsockopt` Signed-off-by: Joel Dice --- .../cloudlibc/src/libc/sys/socket/sockopt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c index 81ca778a9..31de528af 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -351,6 +351,16 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt case SOL_TCP: switch (optname) { + case TCP_NODELAY: { + if (intval == 0) { + errno = EDOM; + return -1; + } else { + // Do nothing -- WASI sockets always have no-delay enabled. + return 0; + } + } + case TCP_KEEPIDLE: { tcp_duration_t duration = intval * NS_PER_S; if (!tcp_method_tcp_socket_set_keep_alive_idle_time(socket_borrow, duration, &error)) { From 253f89597d6501460fc3f855a419e0aa09b571ce Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 6 Dec 2023 17:26:17 -0700 Subject: [PATCH 27/63] add netdb.h-related stubs Signed-off-by: Joel Dice --- .../cloudlibc/src/libc/sys/socket/netdb.c | 50 +++++++++++++++++-- .../headers/public/__header_sys_socket.h | 2 + libc-top-half/musl/include/netdb.h | 5 ++ make-bindings.sh | 40 +++++++++++++++ 4 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 make-bindings.sh diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c index 794f3d8a1..c4752bb62 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c @@ -1,14 +1,58 @@ -#include #include +#include -int getaddrinfo(const char *restrict host, const char *restrict serv, const struct addrinfo *restrict hint, struct addrinfo **restrict res) +_Thread_local int h_errno = 0; + +int getaddrinfo(const char* restrict host, const char* restrict serv, const struct addrinfo* restrict hint, struct addrinfo** restrict res) { // TODO wasi-sockets abort(); } -void freeaddrinfo(struct addrinfo *p) +void freeaddrinfo(struct addrinfo* p) +{ + // TODO + abort(); +} + +int getnameinfo(const struct sockaddr* restrict sa, socklen_t salen, char* restrict host, socklen_t hostlen, char* restrict serv, socklen_t servlen, int flags) { // TODO wasi-sockets abort(); } + +struct hostent* gethostbyname(const char* name) +{ + // TODO + abort(); +} + +struct hostent* gethostbyaddr(const void* addr, socklen_t len, int type) +{ + // TODO + abort(); +} + +const char* hstrerror(int err) +{ + // TODO + abort(); +} + +struct servent* getservbyname(const char* name, const char* proto) +{ + // TODO + abort(); +} + +struct servent* getservbyport(int port, const char* proto) +{ + // TODO + abort(); +} + +struct protoent* getprotobyname(const char* name) +{ + // TODO + abort(); +} diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index bb41677d6..171630cf7 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -20,6 +20,8 @@ #define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM #define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM +#define SOMAXCONN 128 + #define SOCK_NONBLOCK (0x00004000) #define SOCK_CLOEXEC (0x00002000) diff --git a/libc-top-half/musl/include/netdb.h b/libc-top-half/musl/include/netdb.h index d096c7818..777ddfb03 100644 --- a/libc-top-half/musl/include/netdb.h +++ b/libc-top-half/musl/include/netdb.h @@ -118,8 +118,13 @@ struct hostent *gethostbyaddr (const void *, socklen_t, int); #ifdef __GNUC__ __attribute__((const)) #endif +#ifdef __wasilibc_unmodified_upstream int *__h_errno_location(void); #define h_errno (*__h_errno_location()) +#else +extern _Thread_local int h_errno; +#define h_errno h_errno +#endif #define HOST_NOT_FOUND 1 #define TRY_AGAIN 2 #define NO_RECOVERY 3 diff --git a/make-bindings.sh b/make-bindings.sh new file mode 100644 index 000000000..1801f2fc2 --- /dev/null +++ b/make-bindings.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# As of this writing, the `wit` directory was copied from +# https://github.com/bytecodealliance/wasmtime/tree/759aa585496adfbe47aefb4fdf9608aabf8d64ac/crates/wasi/wit + +set -e + +wit-bindgen c --world wasi:cli/imports@0.2.0-rc-2023-12-05 \ + --rename wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10=monotonic_clock \ + --rename wasi:clocks/wall-clock@0.2.0-rc-2023-11-10=wall_clock \ + --rename wasi:filesystem/preopens@0.2.0-rc-2023-11-10=filesystem_preopens \ + --rename wasi:filesystem/types@0.2.0-rc-2023-11-10=filesystem \ + --rename wasi:io/error@0.2.0-rc-2023-11-10=io_error \ + --rename wasi:io/poll@0.2.0-rc-2023-11-10=poll \ + --rename wasi:io/streams@0.2.0-rc-2023-11-10=streams \ + --rename wasi:random/insecure-seed@0.2.0-rc-2023-11-10=random_insecure_seed \ + --rename wasi:random/insecure@0.2.0-rc-2023-11-10=random_insecure \ + --rename wasi:random/random@0.2.0-rc-2023-11-10=random \ + --rename wasi:sockets/instance-network@0.2.0-rc-2023-11-10=instance_network \ + --rename wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10=ip_name_lookup \ + --rename wasi:sockets/network@0.2.0-rc-2023-11-10=network \ + --rename wasi:sockets/tcp-create-socket@0.2.0-rc-2023-11-10=tcp_create_socket \ + --rename wasi:sockets/tcp@0.2.0-rc-2023-11-10=tcp \ + --rename wasi:sockets/udp-create-socket@0.2.0-rc-2023-11-10=udp_create_socket \ + --rename wasi:sockets/udp@0.2.0-rc-2023-11-10=udp \ + --rename wasi:cli/environment@0.2.0-rc-2023-12-05=environment \ + --rename wasi:cli/exit@0.2.0-rc-2023-12-05=exit \ + --rename wasi:cli/stdin@0.2.0-rc-2023-12-05=stdin \ + --rename wasi:cli/stdout@0.2.0-rc-2023-12-05=stdout \ + --rename wasi:cli/stderr@0.2.0-rc-2023-12-05=stderr \ + --rename wasi:cli/terminal-input@0.2.0-rc-2023-12-05=terminal_input \ + --rename wasi:cli/terminal-output@0.2.0-rc-2023-12-05=terminal_output \ + --rename wasi:cli/terminal-stdin@0.2.0-rc-2023-12-05=terminal_stdin \ + --rename wasi:cli/terminal-stdout@0.2.0-rc-2023-12-05=terminal_stdout \ + --rename wasi:cli/terminal-stderr@0.2.0-rc-2023-12-05=terminal_stderr \ + ./wit +mv imports.h libc-bottom-half/headers/private/preview2.h +sed 's/#include "imports.h"/#include "preview2.h"/' < imports.c > libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c +rm imports.c +mv imports_component_type.o libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2_component_type.o From e09d83b9f86c6be8f96f90cbfd6e274b17e4acb9 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Thu, 7 Dec 2023 13:52:44 +0100 Subject: [PATCH 28/63] Implement recv&send using recvfrom&sendto --- .../cloudlibc/src/libc/sys/socket/recv.c | 22 ++++++++++++++----- .../cloudlibc/src/libc/sys/socket/send.c | 22 ++++++++++++++----- libc-top-half/musl/include/sys/socket.h | 2 +- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index de7dba72b..8b2cb8fb9 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -11,7 +11,8 @@ #include #include "__utils.h" -ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int flags) +ssize_t tcp_recvfrom(tcp_socket_t* socket, uint8_t* buffer, size_t length, int flags, + struct sockaddr* addr , socklen_t* addrlen) { // TODO wasi-sockets: flags: // - MSG_WAITALL: we can probably support these relatively easy. @@ -25,6 +26,11 @@ ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int return -1; } + if (addr != NULL || addrlen != NULL) { + errno = EISCONN; + return -1; + } + tcp_socket_state_connected_t connection; if (socket->state.tag == TCP_SOCKET_STATE_CONNECTED) { connection = socket->state.connected; @@ -62,7 +68,8 @@ ssize_t tcp_recv(tcp_socket_t* socket, void* restrict buffer, size_t length, int } } -ssize_t udp_recv(udp_socket_t* socket, void* restrict buffer, size_t length, int flags) +ssize_t udp_recvfrom(udp_socket_t* socket, uint8_t* buffer, size_t length, int flags, + struct sockaddr* addr , socklen_t* addrlen) { // TODO wasi-sockets: Implement flags. Same as tcp_recv except that MSG_TRUNC is valid for UDP. @@ -70,7 +77,12 @@ ssize_t udp_recv(udp_socket_t* socket, void* restrict buffer, size_t length, int return -1; } -ssize_t recv(int socket, void* restrict buffer, size_t length, int flags) +ssize_t recv(int socket, void* restrict buffer, size_t length, int flags) { + return recvfrom(socket, buffer, length, flags, NULL, NULL); +} + +ssize_t recvfrom(int socket, void *__restrict buffer, size_t length, int flags, + struct sockaddr *__restrict addr , socklen_t *__restrict addrlen) { descriptor_table_entry_t* entry; if (!descriptor_table_get_ref(socket, &entry)) { @@ -86,9 +98,9 @@ ssize_t recv(int socket, void* restrict buffer, size_t length, int flags) switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - return tcp_recv(&entry->tcp_socket, buffer, length, flags); + return tcp_recvfrom(&entry->tcp_socket, buffer, length, flags, addr, addrlen); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - return udp_recv(&entry->udp_socket, buffer, length, flags); + return udp_recvfrom(&entry->udp_socket, buffer, length, flags, addr, addrlen); default: errno = EOPNOTSUPP; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c index e6c66589a..1d0d22817 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c @@ -11,7 +11,8 @@ #include #include "__utils.h" -ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int flags) +ssize_t tcp_sendto(tcp_socket_t* socket, const uint8_t* buffer, size_t length, int flags, + const struct sockaddr* addr, socklen_t addrlen) { const int supported_flags = MSG_DONTWAIT | MSG_NOSIGNAL; if ((flags & supported_flags) != flags) { @@ -19,6 +20,11 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int fl return -1; } + if (addr != NULL || addrlen != 0) { + errno = EISCONN; + return -1; + } + tcp_socket_state_connected_t connection; if (socket->state.tag == TCP_SOCKET_STATE_CONNECTED) { connection = socket->state.connected; @@ -68,7 +74,8 @@ ssize_t tcp_send(tcp_socket_t* socket, const void* buffer, size_t length, int fl } } -ssize_t udp_send(udp_socket_t* socket, const void* buffer, size_t length, int flags) +ssize_t udp_sendto(udp_socket_t* socket, const uint8_t* buffer, size_t length, int flags, + const struct sockaddr* addr, socklen_t addrlen) { // TODO wasi-sockets: Implement flags. Same as tcp_send. @@ -76,7 +83,12 @@ ssize_t udp_send(udp_socket_t* socket, const void* buffer, size_t length, int fl return -1; } -ssize_t send(int socket, const void* buffer, size_t length, int flags) +ssize_t send(int socket, const void* buffer, size_t length, int flags) { + return sendto(socket, buffer, length, flags, NULL, 0); +} + +ssize_t sendto(int socket, const void* buffer, size_t length, int flags, + const struct sockaddr* addr, socklen_t addrlen) { descriptor_table_entry_t* entry; if (!descriptor_table_get_ref(socket, &entry)) { @@ -92,9 +104,9 @@ ssize_t send(int socket, const void* buffer, size_t length, int flags) switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: - return tcp_send(&entry->tcp_socket, buffer, length, flags); + return tcp_sendto(&entry->tcp_socket, buffer, length, flags, addr, addrlen); case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: - return udp_send(&entry->udp_socket, buffer, length, flags); + return udp_sendto(&entry->udp_socket, buffer, length, flags, addr, addrlen); default: errno = EOPNOTSUPP; return -1; diff --git a/libc-top-half/musl/include/sys/socket.h b/libc-top-half/musl/include/sys/socket.h index 8b92c34c9..945a5ca63 100644 --- a/libc-top-half/musl/include/sys/socket.h +++ b/libc-top-half/musl/include/sys/socket.h @@ -415,9 +415,9 @@ int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); ssize_t send (int, const void *, size_t, int); ssize_t recv (int, void *, size_t, int); -#ifdef __wasilibc_unmodified_upstream /* TODO wasi-sockets: implement */ ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); +#ifdef __wasilibc_unmodified_upstream /* TODO wasi-sockets: implement */ ssize_t sendmsg (int, const struct msghdr *, int); ssize_t recvmsg (int, struct msghdr *, int); #endif From 8f7dd8c8103d4e6b567d05a6840dbfb5e90deaa0 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Thu, 7 Dec 2023 14:45:40 +0100 Subject: [PATCH 29/63] UDP bind --- .../cloudlibc/src/libc/sys/socket/__utils.c | 78 +++++++++++++++++++ .../cloudlibc/src/libc/sys/socket/__utils.h | 3 + .../cloudlibc/src/libc/sys/socket/bind.c | 12 ++- 3 files changed, 90 insertions(+), 3 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c index 656e551b6..dcabbeef5 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c @@ -279,4 +279,82 @@ int __wasi_sockets_utils__tcp_bind(tcp_socket_t* socket, network_ip_socket_addre socket->state = (tcp_socket_state_t){ .tag = TCP_SOCKET_STATE_BOUND, .bound = { /* No additional state */ } }; return 0; +} + +int __wasi_sockets_utils__udp_bind(udp_socket_t* socket, network_ip_socket_address_t* address) { + + udp_socket_state_unbound_t unbound; + if (socket->state.tag == UDP_SOCKET_STATE_UNBOUND) { + unbound = socket->state.unbound; + } else { + errno = EINVAL; + return -1; + } + + network_error_code_t error; + network_borrow_network_t network_borrow = __wasi_sockets_utils__borrow_network(); + udp_borrow_udp_socket_t socket_borrow = udp_borrow_udp_socket(socket->socket); + + if (!udp_method_udp_socket_start_bind(socket_borrow, network_borrow, address, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + // Bind has successfully started. Attempt to finish it: + while (!udp_method_udp_socket_finish_bind(socket_borrow, &error)) { + if (error == NETWORK_ERROR_CODE_WOULD_BLOCK) { + poll_borrow_pollable_t pollable_borrow = poll_borrow_pollable(socket->socket_pollable); + poll_method_pollable_block(pollable_borrow); + } else { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + } + + // Bind successful. + + udp_socket_streams_t streams; + if (!__wasi_sockets_utils__create_streams(socket_borrow, NULL, &streams, &error)) { + abort(); // TODO wasi-sockets: How to recover from this in a POSIX compatible way? + } + + socket->state = (udp_socket_state_t){ .tag = UDP_SOCKET_STATE_BOUND, .bound = { + .streams = streams, + } }; + return 0; +} + +bool __wasi_sockets_utils__create_streams( + udp_borrow_udp_socket_t socket_borrow, + network_ip_socket_address_t* remote_address, + udp_socket_streams_t* result, + network_error_code_t* error +) { + udp_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_t io; + if (!udp_method_udp_socket_stream(socket_borrow, remote_address, &io, error)) { + return false; + } + + udp_own_incoming_datagram_stream_t incoming = io.f0; + udp_borrow_incoming_datagram_stream_t incoming_borrow = udp_borrow_incoming_datagram_stream(incoming); + poll_own_pollable_t incoming_pollable = udp_method_incoming_datagram_stream_subscribe(incoming_borrow); + + udp_own_outgoing_datagram_stream_t outgoing = io.f1; + udp_borrow_outgoing_datagram_stream_t outgoing_borrow = udp_borrow_outgoing_datagram_stream(outgoing); + poll_own_pollable_t outgoing_pollable = udp_method_outgoing_datagram_stream_subscribe(outgoing_borrow); + + *result = (udp_socket_streams_t){ + .incoming = incoming, + .incoming_pollable = incoming_pollable, + .outgoing = outgoing, + .outgoing_pollable = outgoing_pollable, + }; + return true; +} + +void __wasi_sockets_utils__drop_streams(udp_socket_streams_t streams) { + poll_pollable_drop_own(streams.incoming_pollable); + poll_pollable_drop_own(streams.outgoing_pollable); + udp_incoming_datagram_stream_drop_own(streams.incoming); + udp_outgoing_datagram_stream_drop_own(streams.outgoing); } \ No newline at end of file diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h index 0c92c478e..5a711297b 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h @@ -26,5 +26,8 @@ void __wasi_sockets_utils__output_addr_write(const network_ip_socket_address_t i 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); int __wasi_sockets_utils__tcp_bind(tcp_socket_t* socket, network_ip_socket_address_t* address); +int __wasi_sockets_utils__udp_bind(udp_socket_t* socket, network_ip_socket_address_t* address); +bool __wasi_sockets_utils__create_streams(udp_borrow_udp_socket_t socket_borrow, network_ip_socket_address_t* remote_address, udp_socket_streams_t* result, network_error_code_t* error); +void __wasi_sockets_utils__drop_streams(udp_socket_streams_t streams); #endif \ No newline at end of file diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c index 29f13c760..22bcb0ca2 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/bind.c @@ -17,9 +17,15 @@ int tcp_bind(tcp_socket_t* socket, const struct sockaddr* addr, socklen_t addrle } int udp_bind(udp_socket_t* socket, const struct sockaddr* addr, socklen_t addrlen) { - // TODO wasi-sockets: implement - errno = EOPNOTSUPP; - return -1; + + network_ip_socket_address_t local_address; + int parse_err; + if (!__wasi_sockets_utils__parse_address(socket->family, addr, addrlen, &local_address, &parse_err)) { + errno = parse_err; + return -1; + } + + return __wasi_sockets_utils__udp_bind(socket, &local_address); } int bind(int socket, const struct sockaddr* addr, socklen_t addrlen) { From f7807652f94bb88ea94cf1eb3215e3c74d0c30c4 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Thu, 7 Dec 2023 15:16:40 +0100 Subject: [PATCH 30/63] Split up Bound state --- .../cloudlibc/src/libc/sys/socket/__utils.c | 9 +-------- .../headers/private/descriptor_table.h | 16 +++++++++++----- .../sources/__wasilibc_fd_renumber.c | 5 +++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c index dcabbeef5..cede299f5 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c @@ -313,14 +313,7 @@ int __wasi_sockets_utils__udp_bind(udp_socket_t* socket, network_ip_socket_addre // Bind successful. - udp_socket_streams_t streams; - if (!__wasi_sockets_utils__create_streams(socket_borrow, NULL, &streams, &error)) { - abort(); // TODO wasi-sockets: How to recover from this in a POSIX compatible way? - } - - socket->state = (udp_socket_state_t){ .tag = UDP_SOCKET_STATE_BOUND, .bound = { - .streams = streams, - } }; + socket->state = (udp_socket_state_t){ .tag = UDP_SOCKET_STATE_BOUND_NOSTREAMS, .bound_nostreams = {} }; return 0; } diff --git a/libc-bottom-half/headers/private/descriptor_table.h b/libc-bottom-half/headers/private/descriptor_table.h index 8db7a5ae8..e8caba9bc 100644 --- a/libc-bottom-half/headers/private/descriptor_table.h +++ b/libc-bottom-half/headers/private/descriptor_table.h @@ -58,25 +58,31 @@ typedef struct { } udp_socket_streams_t; typedef struct {} udp_socket_state_unbound_t; +typedef struct {} udp_socket_state_bound_nostreams_t; typedef struct { - udp_socket_streams_t streams; -} udp_socket_state_bound_t; + udp_socket_streams_t streams; // Streams have no remote_address +} udp_socket_state_bound_streaming_t; typedef struct { - udp_socket_streams_t streams; + udp_socket_streams_t streams; // Streams have a remote_address } udp_socket_state_connected_t; // This is a tagged union. When adding/removing/renaming cases, be sure to keep the tag and union definitions in sync. +// The "bound" state is split up into two distinct tags: +// - "bound_nostreams": Bound, but no datagram streams set up (yet). That will be done the first time send or recv is called. +// - "bound_streaming": Bound with active streams. typedef struct { enum { UDP_SOCKET_STATE_UNBOUND, - UDP_SOCKET_STATE_BOUND, + UDP_SOCKET_STATE_BOUND_NOSTREAMS, + UDP_SOCKET_STATE_BOUND_STREAMING, UDP_SOCKET_STATE_CONNECTED, } tag; union { udp_socket_state_unbound_t unbound; - udp_socket_state_bound_t bound; + udp_socket_state_bound_nostreams_t bound_nostreams; + udp_socket_state_bound_streaming_t bound_streaming; udp_socket_state_connected_t connected; }; } udp_socket_state_t; diff --git a/libc-bottom-half/sources/__wasilibc_fd_renumber.c b/libc-bottom-half/sources/__wasilibc_fd_renumber.c index 8a2c9ca74..b86caa247 100644 --- a/libc-bottom-half/sources/__wasilibc_fd_renumber.c +++ b/libc-bottom-half/sources/__wasilibc_fd_renumber.c @@ -52,10 +52,11 @@ void drop_udp_socket_streams(udp_socket_streams_t streams) { void drop_udp_socket(udp_socket_t socket) { switch (socket.state.tag) { case UDP_SOCKET_STATE_UNBOUND: + case UDP_SOCKET_STATE_BOUND_NOSTREAMS: // No additional resources to drop. break; - case UDP_SOCKET_STATE_BOUND: - drop_udp_socket_streams(socket.state.bound.streams); + case UDP_SOCKET_STATE_BOUND_STREAMING: + drop_udp_socket_streams(socket.state.bound_streaming.streams); break; case UDP_SOCKET_STATE_CONNECTED: { drop_udp_socket_streams(socket.state.connected.streams); From 743718dac786cc95a47de5ace194cefc4ee5fb73 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Thu, 7 Dec 2023 15:48:31 +0100 Subject: [PATCH 31/63] Reimplement TCP_NODELAY. (#3) --- .../cloudlibc/src/libc/sys/socket/accept.c | 1 + .../cloudlibc/src/libc/sys/socket/socket.c | 1 + .../cloudlibc/src/libc/sys/socket/sockopt.c | 23 ++++++++++++------- .../headers/private/descriptor_table.h | 1 + 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c index 01e8481f9..dcc213447 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c @@ -60,6 +60,7 @@ bool tcp_accept(tcp_socket_t* socket, bool client_blocking, int* out_clientfd, n .socket = client, .socket_pollable = client_pollable, .blocking = client_blocking, + .fake_nodelay = socket->fake_nodelay, .state_tag = TCP_SOCKET_STATE_CONNECTED, .state = { .connected = { .input = input, diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c index 6702ad893..03d51c255 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket.c @@ -22,6 +22,7 @@ int tcp_socket(network_ip_address_family_t family, bool blocking) .socket = socket, .socket_pollable = socket_pollable, .blocking = blocking, + .fake_nodelay = false, .state_tag = TCP_SOCKET_STATE_UNBOUND, .state = { .unbound = { /* No additional state. */ } }, } }, diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c index 31de528af..a4ed79623 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -167,6 +167,10 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, case SOL_TCP: switch (optname) { + case TCP_NODELAY: { + value = socket->fake_nodelay; + break; + } case TCP_KEEPIDLE: { tcp_duration_t result_ns; if (!tcp_method_tcp_socket_keep_alive_idle_time(socket_borrow, &result_ns, &error)) { @@ -352,15 +356,18 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt case SOL_TCP: switch (optname) { case TCP_NODELAY: { - if (intval == 0) { - errno = EDOM; - return -1; - } else { - // Do nothing -- WASI sockets always have no-delay enabled. - return 0; - } + // At the time of writing, WASI has no support for TCP_NODELAY. + // Yet, many applications expect this option to be implemented. + // To ensure those applications can run on WASI at all, we fake + // support for it by recording the value, but not doing anything + // with it. + // If/when WASI adds true support, we can remove this workaround + // and implement it properly. From the application's perspective + // the "worst" thing that can then happen is that it automagically + // becomes faster. + socket->fake_nodelay = (intval != 0); + return 0; } - case TCP_KEEPIDLE: { tcp_duration_t duration = intval * NS_PER_S; if (!tcp_method_tcp_socket_set_keep_alive_idle_time(socket_borrow, duration, &error)) { diff --git a/libc-bottom-half/headers/private/descriptor_table.h b/libc-bottom-half/headers/private/descriptor_table.h index 9c3f84172..8e7c55c81 100644 --- a/libc-bottom-half/headers/private/descriptor_table.h +++ b/libc-bottom-half/headers/private/descriptor_table.h @@ -41,6 +41,7 @@ typedef struct { tcp_own_tcp_socket_t socket; poll_own_pollable_t socket_pollable; bool blocking; + bool fake_nodelay; tcp_socket_state_tag_t state_tag; tcp_socket_state_t state; } tcp_socket_t; From f60a65526d831ba3cd1eb0d4c6dcab40892f30f6 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Thu, 7 Dec 2023 15:55:08 +0100 Subject: [PATCH 32/63] UDP connect --- .../cloudlibc/src/libc/sys/socket/connect.c | 80 ++++++++++++++++++- 1 file changed, 77 insertions(+), 3 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c index c49c39067..a236e6305 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "__utils.h" @@ -85,11 +86,84 @@ int tcp_connect(tcp_socket_t* socket, const struct sockaddr* addr, socklen_t add return 0; } +// When `connect` is called on a UDP socket with an AF_UNSPEC address, it is actually a "disconnect" request. int udp_connect(udp_socket_t* socket, const struct sockaddr* addr, socklen_t addrlen) { - // TODO wasi-sockets: implement - errno = EOPNOTSUPP; - return -1; + if (addr == NULL || addrlen < sizeof(struct sockaddr)) { + errno = EINVAL; + return -1; + } + + network_ip_socket_address_t remote_address; + bool has_remote_address = (addr->sa_family != AF_UNSPEC); + if (has_remote_address) { + int parse_err; + if (!__wasi_sockets_utils__parse_address(socket->family, addr, addrlen, &remote_address, &parse_err)) { + errno = parse_err; + return -1; + } + } + + // Prepare the socket; binding it if not bound yet, and disconnecting it if connected. + switch (socket->state.tag) { + case UDP_SOCKET_STATE_UNBOUND: { + // Socket is not explicitly bound by the user. We'll do it for them: + + network_ip_socket_address_t any = __wasi_sockets_utils__any_addr(socket->family); + int result = __wasi_sockets_utils__udp_bind(socket, &any); + if (result != 0) { + return result; + } + break; + } + case UDP_SOCKET_STATE_BOUND_NOSTREAMS: { + // This is the state we want to be in. + break; + } + case UDP_SOCKET_STATE_BOUND_STREAMING: { + __wasi_sockets_utils__drop_streams(socket->state.bound_streaming.streams); + socket->state = (udp_socket_state_t){ .tag = UDP_SOCKET_STATE_BOUND_NOSTREAMS, .bound_nostreams = {} }; + break; + } + case UDP_SOCKET_STATE_CONNECTED: { + __wasi_sockets_utils__drop_streams(socket->state.connected.streams); + socket->state = (udp_socket_state_t){ .tag = UDP_SOCKET_STATE_BOUND_NOSTREAMS, .bound_nostreams = {} }; + break; + } + default: /* unreachable */ abort(); + } + + assert(socket->state.tag == UDP_SOCKET_STATE_BOUND_NOSTREAMS); + + + network_error_code_t error; + udp_borrow_udp_socket_t socket_borrow = udp_borrow_udp_socket(socket->socket); + udp_socket_streams_t streams; + + if (has_remote_address) { + // Perform "connect" + if (!__wasi_sockets_utils__create_streams(socket_borrow, &remote_address, &streams, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + socket->state = (udp_socket_state_t){ .tag = UDP_SOCKET_STATE_CONNECTED, .connected = { + .streams = streams, + } }; + return 0; + + } else { + // Perform "disconnect" + if (!__wasi_sockets_utils__create_streams(socket_borrow, NULL, &streams, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + socket->state = (udp_socket_state_t){ .tag = UDP_SOCKET_STATE_BOUND_STREAMING, .bound_streaming = { + .streams = streams, + } }; + return 0; + } } int connect(int fd, const struct sockaddr* addr, socklen_t addrlen) From 954bae8373c78690bb8f284100fab18547c5eae3 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Thu, 7 Dec 2023 16:29:02 +0100 Subject: [PATCH 33/63] Fix trap/abort when calling getsockname or getpeername too soon --- .../src/libc/sys/socket/getsockpeername.c | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c index e5b3c7999..7f8e5b117 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c @@ -17,6 +17,22 @@ int tcp_getsockname(tcp_socket_t* socket, struct sockaddr* addr, socklen_t* addr return -1; } + switch (socket->state.tag) { + case TCP_SOCKET_STATE_UNBOUND: + errno = EINVAL; + return -1; + + case TCP_SOCKET_STATE_BOUND: + case TCP_SOCKET_STATE_CONNECTING: + case TCP_SOCKET_STATE_CONNECT_FAILED: + case TCP_SOCKET_STATE_LISTENING: + case TCP_SOCKET_STATE_CONNECTED: + // OK. Continue.. + break; + + default: /* unreachable */ abort(); + } + network_error_code_t error; network_ip_socket_address_t result; tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); @@ -43,6 +59,22 @@ int tcp_getpeername(tcp_socket_t* socket, struct sockaddr* addr, socklen_t* addr return -1; } + switch (socket->state.tag) { + case TCP_SOCKET_STATE_UNBOUND: + case TCP_SOCKET_STATE_BOUND: + case TCP_SOCKET_STATE_CONNECTING: + case TCP_SOCKET_STATE_CONNECT_FAILED: + case TCP_SOCKET_STATE_LISTENING: + errno = ENOTCONN; + return -1; + + case TCP_SOCKET_STATE_CONNECTED: + // OK. Continue.. + break; + + default: /* unreachable */ abort(); + } + network_error_code_t error; network_ip_socket_address_t result; tcp_borrow_tcp_socket_t socket_borrow = tcp_borrow_tcp_socket(socket->socket); From fac12b24810d6439e64468e498ce43b152eb23a5 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Thu, 7 Dec 2023 16:29:39 +0100 Subject: [PATCH 34/63] UDP getsockname & getpeername --- .../src/libc/sys/socket/getsockpeername.c | 78 +++++++++++++++++-- 1 file changed, 72 insertions(+), 6 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c index 7f8e5b117..8141fbd06 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockpeername.c @@ -90,16 +90,82 @@ int tcp_getpeername(tcp_socket_t* socket, struct sockaddr* addr, socklen_t* addr int udp_getsockname(udp_socket_t* socket, struct sockaddr* addr, socklen_t* addrlen) { - // TODO wasi-sockets: implement - errno = EOPNOTSUPP; - return -1; + output_sockaddr_t output_addr; + if (!__wasi_sockets_utils__output_addr_validate(socket->family, addr, addrlen, &output_addr)) { + errno = EINVAL; + return -1; + } + + if (output_addr.tag == OUTPUT_SOCKADDR_NULL) { + errno = EINVAL; + return -1; + } + + switch (socket->state.tag) { + case UDP_SOCKET_STATE_UNBOUND: + errno = EINVAL; + return -1; + + case UDP_SOCKET_STATE_BOUND_NOSTREAMS: + case UDP_SOCKET_STATE_BOUND_STREAMING: + case UDP_SOCKET_STATE_CONNECTED: + // OK. Continue.. + break; + + default: /* unreachable */ abort(); + } + + network_error_code_t error; + network_ip_socket_address_t result; + udp_borrow_udp_socket_t socket_borrow = udp_borrow_udp_socket(socket->socket); + if (!udp_method_udp_socket_local_address(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + __wasi_sockets_utils__output_addr_write(result, &output_addr); + + return 0; } int udp_getpeername(udp_socket_t* socket, struct sockaddr* addr, socklen_t* addrlen) { - // TODO wasi-sockets: implement - errno = EOPNOTSUPP; - return -1; + output_sockaddr_t output_addr; + if (!__wasi_sockets_utils__output_addr_validate(socket->family, addr, addrlen, &output_addr)) { + errno = EINVAL; + return -1; + } + + if (output_addr.tag == OUTPUT_SOCKADDR_NULL) { + errno = EINVAL; + return -1; + } + + switch (socket->state.tag) { + case UDP_SOCKET_STATE_UNBOUND: + case UDP_SOCKET_STATE_BOUND_NOSTREAMS: + case UDP_SOCKET_STATE_BOUND_STREAMING: + errno = ENOTCONN; + return -1; + + case UDP_SOCKET_STATE_CONNECTED: + // OK. Continue.. + break; + + default: /* unreachable */ abort(); + } + + network_error_code_t error; + network_ip_socket_address_t result; + udp_borrow_udp_socket_t socket_borrow = udp_borrow_udp_socket(socket->socket); + if (!udp_method_udp_socket_remote_address(socket_borrow, &result, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + __wasi_sockets_utils__output_addr_write(result, &output_addr); + + return 0; } int getsockname(int socket, struct sockaddr *__restrict addr, socklen_t *__restrict addrlen) From 9eb88b15d00d441dff9701c24631a471d9e7329f Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Thu, 7 Dec 2023 12:42:42 -0700 Subject: [PATCH 35/63] add `wasi-sockets` support for `poll` and `ioctl` Signed-off-by: Joel Dice --- .../cloudlibc/src/libc/poll/poll.c | 174 +++++++++++++++++- .../cloudlibc/src/libc/sys/ioctl/ioctl.c | 170 ++++++++++------- 2 files changed, 273 insertions(+), 71 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c index cde4e81c2..d0fb462e0 100644 --- a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c +++ b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c @@ -6,8 +6,9 @@ #include #include #include +#include -int poll(struct pollfd *fds, size_t nfds, int timeout) { +static int poll_preview1(struct pollfd *fds, size_t nfds, int timeout) { // Construct events for poll(). size_t maxevents = 2 * nfds + 1; __wasi_subscription_t subscriptions[maxevents]; @@ -127,3 +128,174 @@ int poll(struct pollfd *fds, size_t nfds, int timeout) { } return retval; } + +typedef struct { + poll_own_pollable_t pollable; + struct pollfd* pollfd; + tcp_socket_t* socket; + short events; +} state_t; + +static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) +{ + size_t max_pollables = (2 * nfds) + 1; + state_t states[max_pollables]; + size_t state_index = 0; + for (size_t i = 0; i < nfds; ++i) { + struct pollfd* pollfd = fds + i; + descriptor_table_entry_t* entry; + if (descriptor_table_get_ref(pollfd->fd, &entry)) { + switch (entry->tag) { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: { + tcp_socket_t* socket = &(entry->value.tcp_socket); + switch (socket->state_tag) { + case TCP_SOCKET_STATE_CONNECTING: { + if ((pollfd->events & (POLLRDNORM | POLLWRNORM)) != 0) { + state_t state = { .pollable = socket->socket_pollable, + .pollfd = pollfd, + .socket = socket, + .events = pollfd->events }; + states[state_index++] = state; + } + break; + } + + case TCP_SOCKET_STATE_CONNECTED: { + if ((pollfd->events & POLLRDNORM) != 0) { + state_t state = { .pollable = socket->state.connected.input_pollable, + .pollfd = pollfd, + .socket = socket, + .events = POLLRDNORM }; + states[state_index++] = state; + } + if ((pollfd->events & POLLWRNORM) != 0) { + state_t state = { .pollable = socket->state.connected.output_pollable, + .pollfd = pollfd, + .socket = socket, + .events = POLLWRNORM }; + states[state_index++] = state; + } + break; + } + + default: + errno = ENOTSUP; + return -1; + } + break; + } + + default: + // TODO wasi-sockets: UDP + errno = ENOTSUP; + return -1; + } + } else { + abort(); + } + } + + poll_borrow_pollable_t pollables[state_index + 1]; + for (size_t i = 0; i < state_index; ++i) { + pollables[i] = poll_borrow_pollable(states[i].pollable); + } + + poll_own_pollable_t timeout_pollable; + size_t pollable_count = state_index; + if (timeout >= 0) { + timeout_pollable = monotonic_clock_subscribe_duration(((monotonic_clock_duration_t)timeout) * 1000000); + pollables[pollable_count++] = poll_borrow_pollable(timeout_pollable); + } + + poll_list_u32_t ready; + poll_list_borrow_pollable_t list = { .ptr = (poll_borrow_pollable_t*)&pollables, .len = pollable_count }; + poll_poll(&list, &ready); + + for (size_t i = 0; i < nfds; ++i) { + fds[i].revents = 0; + } + + int event_count = 0; + for (size_t i = 0; i < ready.len; ++i) { + size_t index = ready.ptr[i]; + if (index < state_index) { + state_t* state = &states[index]; + if (state->socket->state_tag == TCP_SOCKET_STATE_CONNECTING) { + tcp_borrow_tcp_socket_t borrow = tcp_borrow_tcp_socket(state->socket->socket); + tcp_tuple2_own_input_stream_own_output_stream_t tuple; + tcp_error_code_t error; + if (tcp_method_tcp_socket_finish_connect(borrow, &tuple, &error)) { + state->socket->state_tag = TCP_SOCKET_STATE_CONNECTED; + streams_borrow_input_stream_t input_stream_borrow = streams_borrow_input_stream(tuple.f0); + streams_own_pollable_t input_pollable = streams_method_input_stream_subscribe(input_stream_borrow); + streams_borrow_output_stream_t output_stream_borrow = streams_borrow_output_stream(tuple.f1); + streams_own_pollable_t output_pollable = streams_method_output_stream_subscribe(output_stream_borrow); + tcp_socket_state_t socket_state = { .connected = { .input_pollable = input_pollable, + .input = tuple.f0, + .output_pollable = output_pollable, + .output = tuple.f1 } }; + state->socket->state = socket_state; + if (state->pollfd->revents == 0) { + ++event_count; + } + state->pollfd->revents |= state->events; + } else if (error == NETWORK_ERROR_CODE_WOULD_BLOCK) { + // No events yet -- application will need to poll again + } else { + state->socket->state_tag = TCP_SOCKET_STATE_CONNECT_FAILED; + tcp_socket_state_t socket_state = { .connect_failed = { .error_code = error } }; + state->socket->state = socket_state; + if (state->pollfd->revents == 0) { + ++event_count; + } + state->pollfd->revents |= state->events; + } + } else { + if (state->pollfd->revents == 0) { + ++event_count; + } + state->pollfd->revents |= state->events; + } + } + } + + if (timeout >= 0) { + poll_pollable_drop_own(timeout_pollable); + } + + return event_count; +} + +int poll(struct pollfd* fds, size_t nfds, int timeout) +{ + bool found_socket = false; + bool found_non_socket = false; + for (size_t i = 0; i < nfds; ++i) { + descriptor_table_entry_t* entry; + if (descriptor_table_get_ref(fds[i].fd, &entry)) { + found_socket = true; + } else { + found_non_socket = true; + } + } + + if (found_socket) { + if (found_non_socket) { + // We currently don't support polling a mix of non-sockets and + // sockets here (though you can do it by using the host APIs + // directly), and we probably won't until we've migrated entirely to + // WASI Preview 2. + errno = ENOTSUP; + return -1; + } + + return poll_preview2(fds, nfds, timeout); + } else if (found_non_socket) { + return poll_preview1(fds, nfds, timeout); + } else if (timeout >= 0) { + return poll_preview2(fds, nfds, timeout); + } else { + errno = ENOTSUP; + return -1; + } +} 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 7d03cc61a..d9fd93220 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c @@ -4,85 +4,115 @@ #include -#include +#include #include #include +#include -int ioctl(int fildes, int request, ...) { - switch (request) { - case FIONREAD: { - // Poll the file descriptor to determine how many bytes can be read. - __wasi_subscription_t subscriptions[2] = { - { - .u.tag = __WASI_EVENTTYPE_FD_READ, - .u.u.fd_read.file_descriptor = fildes, - }, - { - .u.tag = __WASI_EVENTTYPE_CLOCK, - .u.u.clock.id = __WASI_CLOCKID_MONOTONIC, - }, - }; - __wasi_event_t events[__arraycount(subscriptions)]; - size_t nevents; - __wasi_errno_t error = __wasi_poll_oneoff( - subscriptions, events, __arraycount(subscriptions), &nevents); - if (error != 0) { - errno = error; - return -1; - } +int ioctl(int fildes, int request, ...) +{ + descriptor_table_entry_t* entry; + if (descriptor_table_get_ref(fildes, &entry)) { + switch (entry->tag) { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: { + switch (request) { + case FIONBIO: { + va_list ap; + va_start(ap, request); + entry->value.tcp_socket.blocking = *va_arg(ap, const int*) != 0; + va_end(ap); - // Location where result should be written. - va_list ap; - va_start(ap, request); - int *result = va_arg(ap, int *); - va_end(ap); + return 0; + } - // Extract number of bytes for reading from poll results. - for (size_t i = 0; i < nevents; ++i) { - __wasi_event_t *event = &events[i]; - if (event->error != 0) { - errno = event->error; - return -1; + default: + // TODO wasi-sockets: anything else we should support? + errno = EINVAL; + return -1; + } } - if (event->type == __WASI_EVENTTYPE_FD_READ) { - *result = event->fd_readwrite.nbytes; - return 0; + + default: + // TODO wasi-sockets: UDP + errno = ENOPROTOOPT; + return -1; } - } + } else { + switch (request) { + case FIONREAD: { + // Poll the file descriptor to determine how many bytes can be read. + __wasi_subscription_t subscriptions[2] = { + { + .u.tag = __WASI_EVENTTYPE_FD_READ, + .u.u.fd_read.file_descriptor = fildes, + }, + { + .u.tag = __WASI_EVENTTYPE_CLOCK, + .u.u.clock.id = __WASI_CLOCKID_MONOTONIC, + }, + }; + __wasi_event_t events[__arraycount(subscriptions)]; + size_t nevents; + __wasi_errno_t error = __wasi_poll_oneoff( + subscriptions, events, __arraycount(subscriptions), &nevents); + if (error != 0) { + errno = error; + return -1; + } - // No data available for reading. - *result = 0; - return 0; - } - case FIONBIO: { - // Obtain the current file descriptor flags. - __wasi_fdstat_t fds; - __wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds); - if (error != 0) { - errno = error; - return -1; - } + // Location where result should be written. + va_list ap; + va_start(ap, request); + int* result = va_arg(ap, int*); + va_end(ap); - // Toggle the non-blocking flag based on the argument. - va_list ap; - va_start(ap, request); - if (*va_arg(ap, const int *) != 0) - fds.fs_flags |= __WASI_FDFLAGS_NONBLOCK; - else - fds.fs_flags &= ~__WASI_FDFLAGS_NONBLOCK; - va_end(ap); + // Extract number of bytes for reading from poll results. + for (size_t i = 0; i < nevents; ++i) { + __wasi_event_t* event = &events[i]; + if (event->error != 0) { + errno = event->error; + return -1; + } + if (event->type == __WASI_EVENTTYPE_FD_READ) { + *result = event->fd_readwrite.nbytes; + return 0; + } + } - // Update the file descriptor flags. - error = __wasi_fd_fdstat_set_flags(fildes, fds.fs_flags); - if (error != 0) { - errno = error; - return -1; - } - return 0; + // No data available for reading. + *result = 0; + return 0; + } + case FIONBIO: { + // Obtain the current file descriptor flags. + __wasi_fdstat_t fds; + __wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds); + if (error != 0) { + errno = error; + return -1; + } + + // Toggle the non-blocking flag based on the argument. + va_list ap; + va_start(ap, request); + if (*va_arg(ap, const int*) != 0) + fds.fs_flags |= __WASI_FDFLAGS_NONBLOCK; + else + fds.fs_flags &= ~__WASI_FDFLAGS_NONBLOCK; + va_end(ap); + + // Update the file descriptor flags. + error = __wasi_fd_fdstat_set_flags(fildes, fds.fs_flags); + if (error != 0) { + errno = error; + return -1; + } + return 0; + } + default: + // Invalid request. + errno = EINVAL; + return -1; + } } - default: - // Invalid request. - errno = EINVAL; - return -1; - } } From 26801968c62a92ef6ae50174f768c4e9c8decc5e Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Fri, 8 Dec 2023 20:42:44 +0100 Subject: [PATCH 36/63] Refactor `stream` state transition --- .../cloudlibc/src/libc/sys/socket/__utils.c | 33 +++++++++++++++++++ .../cloudlibc/src/libc/sys/socket/__utils.h | 2 +- .../cloudlibc/src/libc/sys/socket/connect.c | 31 +++-------------- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c index cede299f5..346b2675e 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c @@ -350,4 +350,37 @@ void __wasi_sockets_utils__drop_streams(udp_socket_streams_t streams) { poll_pollable_drop_own(streams.outgoing_pollable); udp_incoming_datagram_stream_drop_own(streams.incoming); udp_outgoing_datagram_stream_drop_own(streams.outgoing); +} + +bool __wasi_sockets_utils__stream( + udp_socket_t* socket, + network_ip_socket_address_t* remote_address, // May be null to "disconnect" + udp_socket_streams_t* result, + network_error_code_t* error +) { + + // Assert that: + // - We're already bound. This is required by WASI. + // - We have no active streams. From WASI: + // > Implementations may trap if the streams returned by a previous + // > invocation haven't been dropped yet before calling `stream` again. + assert(socket->state.tag == UDP_SOCKET_STATE_BOUND_NOSTREAMS); + + udp_borrow_udp_socket_t socket_borrow = udp_borrow_udp_socket(socket->socket); + + if (!__wasi_sockets_utils__create_streams(socket_borrow, remote_address, result, error)) { + return false; + } + + if (remote_address != NULL) { + socket->state = (udp_socket_state_t){ .tag = UDP_SOCKET_STATE_CONNECTED, .connected = { + .streams = *result, + } }; + } else { + socket->state = (udp_socket_state_t){ .tag = UDP_SOCKET_STATE_BOUND_STREAMING, .bound_streaming = { + .streams = *result, + } }; + } + + return true; } \ No newline at end of file diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h index 5a711297b..b56abfa3c 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.h @@ -27,7 +27,7 @@ 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); int __wasi_sockets_utils__tcp_bind(tcp_socket_t* socket, network_ip_socket_address_t* address); int __wasi_sockets_utils__udp_bind(udp_socket_t* socket, network_ip_socket_address_t* address); -bool __wasi_sockets_utils__create_streams(udp_borrow_udp_socket_t socket_borrow, network_ip_socket_address_t* remote_address, udp_socket_streams_t* result, network_error_code_t* error); +bool __wasi_sockets_utils__stream(udp_socket_t* socket, network_ip_socket_address_t* remote_address, udp_socket_streams_t* result, network_error_code_t* error); void __wasi_sockets_utils__drop_streams(udp_socket_streams_t streams); #endif \ No newline at end of file diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c index a236e6305..5a9a80dd6 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c @@ -133,37 +133,16 @@ int udp_connect(udp_socket_t* socket, const struct sockaddr* addr, socklen_t add default: /* unreachable */ abort(); } - assert(socket->state.tag == UDP_SOCKET_STATE_BOUND_NOSTREAMS); - network_error_code_t error; - udp_borrow_udp_socket_t socket_borrow = udp_borrow_udp_socket(socket->socket); udp_socket_streams_t streams; - if (has_remote_address) { - // Perform "connect" - if (!__wasi_sockets_utils__create_streams(socket_borrow, &remote_address, &streams, &error)) { - errno = __wasi_sockets_utils__map_error(error); - return -1; - } - - socket->state = (udp_socket_state_t){ .tag = UDP_SOCKET_STATE_CONNECTED, .connected = { - .streams = streams, - } }; - return 0; - - } else { - // Perform "disconnect" - if (!__wasi_sockets_utils__create_streams(socket_borrow, NULL, &streams, &error)) { - errno = __wasi_sockets_utils__map_error(error); - return -1; - } - - socket->state = (udp_socket_state_t){ .tag = UDP_SOCKET_STATE_BOUND_STREAMING, .bound_streaming = { - .streams = streams, - } }; - return 0; + if (!__wasi_sockets_utils__stream(socket, has_remote_address ? &remote_address : NULL, &streams, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; } + + return 0; } int connect(int fd, const struct sockaddr* addr, socklen_t addrlen) From 9e9171f5a37a0eaf5e23814cf47d882e8b5067e5 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Fri, 8 Dec 2023 20:44:26 +0100 Subject: [PATCH 37/63] UDP send and recv --- .../cloudlibc/src/libc/sys/socket/recv.c | 86 +++++++++++- .../cloudlibc/src/libc/sys/socket/send.c | 124 +++++++++++++++++- 2 files changed, 200 insertions(+), 10 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index 8b2cb8fb9..dec1c5d48 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -18,8 +18,7 @@ ssize_t tcp_recvfrom(tcp_socket_t* socket, uint8_t* buffer, size_t length, int f // - MSG_WAITALL: we can probably support these relatively easy. // - MSG_OOB: could be shimmed by always responding that no OOB data is available. // - MSG_PEEK: could be shimmed by performing the receive into a local socket-specific buffer. And on subsequent receives first check that buffer. - // - MSG_TRUNC: return EOPNOTSUPP. Is UDP only. - // - MSG_EOR, MSG_CMSG_CLOEXEC: return EOPNOTSUPP. Is not supported on TCP or UDP. + const int supported_flags = MSG_DONTWAIT; if ((flags & supported_flags) != flags) { errno = EOPNOTSUPP; @@ -49,7 +48,7 @@ ssize_t tcp_recvfrom(tcp_socket_t* socket, uint8_t* buffer, size_t length, int f streams_list_u8_t result; streams_stream_error_t error; if (!streams_method_input_stream_read(rx_borrow, length, &result, &error)) { - // TODO wasi-sockets: wasi-sockets has no way to recover stream errors yet. + // TODO wasi-sockets: wasi-sockets has no way to recover TCP stream errors yet. errno = EPIPE; return -1; } @@ -71,10 +70,85 @@ ssize_t tcp_recvfrom(tcp_socket_t* socket, uint8_t* buffer, size_t length, int f ssize_t udp_recvfrom(udp_socket_t* socket, uint8_t* buffer, size_t length, int flags, struct sockaddr* addr , socklen_t* addrlen) { - // TODO wasi-sockets: Implement flags. Same as tcp_recv except that MSG_TRUNC is valid for UDP. + // TODO wasi-sockets: flags: + // - MSG_PEEK: could be shimmed by performing the receive into a local socket-specific buffer. And on subsequent receives first check that buffer. + + const int supported_flags = MSG_DONTWAIT | MSG_TRUNC; + if ((flags & supported_flags) != flags) { + errno = EOPNOTSUPP; + return -1; + } + + output_sockaddr_t output_addr; + if (!__wasi_sockets_utils__output_addr_validate(socket->family, addr, addrlen, &output_addr)) { + errno = EINVAL; + return -1; + } + + + network_error_code_t error; + udp_borrow_udp_socket_t socket_borrow = udp_borrow_udp_socket(socket->socket); + + udp_socket_streams_t streams; + switch (socket->state.tag) { + case UDP_SOCKET_STATE_UNBOUND: { + // Unlike `send`, `recv` should _not_ perform an implicit bind. + errno = EINVAL; + return -1; + } + case UDP_SOCKET_STATE_BOUND_NOSTREAMS: { + if (!__wasi_sockets_utils__stream(socket, NULL, &streams, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + break; + } + case UDP_SOCKET_STATE_BOUND_STREAMING: + streams = socket->state.bound_streaming.streams; + break; + + case UDP_SOCKET_STATE_CONNECTED: + streams = socket->state.connected.streams; + break; - errno = EOPNOTSUPP; - return -1; + default: /* unreachable */ abort(); + } + + bool return_real_size = (flags & MSG_TRUNC) != 0; + bool should_block = socket->blocking; + if ((flags & MSG_DONTWAIT) != 0) { + should_block = false; + } + + udp_borrow_incoming_datagram_stream_t incoming_borrow = udp_borrow_incoming_datagram_stream(streams.incoming); + while (true) { + udp_list_incoming_datagram_t datagrams; + if (!udp_method_incoming_datagram_stream_receive(incoming_borrow, 1, &datagrams, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + if (datagrams.len) { + udp_incoming_datagram_t datagram = datagrams.ptr[0]; + size_t datagram_size = datagram.data.len; + size_t bytes_to_copy = datagram_size < length ? datagram_size : length; + + if (output_addr.tag != OUTPUT_SOCKADDR_NULL) { + __wasi_sockets_utils__output_addr_write(datagram.remote_address, &output_addr); + } + + memcpy(buffer, datagram.data.ptr, bytes_to_copy); + udp_list_incoming_datagram_free(&datagrams); + return return_real_size ? datagram_size : bytes_to_copy; + + } else if (should_block) { + poll_borrow_pollable_t pollable_borrow = poll_borrow_pollable(streams.incoming_pollable); + poll_method_pollable_block(pollable_borrow); + } else { + errno = EWOULDBLOCK; + return -1; + } + } } ssize_t recv(int socket, void* restrict buffer, size_t length, int flags) { diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c index 1d0d22817..59a7be2c3 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c @@ -58,7 +58,7 @@ ssize_t tcp_sendto(tcp_socket_t* socket, const uint8_t* buffer, size_t length, i count = count < length ? count : length; streams_list_u8_t list = { .ptr = (uint8_t*)buffer, .len = count }; if (!streams_method_output_stream_write(tx_borrow, &list, &error)) { - // TODO wasi-sockets: wasi-sockets has no way to recover stream errors yet. + // TODO wasi-sockets: wasi-sockets has no way to recover TCP stream errors yet. errno = EPIPE; return -1; } else { @@ -77,10 +77,126 @@ ssize_t tcp_sendto(tcp_socket_t* socket, const uint8_t* buffer, size_t length, i ssize_t udp_sendto(udp_socket_t* socket, const uint8_t* buffer, size_t length, int flags, const struct sockaddr* addr, socklen_t addrlen) { - // TODO wasi-sockets: Implement flags. Same as tcp_send. + const int supported_flags = MSG_DONTWAIT; + if ((flags & supported_flags) != flags) { + errno = EOPNOTSUPP; + return -1; + } + + network_ip_socket_address_t remote_address; + bool has_remote_address = (addr != NULL); + + if (has_remote_address) { + if (socket->state.tag == UDP_SOCKET_STATE_CONNECTED) { + errno = EISCONN; + return -1; + } + + int parse_err; + if (!__wasi_sockets_utils__parse_address(socket->family, addr, addrlen, &remote_address, &parse_err)) { + errno = parse_err; + return -1; + } + } else { + if (addrlen != 0) { + errno = EINVAL; + return -1; + } - errno = EOPNOTSUPP; - return -1; + if (socket->state.tag != UDP_SOCKET_STATE_CONNECTED) { + errno = EDESTADDRREQ; + return -1; + } + } + + network_error_code_t error; + udp_borrow_udp_socket_t socket_borrow = udp_borrow_udp_socket(socket->socket); + + udp_socket_streams_t streams; + switch (socket->state.tag) { + case UDP_SOCKET_STATE_UNBOUND: { + // Socket is not explicitly bound by the user. We'll do it for them: + + network_ip_socket_address_t any = __wasi_sockets_utils__any_addr(socket->family); + int result = __wasi_sockets_utils__udp_bind(socket, &any); + if (result != 0) { + return result; + } + + if (!__wasi_sockets_utils__stream(socket, NULL, &streams, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + break; + } + case UDP_SOCKET_STATE_BOUND_NOSTREAMS: { + if (!__wasi_sockets_utils__stream(socket, NULL, &streams, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + break; + } + case UDP_SOCKET_STATE_BOUND_STREAMING: + streams = socket->state.bound_streaming.streams; + break; + + case UDP_SOCKET_STATE_CONNECTED: + streams = socket->state.connected.streams; + break; + + default: /* unreachable */ abort(); + } + + bool should_block = socket->blocking; + if ((flags & MSG_DONTWAIT) != 0) { + should_block = false; + } + + udp_outgoing_datagram_t datagrams[1] = {{ + .remote_address = { + .is_some = has_remote_address, + .val = remote_address, + }, + .data = { + .len = length, + .ptr = (uint8_t*)buffer, + }, + }}; + udp_list_outgoing_datagram_t list = { + .len = 1, + .ptr = datagrams, + }; + + udp_borrow_outgoing_datagram_stream_t outgoing_borrow = udp_borrow_outgoing_datagram_stream(streams.outgoing); + while (true) { + uint64_t allowed; + if (!udp_method_outgoing_datagram_stream_check_send(outgoing_borrow, &allowed, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + if (allowed) { + uint64_t datagrams_sent; + if (!udp_method_outgoing_datagram_stream_send(outgoing_borrow, &list, &datagrams_sent, &error)) { + errno = __wasi_sockets_utils__map_error(error); + return -1; + } + + assert(datagrams_sent == 0 || datagrams_sent == 1); + + if (datagrams_sent == 1) { + return length; + } + } + + if (should_block) { + poll_borrow_pollable_t pollable_borrow = poll_borrow_pollable(streams.outgoing_pollable); + poll_method_pollable_block(pollable_borrow); + } else { + errno = EWOULDBLOCK; + return -1; + } + } } ssize_t send(int socket, const void* buffer, size_t length, int flags) { From 02285af0c33d8915b9e230ea7fc9c1efaf06e12c Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Fri, 8 Dec 2023 21:04:21 +0100 Subject: [PATCH 38/63] Fix build errors after pull --- .../cloudlibc/src/libc/poll/poll.c | 24 +++++++++---------- .../cloudlibc/src/libc/sys/ioctl/ioctl.c | 3 ++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c index d0fb462e0..3d7055065 100644 --- a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c +++ b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c @@ -147,8 +147,8 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) if (descriptor_table_get_ref(pollfd->fd, &entry)) { switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: { - tcp_socket_t* socket = &(entry->value.tcp_socket); - switch (socket->state_tag) { + tcp_socket_t* socket = &(entry->tcp_socket); + switch (socket->state.tag) { case TCP_SOCKET_STATE_CONNECTING: { if ((pollfd->events & (POLLRDNORM | POLLWRNORM)) != 0) { state_t state = { .pollable = socket->socket_pollable, @@ -220,21 +220,21 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) size_t index = ready.ptr[i]; if (index < state_index) { state_t* state = &states[index]; - if (state->socket->state_tag == TCP_SOCKET_STATE_CONNECTING) { + if (state->socket->state.tag == TCP_SOCKET_STATE_CONNECTING) { tcp_borrow_tcp_socket_t borrow = tcp_borrow_tcp_socket(state->socket->socket); tcp_tuple2_own_input_stream_own_output_stream_t tuple; tcp_error_code_t error; if (tcp_method_tcp_socket_finish_connect(borrow, &tuple, &error)) { - state->socket->state_tag = TCP_SOCKET_STATE_CONNECTED; streams_borrow_input_stream_t input_stream_borrow = streams_borrow_input_stream(tuple.f0); streams_own_pollable_t input_pollable = streams_method_input_stream_subscribe(input_stream_borrow); streams_borrow_output_stream_t output_stream_borrow = streams_borrow_output_stream(tuple.f1); streams_own_pollable_t output_pollable = streams_method_output_stream_subscribe(output_stream_borrow); - tcp_socket_state_t socket_state = { .connected = { .input_pollable = input_pollable, - .input = tuple.f0, - .output_pollable = output_pollable, - .output = tuple.f1 } }; - state->socket->state = socket_state; + state->socket->state = (tcp_socket_state_t){ .tag = TCP_SOCKET_STATE_CONNECTED, .connected = { + .input_pollable = input_pollable, + .input = tuple.f0, + .output_pollable = output_pollable, + .output = tuple.f1, + } }; if (state->pollfd->revents == 0) { ++event_count; } @@ -242,9 +242,9 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) } else if (error == NETWORK_ERROR_CODE_WOULD_BLOCK) { // No events yet -- application will need to poll again } else { - state->socket->state_tag = TCP_SOCKET_STATE_CONNECT_FAILED; - tcp_socket_state_t socket_state = { .connect_failed = { .error_code = error } }; - state->socket->state = socket_state; + state->socket->state = (tcp_socket_state_t){ .tag = TCP_SOCKET_STATE_CONNECT_FAILED, .connect_failed = { + .error_code = error, + } }; if (state->pollfd->revents == 0) { ++event_count; } 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 d9fd93220..91dcce920 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c @@ -15,11 +15,12 @@ int ioctl(int fildes, int request, ...) if (descriptor_table_get_ref(fildes, &entry)) { switch (entry->tag) { case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: { + tcp_socket_t* socket = &entry->tcp_socket; switch (request) { case FIONBIO: { va_list ap; va_start(ap, request); - entry->value.tcp_socket.blocking = *va_arg(ap, const int*) != 0; + socket->blocking = *va_arg(ap, const int*) != 0; va_end(ap); return 0; From b984f46e3d700313789775259dd4f544b1c854e8 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Fri, 8 Dec 2023 21:12:25 +0100 Subject: [PATCH 39/63] Fix incompatible signature of poll --- libc-bottom-half/cloudlibc/src/libc/poll/poll.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c index 3d7055065..fb27ae45d 100644 --- a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c +++ b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c @@ -266,7 +266,7 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) return event_count; } -int poll(struct pollfd* fds, size_t nfds, int timeout) +int poll(struct pollfd* fds, nfds_t nfds, int timeout) { bool found_socket = false; bool found_non_socket = false; From 2a24635e395db274d99d35c2184c9dc56b625c6a Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Sat, 9 Dec 2023 08:54:55 -0700 Subject: [PATCH 40/63] free ready list after polling Signed-off-by: Joel Dice --- libc-bottom-half/cloudlibc/src/libc/poll/poll.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c index d0fb462e0..879cc6e0b 100644 --- a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c +++ b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c @@ -259,6 +259,8 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) } } + poll_list_u32_free(&ready); + if (timeout >= 0) { poll_pollable_drop_own(timeout_pollable); } From 955e4d733103f9412387a378dd5e5eb93f433b7e Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 11 Dec 2023 10:25:57 -0700 Subject: [PATCH 41/63] use a single assignment when updating TCP state Signed-off-by: Joel Dice --- libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c index 5a9a80dd6..e1e607ab4 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/connect.c @@ -57,8 +57,7 @@ int tcp_connect(tcp_socket_t* socket, const struct sockaddr* addr, socklen_t add return -1; } } else { - socket->state.tag = TCP_SOCKET_STATE_CONNECT_FAILED; - socket->state = (tcp_socket_state_t){ .connect_failed = { + socket->state = (tcp_socket_state_t){ .tag = TCP_SOCKET_STATE_CONNECT_FAILED, .connect_failed = { .error_code = error, } }; From 6be1e1a29cfb1d1224b9a5a940de48ff26699a23 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 11 Dec 2023 17:53:46 -0700 Subject: [PATCH 42/63] build for Preview 1 and 2 separately This restores the original Preview 1 socket code and only enables Preview 2 -based functionality when requested via `WASI_SNAPSHOT=preview2`. Signed-off-by: Joel Dice --- Makefile | 29 +++- .../cloudlibc/src/libc/poll/poll.c | 10 +- .../cloudlibc/src/libc/sys/ioctl/ioctl.c | 146 +++++++++--------- .../cloudlibc/src/libc/sys/socket/accept.c | 53 +++++++ .../cloudlibc/src/libc/sys/socket/netdb.c | 2 + .../cloudlibc/src/libc/sys/socket/recv.c | 36 +++++ .../cloudlibc/src/libc/sys/socket/send.c | 28 ++++ .../cloudlibc/src/libc/sys/socket/shutdown.c | 26 +++- .../cloudlibc/src/libc/sys/socket/sockopt.c | 48 +++++- .../headers/public/__header_sys_socket.h | 36 +++-- .../sources/__wasilibc_fd_renumber.c | 24 +-- libc-top-half/musl/include/netdb.h | 4 +- libc-top-half/musl/include/sys/socket.h | 11 +- 13 files changed, 346 insertions(+), 107 deletions(-) diff --git a/Makefile b/Makefile index 7181421ab..0167f4a43 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,9 @@ SYSROOT ?= $(CURDIR)/sysroot # A directory to install to for "make install". INSTALL_DIR ?= /usr/local # single or posix; note that pthread support is still a work-in-progress. -THREAD_MODEL ?= single +TARGET_TRIPLE ?= single +# preview1 or preview2; the latter is not (yet) compatible with multithreading +WASI_SNAPSHOT ?= preview1 # dlmalloc or none MALLOC_IMPL ?= dlmalloc # yes or no @@ -41,6 +43,10 @@ ifeq ($(THREAD_MODEL), posix) TARGET_TRIPLE = wasm32-wasi-threads endif +ifeq ($(WASI_SNAPSHOT), preview2) +TARGET_TRIPLE = wasm32-wasi-preview2 +endif + BUILTINS_LIB ?= $(shell ${CC} --print-libgcc-file-name) # These variables describe the locations of various files and directories in @@ -112,7 +118,6 @@ LIBC_TOP_HALF_MUSL_SOURCES = \ network/inet_aton.c \ network/in6addr_any.c \ network/in6addr_loopback.c \ - network/gai_strerror.c \ fenv/fenv.c \ fenv/fesetround.c \ fenv/feupdateenv.c \ @@ -198,6 +203,13 @@ LIBC_TOP_HALF_MUSL_SOURCES = \ $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/complex/*.c)) \ $(wildcard $(LIBC_TOP_HALF_MUSL_SRC_DIR)/crypt/*.c) +ifeq ($(WASI_SNAPSHOT), preview2) +LIBC_TOP_HALF_MUSL_SOURCES += \ + $(addprefix $(LIBC_TOP_HALF_MUSL_SRC_DIR)/, \ + network/gai_strerror.c \ + ) +endif + ifeq ($(THREAD_MODEL), posix) LIBC_TOP_HALF_MUSL_SOURCES += \ $(addprefix $(LIBC_TOP_HALF_MUSL_SRC_DIR)/, \ @@ -335,6 +347,10 @@ ASMFLAGS += -matomics CFLAGS += -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) endif +ifeq ($(WASI_SNAPSHOT), preview2) +EXTRA_CFLAGS += -D__wasilibc_use_preview2 +endif + # Expose the public headers to the implementation. We use `-isystem` for # purpose for two reasons: # @@ -357,7 +373,9 @@ DLMALLOC_OBJS = $(call objs,$(DLMALLOC_SOURCES)) EMMALLOC_OBJS = $(call objs,$(EMMALLOC_SOURCES)) LIBC_BOTTOM_HALF_ALL_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_ALL_SOURCES)) LIBC_TOP_HALF_ALL_OBJS = $(call asmobjs,$(call objs,$(LIBC_TOP_HALF_ALL_SOURCES))) +ifeq ($(WASI_SNAPSHOT), preview2) LIBC_OBJS += $(OBJDIR)/preview2_component_type.o +endif ifeq ($(MALLOC_IMPL),dlmalloc) LIBC_OBJS += $(DLMALLOC_OBJS) else ifeq ($(MALLOC_IMPL),emmalloc) @@ -469,6 +487,11 @@ MUSL_OMIT_HEADERS += \ "sys/sysmacros.h" \ "aio.h" +ifeq ($(WASI_SNAPSHOT), preview1) +# Remove headers not supported in WASI Preview 1. +MUSL_OMIT_HEADERS += "netdb.h" +endif + ifeq ($(THREAD_MODEL), single) # Remove headers not supported in single-threaded mode. MUSL_OMIT_HEADERS += "pthread.h" @@ -511,7 +534,7 @@ PIC_OBJS = \ # to CC. This is a workaround for a Windows command line size limitation. See # the `%.a` rule below for details. $(SYSROOT_LIB)/%.so: $(OBJDIR)/%.so.a $(BUILTINS_LIB) - $(CC) -nodefaultlibs -shared --sysroot=$(SYSROOT) \ + $(CC) --target=$(TARGET_TRIPLE) -nodefaultlibs -shared --sysroot=$(SYSROOT) \ -o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive $(BUILTINS_LIB) $(OBJDIR)/libc.so.a: $(LIBC_SO_OBJS) $(MUSL_PRINTSCAN_LONG_DOUBLE_SO_OBJS) diff --git a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c index 4be63c79b..c80532d06 100644 --- a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c +++ b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c @@ -6,7 +6,6 @@ #include #include #include -#include static int poll_preview1(struct pollfd *fds, size_t nfds, int timeout) { // Construct events for poll(). @@ -129,6 +128,9 @@ static int poll_preview1(struct pollfd *fds, size_t nfds, int timeout) { return retval; } +#ifdef __wasilibc_use_preview2 +#include + typedef struct { poll_own_pollable_t pollable; struct pollfd* pollfd; @@ -301,3 +303,9 @@ int poll(struct pollfd* fds, nfds_t nfds, int timeout) return -1; } } +#else // __wasilibc_use_preview2 +int poll(struct pollfd* fds, nfds_t nfds, int timeout) +{ + return poll_preview1(fds, nfds, timeout); +} +#endif 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 91dcce920..3f58afe02 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c @@ -2,15 +2,18 @@ // // SPDX-License-Identifier: BSD-2-Clause -#include - -#include #include #include +#include #include +#ifdef __wasilibc_use_preview2 +#include +#endif + int ioctl(int fildes, int request, ...) { +#ifdef __wasilibc_use_preview2 descriptor_table_entry_t* entry; if (descriptor_table_get_ref(fildes, &entry)) { switch (entry->tag) { @@ -38,82 +41,83 @@ int ioctl(int fildes, int request, ...) errno = ENOPROTOOPT; return -1; } - } else { - switch (request) { - case FIONREAD: { - // Poll the file descriptor to determine how many bytes can be read. - __wasi_subscription_t subscriptions[2] = { - { - .u.tag = __WASI_EVENTTYPE_FD_READ, - .u.u.fd_read.file_descriptor = fildes, - }, - { - .u.tag = __WASI_EVENTTYPE_CLOCK, - .u.u.clock.id = __WASI_CLOCKID_MONOTONIC, - }, - }; - __wasi_event_t events[__arraycount(subscriptions)]; - size_t nevents; - __wasi_errno_t error = __wasi_poll_oneoff( - subscriptions, events, __arraycount(subscriptions), &nevents); - if (error != 0) { - errno = error; - return -1; - } - - // Location where result should be written. - va_list ap; - va_start(ap, request); - int* result = va_arg(ap, int*); - va_end(ap); - - // Extract number of bytes for reading from poll results. - for (size_t i = 0; i < nevents; ++i) { - __wasi_event_t* event = &events[i]; - if (event->error != 0) { - errno = event->error; - return -1; - } - if (event->type == __WASI_EVENTTYPE_FD_READ) { - *result = event->fd_readwrite.nbytes; - return 0; - } - } + } +#endif // __wasilibc_use_preview2 - // No data available for reading. - *result = 0; - return 0; + switch (request) { + case FIONREAD: { + // Poll the file descriptor to determine how many bytes can be read. + __wasi_subscription_t subscriptions[2] = { + { + .u.tag = __WASI_EVENTTYPE_FD_READ, + .u.u.fd_read.file_descriptor = fildes, + }, + { + .u.tag = __WASI_EVENTTYPE_CLOCK, + .u.u.clock.id = __WASI_CLOCKID_MONOTONIC, + }, + }; + __wasi_event_t events[__arraycount(subscriptions)]; + size_t nevents; + __wasi_errno_t error = __wasi_poll_oneoff( + subscriptions, events, __arraycount(subscriptions), &nevents); + if (error != 0) { + errno = error; + return -1; } - case FIONBIO: { - // Obtain the current file descriptor flags. - __wasi_fdstat_t fds; - __wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds); - if (error != 0) { - errno = error; - return -1; - } - // Toggle the non-blocking flag based on the argument. - va_list ap; - va_start(ap, request); - if (*va_arg(ap, const int*) != 0) - fds.fs_flags |= __WASI_FDFLAGS_NONBLOCK; - else - fds.fs_flags &= ~__WASI_FDFLAGS_NONBLOCK; - va_end(ap); + // Location where result should be written. + va_list ap; + va_start(ap, request); + int* result = va_arg(ap, int*); + va_end(ap); - // Update the file descriptor flags. - error = __wasi_fd_fdstat_set_flags(fildes, fds.fs_flags); - if (error != 0) { - errno = error; + // Extract number of bytes for reading from poll results. + for (size_t i = 0; i < nevents; ++i) { + __wasi_event_t* event = &events[i]; + if (event->error != 0) { + errno = event->error; return -1; } - return 0; + if (event->type == __WASI_EVENTTYPE_FD_READ) { + *result = event->fd_readwrite.nbytes; + return 0; + } } - default: - // Invalid request. - errno = EINVAL; + + // No data available for reading. + *result = 0; + return 0; + } + case FIONBIO: { + // Obtain the current file descriptor flags. + __wasi_fdstat_t fds; + __wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds); + if (error != 0) { + errno = error; + return -1; + } + + // Toggle the non-blocking flag based on the argument. + va_list ap; + va_start(ap, request); + if (*va_arg(ap, const int*) != 0) + fds.fs_flags |= __WASI_FDFLAGS_NONBLOCK; + else + fds.fs_flags &= ~__WASI_FDFLAGS_NONBLOCK; + va_end(ap); + + // Update the file descriptor flags. + error = __wasi_fd_fdstat_set_flags(fildes, fds.fs_flags); + if (error != 0) { + errno = error; return -1; } + return 0; + } + default: + // Invalid request. + errno = EINVAL; + return -1; } } diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c index f2bef364b..19482a52c 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/accept.c @@ -1,7 +1,13 @@ +// SPDX-License-Identifier: BSD-2-Clause + +#include + #include #include #include +#include +#ifdef __wasilibc_use_preview2 #include #include "__utils.h" @@ -118,3 +124,50 @@ int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addr return -1; } } + +#else // __wasilibc_use_preview2 + +int accept(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen) { + int ret = -1; + + __wasi_errno_t error = __wasi_sock_accept(socket, 0, &ret); + + if (error != 0) { + errno = error; + return -1; + } + + // Clear sockaddr to indicate undefined address + memset(addr, 0, *addrlen); + // might be AF_UNIX or AF_INET + addr->sa_family = AF_UNSPEC; + *addrlen = sizeof(struct sockaddr); + + return ret; +} + +int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen, int flags) { + int ret = -1; + + if (flags & ~(SOCK_NONBLOCK | SOCK_CLOEXEC)) { + errno = EINVAL; + return -1; + } + + __wasi_errno_t error = __wasi_sock_accept(socket, (flags & SOCK_NONBLOCK) ? __WASI_FDFLAGS_NONBLOCK : 0, &ret); + + if (error != 0) { + errno = error; + return -1; + } + + // Clear sockaddr to indicate undefined address + memset(addr, 0, *addrlen); + // might be AF_UNIX or AF_INET + addr->sa_family = AF_UNSPEC; + *addrlen = sizeof(struct sockaddr); + + return ret; +} + +#endif // __wasilibc_use_preview2 diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c index c4752bb62..a25c6d891 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c @@ -1,3 +1,4 @@ +#ifdef __wasilibc_use_preview2 #include #include @@ -56,3 +57,4 @@ struct protoent* getprotobyname(const char* name) // TODO abort(); } +#endif // __wasilibc_use_preview2 diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index dec1c5d48..a80e3b52b 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -4,10 +4,12 @@ #include +#include #include #include #include +#ifdef __wasilibc_use_preview2 #include #include "__utils.h" @@ -180,3 +182,37 @@ ssize_t recvfrom(int socket, void *__restrict buffer, size_t length, int flags, return -1; } } + +#else // __wasilibc_use_preview2 + +static_assert(MSG_PEEK == __WASI_RIFLAGS_RECV_PEEK, "Value mismatch"); +static_assert(MSG_WAITALL == __WASI_RIFLAGS_RECV_WAITALL, "Value mismatch"); + +ssize_t recv(int socket, void *restrict buffer, size_t length, int flags) { + // Validate flags. + if ((flags & ~(MSG_PEEK | MSG_WAITALL)) != 0) { + errno = EOPNOTSUPP; + return -1; + } + + // Prepare input parameters. + __wasi_iovec_t iov = {.buf = buffer, .buf_len = length}; + __wasi_iovec_t *ri_data = &iov; + size_t ri_data_len = 1; + __wasi_riflags_t ri_flags = flags; + + // Perform system call. + size_t ro_datalen; + __wasi_roflags_t ro_flags; + __wasi_errno_t error = __wasi_sock_recv(socket, + ri_data, ri_data_len, ri_flags, + &ro_datalen, + &ro_flags); + if (error != 0) { + errno = error; + return -1; + } + return ro_datalen; +} + +#endif // __wasilibc_use_preview2 diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c index 59a7be2c3..34e659677 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c @@ -8,6 +8,7 @@ #include #include +#ifdef __wasilibc_use_preview2 #include #include "__utils.h" @@ -228,3 +229,30 @@ ssize_t sendto(int socket, const void* buffer, size_t length, int flags, return -1; } } + +#else // __wasilibc_use_preview2 + +ssize_t send(int socket, const void *buffer, size_t length, int flags) { + // This implementation does not support any flags. + if (flags != 0) { + errno = EOPNOTSUPP; + return -1; + } + + // Prepare input parameters. + __wasi_ciovec_t iov = {.buf = buffer, .buf_len = length}; + __wasi_ciovec_t *si_data = &iov; + size_t si_data_len = 1; + __wasi_siflags_t si_flags = 0; + + // Perform system call. + size_t so_datalen; + __wasi_errno_t error = __wasi_sock_send(socket, si_data, si_data_len, si_flags, &so_datalen); + if (error != 0) { + errno = error; + return -1; + } + return so_datalen; +} + +#endif // __wasilibc_use_preview2 diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c index 195d0e876..6d7cd4142 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c @@ -8,12 +8,13 @@ #include #include -#include -#include "__utils.h" - static_assert(SHUT_RD == __WASI_SDFLAGS_RD, "Value mismatch"); static_assert(SHUT_WR == __WASI_SDFLAGS_WR, "Value mismatch"); +#ifdef __wasilibc_use_preview2 +#include +#include "__utils.h" + int tcp_shutdown(tcp_socket_t* socket, int posix_how) { tcp_shutdown_type_t wasi_how; @@ -85,3 +86,22 @@ int shutdown(int socket, int how) { return -1; } } + +#else // __wasilibc_use_preview2 + +int shutdown(int socket, int how) { + // Validate shutdown flags. + if (how != SHUT_RD && how != SHUT_WR && how != SHUT_RDWR) { + errno = EINVAL; + return -1; + } + + __wasi_errno_t error = __wasi_sock_shutdown(socket, how); + if (error != 0) { + errno = error; + return -1; + } + return error; +} + +#endif // __wasilibc_use_preview2 diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c index 906538c45..df6187572 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -5,12 +5,13 @@ #include #include #include - -#include #include #include #include #include + +#ifdef __wasilibc_use_preview2 +#include #include "__utils.h" const uint64_t NS_PER_S = 1000000000; @@ -692,3 +693,46 @@ int setsockopt(int sockfd, int level, int optname, const void* optval, socklen_t return -1; } } + +#else // __wasilibc_use_preview2 + +int getsockopt(int socket, int level, int option_name, + void *restrict option_value, socklen_t *restrict option_len) { + // Only support SOL_SOCKET options for now. + if (level != SOL_SOCKET) { + errno = ENOPROTOOPT; + return -1; + } + + int value; + switch (option_name) { + case SO_TYPE: { + // Return the type of the socket. This information can simply be + // obtained by looking at the file descriptor type. + __wasi_fdstat_t fsb; + if (__wasi_fd_fdstat_get(socket, &fsb) != 0) { + errno = EBADF; + return -1; + } + if (fsb.fs_filetype != __WASI_FILETYPE_SOCKET_DGRAM && + fsb.fs_filetype != __WASI_FILETYPE_SOCKET_STREAM) { + errno = ENOTSOCK; + return -1; + } + value = fsb.fs_filetype; + break; + } + default: { + errno = ENOPROTOOPT; + return -1; + } + } + + // Copy out integer value. + memcpy(option_value, &value, + *option_len < sizeof(int) ? *option_len : sizeof(int)); + *option_len = sizeof(int); + return 0; +} + +#endif // __wasilibc_use_preview2 diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index 171630cf7..fb3c585ef 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -7,31 +7,20 @@ #include -#define SHUT_RD __WASI_SDFLAGS_RD -#define SHUT_WR __WASI_SDFLAGS_WR -#define SHUT_RDWR (SHUT_RD | SHUT_WR) - +#ifdef __wasilibc_use_preview2 #define MSG_DONTWAIT 0x0040 #define MSG_NOSIGNAL 0x4000 #define MSG_PEEK 0x0002 #define MSG_WAITALL 0x0100 #define MSG_TRUNC 0x0020 -#define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM -#define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM - -#define SOMAXCONN 128 - -#define SOCK_NONBLOCK (0x00004000) -#define SOCK_CLOEXEC (0x00002000) - -#define SOL_SOCKET 0x7fffffff #define SOL_IP 0 #define SOL_TCP 6 #define SOL_UDP 17 #define SOL_IPV6 41 -#define SO_TYPE 3 +#define SOMAXCONN 128 + #define SO_ERROR 4 #define SO_SNDBUF 7 #define SO_RCVBUF 8 @@ -53,6 +42,25 @@ #define TCP_KEEPIDLE 4 #define TCP_KEEPINTVL 5 #define TCP_KEEPCNT 6 +#else // __wasilibc_use_preview2 +#define MSG_PEEK __WASI_RIFLAGS_RECV_PEEK +#define MSG_WAITALL __WASI_RIFLAGS_RECV_WAITALL +#define MSG_TRUNC __WASI_ROFLAGS_RECV_DATA_TRUNCATED +#endif // __wasilibc_use_preview2 + +#define SHUT_RD __WASI_SDFLAGS_RD +#define SHUT_WR __WASI_SDFLAGS_WR +#define SHUT_RDWR (SHUT_RD | SHUT_WR) + +#define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM +#define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM + +#define SOCK_NONBLOCK (0x00004000) +#define SOCK_CLOEXEC (0x00002000) + +#define SOL_SOCKET 0x7fffffff + +#define SO_TYPE 3 #define PF_UNSPEC 0 #define PF_INET 1 diff --git a/libc-bottom-half/sources/__wasilibc_fd_renumber.c b/libc-bottom-half/sources/__wasilibc_fd_renumber.c index b86caa247..0c4eab02e 100644 --- a/libc-bottom-half/sources/__wasilibc_fd_renumber.c +++ b/libc-bottom-half/sources/__wasilibc_fd_renumber.c @@ -3,8 +3,6 @@ #include #include -#include - int __wasilibc_fd_renumber(int fd, int newfd) { // Scan the preopen fds before making any changes. __wasilibc_populate_preopens(); @@ -17,6 +15,9 @@ int __wasilibc_fd_renumber(int fd, int newfd) { return 0; } +#ifdef __wasilibc_use_preview2 +#include + void drop_tcp_socket(tcp_socket_t socket) { switch (socket.state.tag) { case TCP_SOCKET_STATE_UNBOUND: @@ -68,11 +69,13 @@ void drop_udp_socket(udp_socket_t socket) { poll_pollable_drop_own(socket.socket_pollable); udp_udp_socket_drop_own(socket.socket); } +#endif // __wasilibc_use_preview2 int close(int fd) { // Scan the preopen fds before making any changes. __wasilibc_populate_preopens(); +#ifdef __wasilibc_use_preview2 descriptor_table_entry_t entry; if (descriptor_table_remove(fd, &entry)) { @@ -87,16 +90,17 @@ int close(int fd) { default: /* unreachable */ abort(); } - return 0; - } else { - __wasi_errno_t error = __wasi_fd_close(fd); - if (error != 0) { - errno = error; - return -1; - } - return 0; } +#endif // __wasilibc_use_preview2 + + __wasi_errno_t error = __wasi_fd_close(fd); + if (error != 0) { + errno = error; + return -1; + } + + return 0; } weak void __wasilibc_populate_preopens(void) { diff --git a/libc-top-half/musl/include/netdb.h b/libc-top-half/musl/include/netdb.h index 777ddfb03..3abc3c55e 100644 --- a/libc-top-half/musl/include/netdb.h +++ b/libc-top-half/musl/include/netdb.h @@ -118,10 +118,10 @@ struct hostent *gethostbyaddr (const void *, socklen_t, int); #ifdef __GNUC__ __attribute__((const)) #endif -#ifdef __wasilibc_unmodified_upstream +#ifdef __wasilibc_unmodified_upstream int *__h_errno_location(void); #define h_errno (*__h_errno_location()) -#else +#elif (defined __wasilibc_use_preview2) extern _Thread_local int h_errno; #define h_errno h_errno #endif diff --git a/libc-top-half/musl/include/sys/socket.h b/libc-top-half/musl/include/sys/socket.h index 945a5ca63..2a478c248 100644 --- a/libc-top-half/musl/include/sys/socket.h +++ b/libc-top-half/musl/include/sys/socket.h @@ -403,27 +403,36 @@ int socketpair (int, int, int, int [2]); #endif int shutdown (int, int); + +#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_preview2) int bind (int, const struct sockaddr *, socklen_t); int connect (int, const struct sockaddr *, socklen_t); int listen (int, int); - +#endif + int accept (int, struct sockaddr *__restrict, socklen_t *__restrict); int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); +#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_preview2) int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict); int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); +#endif ssize_t send (int, const void *, size_t, int); ssize_t recv (int, void *, size_t, int); +#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_preview2) ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); +#endif #ifdef __wasilibc_unmodified_upstream /* TODO wasi-sockets: implement */ ssize_t sendmsg (int, const struct msghdr *, int); ssize_t recvmsg (int, struct msghdr *, int); #endif int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict); +#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_preview2) int setsockopt (int, int, int, const void *, socklen_t); +#endif #ifdef __wasilibc_unmodified_upstream /* WASI has no sockatmark */ int sockatmark (int); From 24c7bb7d46473b025c8f35a0cd990c89b7d7ab0f Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 12 Dec 2023 11:34:22 -0700 Subject: [PATCH 43/63] use separate include dirs for each target This allows each target to have a different set of header files under the same sysroot. Signed-off-by: Joel Dice --- .github/workflows/main.yml | 6 ++- Makefile | 6 ++- .../libc/sys/wasi_preview2/descriptor_table.c | 4 +- .../headers/public/__header_sys_socket.h | 1 + .../headers/public/__wasi_snapshot.h | 5 +++ libc-top-half/musl/include/sys/socket.h | 3 ++ test/Makefile | 39 +++++++++++++++++-- 7 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 libc-bottom-half/headers/public/__wasi_snapshot.h diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index eb9b59f83..186ae0797 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -84,7 +84,9 @@ jobs: - name: Build libc shell: bash - run: make -j4 + run: | + make -j4 + WASI_SNAPSHOT=preview2 make -j4 - name: Test shell: bash @@ -98,6 +100,8 @@ jobs: mkdir -p $WASI_DIR cp download/lib/wasi/libclang_rt.builtins-wasm32.a $WASI_DIR make test + rm -r build + WASI_SNAPSHOT=preview2 make test # The older version of Clang does not provide the expected symbol for the # test entrypoints: `undefined symbol: __main_argc_argv`. # The older (<15.0.7) version of wasm-ld does not provide `__heap_end`, diff --git a/Makefile b/Makefile index 0167f4a43..4abba786d 100644 --- a/Makefile +++ b/Makefile @@ -406,7 +406,7 @@ LIBC_BOTTOM_HALF_CRT_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_CRT_SOURCES)) # These variables describe the locations of various files and # directories in the generated sysroot tree. SYSROOT_LIB := $(SYSROOT)/lib/$(TARGET_TRIPLE) -SYSROOT_INC = $(SYSROOT)/include +SYSROOT_INC = $(SYSROOT)/include/$(TARGET_TRIPLE) SYSROOT_SHARE = $(SYSROOT)/share/$(TARGET_TRIPLE) # Files from musl's include directory that we don't want to install in the @@ -681,6 +681,10 @@ include_dirs: # Remove selected header files. $(RM) $(patsubst %,$(SYSROOT_INC)/%,$(MUSL_OMIT_HEADERS)) +ifeq ($(WASI_SNAPSHOT), preview2) + printf '#ifndef __wasilibc_use_preview2\n#define __wasilibc_use_preview2\n#endif\n' \ + > "$(SYSROOT_INC)/__wasi_snapshot.h" +endif startup_files: include_dirs $(LIBC_BOTTOM_HALF_CRT_OBJS) # diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c index f11da1ff7..da4a0d004 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c @@ -29,14 +29,14 @@ __attribute__((__import_module__("wasi_snapshot_preview1"), __import_name__("ada static bool wasi_preview1_adapter_open_badfd(int* fd) { - return __wasi_preview1_adapter_open_badfd((int32_t)fd) != 0; + return __wasi_preview1_adapter_open_badfd((int32_t)fd) == 0; } __attribute__((__import_module__("wasi_snapshot_preview1"), __import_name__("adapter_close_badfd"))) extern int32_t __wasi_preview1_adapter_close_badfd(int32_t); static bool wasi_preview1_adapter_close_badfd(int fd) { - return __wasi_preview1_adapter_close_badfd(fd) != 0; + return __wasi_preview1_adapter_close_badfd(fd) == 0; } /* diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index fb3c585ef..f39577468 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -1,6 +1,7 @@ #ifndef __wasilibc___header_sys_socket_h #define __wasilibc___header_sys_socket_h +#include <__wasi_snapshot.h> #include <__struct_msghdr.h> #include <__struct_sockaddr.h> #include <__struct_sockaddr_storage.h> diff --git a/libc-bottom-half/headers/public/__wasi_snapshot.h b/libc-bottom-half/headers/public/__wasi_snapshot.h new file mode 100644 index 000000000..26aa6b824 --- /dev/null +++ b/libc-bottom-half/headers/public/__wasi_snapshot.h @@ -0,0 +1,5 @@ +/* This is file is (practically) empty by default. The Makefile will replace it + with a non-empty version that defines `__wasilibc_use_preview2` if targeting + `wasm32-wasi-preview2`. + */ + diff --git a/libc-top-half/musl/include/sys/socket.h b/libc-top-half/musl/include/sys/socket.h index 2a478c248..67dee2588 100644 --- a/libc-top-half/musl/include/sys/socket.h +++ b/libc-top-half/musl/include/sys/socket.h @@ -1,5 +1,8 @@ #ifndef _SYS_SOCKET_H #define _SYS_SOCKET_H + +#include <__wasi_snapshot.h> + #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ #else #include <__header_sys_socket.h> diff --git a/test/Makefile b/test/Makefile index 61e1756bc..9db4cf974 100644 --- a/test/Makefile +++ b/test/Makefile @@ -16,16 +16,29 @@ test: run OBJDIR ?= $(CURDIR)/build DOWNDIR ?= $(CURDIR)/download +# preview1 or preview2 +WASI_SNAPSHOT ?= preview1 + ##### DOWNLOAD ################################################################# LIBC_TEST_URL ?= https://github.com/bytecodealliance/libc-test LIBC_TEST = $(DOWNDIR)/libc-test LIBRT_URL ?= https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-16/libclang_rt.builtins-wasm32-wasi-16.0.tar.gz LIBRT = $(DOWNDIR)/lib/wasi/libclang_rt.builtins-wasm32.a -WASMTIME_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/v3.0.0/wasmtime-v3.0.0-x86_64-linux.tar.xz +# TODO: switch to Wasmtime 16 once it's released +WASMTIME_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/dev/wasmtime-dev-x86_64-linux.tar.xz WASMTIME = $(DOWNDIR)/$(shell basename $(WASMTIME_URL) .tar.xz)/wasmtime +WASM_TOOLS_URL ?= https://github.com/bytecodealliance/wasm-tools/releases/download/wasm-tools-1.0.54/wasm-tools-1.0.54-x86_64-linux.tar.gz +WASM_TOOLS = $(DOWNDIR)/$(shell basename $(WASM_TOOLS_URL) .tar.gz)/wasm-tools +ADAPTER_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/dev/wasi_snapshot_preview1.command.wasm +ADAPTER = $(DOWNDIR)/wasi_snapshot_preview1.command.wasm + +TO_DOWNLOAD = $(LIBC_TEST) $(LIBRT) $(WASMTIME) +ifeq ($(WASI_SNAPSHOT), preview2) +TO_DOWNLOAD += $(ADAPTER) $(WASM_TOOLS) +endif -download: $(LIBC_TEST) $(LIBRT) $(WASMTIME) +download: $(TO_DOWNLOAD) $(DOWNDIR): mkdir -p download @@ -42,6 +55,13 @@ $(WASMTIME): | $(DOWNDIR) wget --no-clobber --directory-prefix=$(DOWNDIR) $(WASMTIME_URL) tar --extract --file=$(DOWNDIR)/$(shell basename $(WASMTIME_URL)) --directory=$(DOWNDIR)/ +$(WASM_TOOLS): | $(DOWNDIR) + wget --no-clobber --directory-prefix=$(DOWNDIR) $(WASM_TOOLS_URL) + tar --extract --file=$(DOWNDIR)/$(shell basename $(WASM_TOOLS_URL)) --directory=$(DOWNDIR)/ + +$(ADAPTER): | $(DOWNDIR) + wget --no-clobber --directory-prefix=$(DOWNDIR) $(ADAPTER_URL) + clean:: rm -rf download @@ -110,13 +130,18 @@ WASM_OBJS += $(INFRA_WASM_OBJS) DIRS := $(patsubst $(OBJDIR)/%/,%,$(sort $(dir $(WASM_OBJS)))) OBJDIRS := $(DIRS:%=$(OBJDIR)/%) +TARGET_TRIPLE = wasm32-wasi +ifeq ($(WASI_SNAPSHOT), preview2) +TARGET_TRIPLE = wasm32-wasi-preview2 +endif + # Allow $(CC) to be set from the command line; ?= doesn't work for CC because # make has a default value for it. ifeq ($(origin CC), default) CC := clang endif LDFLAGS ?= -CFLAGS ?= --target=wasm32-wasi --sysroot=../sysroot +CFLAGS ?= --target=$(TARGET_TRIPLE) --sysroot=../sysroot # Always include the `libc-test` infrastructure headers. CFLAGS += -I$(LIBC_TEST)/src/common @@ -129,7 +154,10 @@ build: download $(WASMS) $(WASMS): | $(OBJDIRS) $(OBJDIR)/%.wasm: $(OBJDIR)/%.wasm.o $(INFRA_WASM_OBJS) - $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ + $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ +ifeq ($(WASI_SNAPSHOT), preview2) + $(WASM_TOOLS) component new --adapt $(ADAPTER) $@ -o $@ +endif $(WASM_OBJS): $(LIBC_TEST)/src/common/test.h | $(OBJDIRS) $(OBJDIR)/%.wasm.o: $(LIBC_TEST)/src/%.c @@ -144,6 +172,9 @@ clean:: ##### RUN ###################################################################### ENGINE ?= $(WASMTIME) run +ifeq ($(WASI_SNAPSHOT), preview2) +ENGINE += --wasm component-model +endif ERRS:=$(WASMS:%.wasm=%.wasm.err) # Use the provided Wasm engine to execute each test, emitting its output into From e8925b3afd5a045ff8a244f09e8836654f7f0350 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 12 Dec 2023 12:11:44 -0700 Subject: [PATCH 44/63] add (slightly modified) socket.c to test list I've commented-out the `SO_RCVTIMEO` test since we don't support it yet. Signed-off-by: Joel Dice --- test/Makefile | 8 +++++++- test/libc-test.patch | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 test/libc-test.patch diff --git a/test/Makefile b/test/Makefile index 9db4cf974..baf1be287 100644 --- a/test/Makefile +++ b/test/Makefile @@ -23,6 +23,8 @@ WASI_SNAPSHOT ?= preview1 LIBC_TEST_URL ?= https://github.com/bytecodealliance/libc-test LIBC_TEST = $(DOWNDIR)/libc-test +# TODO: remove the patch once we support `SO_RCVTIMEO` +LIBC_TEST_PATCH = $(CURDIR)/libc-test.patch LIBRT_URL ?= https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-16/libclang_rt.builtins-wasm32-wasi-16.0.tar.gz LIBRT = $(DOWNDIR)/lib/wasi/libclang_rt.builtins-wasm32.a # TODO: switch to Wasmtime 16 once it's released @@ -45,6 +47,7 @@ $(DOWNDIR): $(LIBC_TEST): | $(DOWNDIR) git clone --depth 1 $(LIBC_TEST_URL) $@ + cd $@ && git apply < $(LIBC_TEST_PATCH) # TODO install target to place into... $(LIBRT): | $(DOWNDIR) @@ -109,6 +112,9 @@ TESTS := \ $(LIBC_TEST)/src/functional/udiv.c \ $(LIBC_TEST)/src/functional/wcsstr.c \ $(LIBC_TEST)/src/functional/wcstol.c +ifeq ($(WASI_SNAPSHOT), preview2) +TESTS += $(LIBC_TEST)/src/functional/socket.c +endif # Part of the problem including more tests is that the `libc-test` # infrastructure code is not all Wasm-compilable. As we include more tests @@ -173,7 +179,7 @@ clean:: ENGINE ?= $(WASMTIME) run ifeq ($(WASI_SNAPSHOT), preview2) -ENGINE += --wasm component-model +ENGINE += --wasm component-model --wasi inherit-network endif ERRS:=$(WASMS:%.wasm=%.wasm.err) diff --git a/test/libc-test.patch b/test/libc-test.patch new file mode 100644 index 000000000..dc764a7bb --- /dev/null +++ b/test/libc-test.patch @@ -0,0 +1,15 @@ +diff --git a/src/functional/socket.c b/src/functional/socket.c +index b62cf98..308d87d 100644 +--- a/src/functional/socket.c ++++ b/src/functional/socket.c +@@ -21,8 +21,8 @@ int main(void) + TESTE(bind(s, (void *)&sa, sizeof sa)==0); + TESTE(getsockname(s, (void *)&sa, (socklen_t[]){sizeof sa})==0); + +- TESTE(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, +- &(struct timeval){.tv_usec=1}, sizeof(struct timeval))==0); ++ /* TESTE(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, */ ++ /* &(struct timeval){.tv_usec=1}, sizeof(struct timeval))==0); */ + + TESTE((c=socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP))>=0); + sa.sin_addr.s_addr = htonl(0x7f000001); From 51124611f5f1b1d355624bcbfda57552474347b7 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 12 Dec 2023 13:18:57 -0700 Subject: [PATCH 45/63] re-enable `check-symbols` Signed-off-by: Joel Dice --- Makefile | 21 +- .../wasm32-wasi-preview2/defined-symbols.txt | 1514 ++++++++ expected/wasm32-wasi-preview2/include-all.c | 173 + .../predefined-macros.txt | 3420 +++++++++++++++++ .../undefined-symbols.txt | 210 + expected/wasm32-wasi-threads/include-all.c | 1 + expected/wasm32-wasi/include-all.c | 1 + 7 files changed, 5338 insertions(+), 2 deletions(-) create mode 100644 expected/wasm32-wasi-preview2/defined-symbols.txt create mode 100644 expected/wasm32-wasi-preview2/include-all.c create mode 100644 expected/wasm32-wasi-preview2/predefined-macros.txt create mode 100644 expected/wasm32-wasi-preview2/undefined-symbols.txt diff --git a/Makefile b/Makefile index 4abba786d..b4172d02b 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ SYSROOT ?= $(CURDIR)/sysroot # A directory to install to for "make install". INSTALL_DIR ?= /usr/local # single or posix; note that pthread support is still a work-in-progress. -TARGET_TRIPLE ?= single +THREAD_MODEL ?= single # preview1 or preview2; the latter is not (yet) compatible with multithreading WASI_SNAPSHOT ?= preview1 # dlmalloc or none @@ -68,6 +68,23 @@ LIBC_BOTTOM_HALF_ALL_SOURCES = \ $(shell find $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) -name \*.c) \ $(shell find $(LIBC_BOTTOM_HALF_SOURCES) -name \*.c)) +ifeq ($(WASI_SNAPSHOT), preview1) +# WASI Preview 1 has minimal socket support, so the following files are not used: +LIBC_BOTTOM_HALF_OMIT_SOURCES := \ + $(addprefix $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)/libc/sys/, \ + socket/__utils.c \ + socket/bind.c \ + socket/connect.c \ + socket/getsockpeername.c \ + socket/listen.c \ + socket/netdb.c \ + socket/socket.c \ + wasi_preview2/descriptor_table.c \ + wasi_preview2/preview2.c \ + ) +LIBC_BOTTOM_HALF_ALL_SOURCES := $(filter-out $(LIBC_BOTTOM_HALF_OMIT_SOURCES),$(LIBC_BOTTOM_HALF_ALL_SOURCES)) +endif + # FIXME(https://reviews.llvm.org/D85567) - due to a bug in LLD the weak # references to a function defined in `chdir.c` only work if `chdir.c` is at the # end of the archive, but once that LLD review lands and propagates into LLVM @@ -833,7 +850,7 @@ check-symbols: startup_files libc # Check that the computed metadata matches the expected metadata. # This ignores whitespace because on Windows the output has CRLF line endings. - : diff -wur "expected/$(TARGET_TRIPLE)" "$(SYSROOT_SHARE)" + diff -wur "expected/$(TARGET_TRIPLE)" "$(SYSROOT_SHARE)" install: finish mkdir -p "$(INSTALL_DIR)" diff --git a/expected/wasm32-wasi-preview2/defined-symbols.txt b/expected/wasm32-wasi-preview2/defined-symbols.txt new file mode 100644 index 000000000..de15caffa --- /dev/null +++ b/expected/wasm32-wasi-preview2/defined-symbols.txt @@ -0,0 +1,1514 @@ +NS_PER_S +_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 +__asctime_r +__assert_fail +__c_dot_utf8 +__c_dot_utf8_locale +__c_locale +__clock +__clock_gettime +__clock_nanosleep +__component_type_object_force_link_imports +__component_type_object_force_link_imports_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 +__des_setkey +__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 +__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 +__putenv +__qsort_r +__rand48_step +__reallocarray +__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 +__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_args_get +__wasi_args_sizes_get +__wasi_clock_res_get +__wasi_clock_time_get +__wasi_environ_get +__wasi_environ_sizes_get +__wasi_fd_advise +__wasi_fd_allocate +__wasi_fd_close +__wasi_fd_datasync +__wasi_fd_fdstat_get +__wasi_fd_fdstat_set_flags +__wasi_fd_fdstat_set_rights +__wasi_fd_filestat_get +__wasi_fd_filestat_set_size +__wasi_fd_filestat_set_times +__wasi_fd_pread +__wasi_fd_prestat_dir_name +__wasi_fd_prestat_get +__wasi_fd_pwrite +__wasi_fd_read +__wasi_fd_readdir +__wasi_fd_renumber +__wasi_fd_seek +__wasi_fd_sync +__wasi_fd_tell +__wasi_fd_write +__wasi_path_create_directory +__wasi_path_filestat_get +__wasi_path_filestat_set_times +__wasi_path_link +__wasi_path_open +__wasi_path_readlink +__wasi_path_remove_directory +__wasi_path_rename +__wasi_path_symlink +__wasi_path_unlink_file +__wasi_poll_oneoff +__wasi_proc_exit +__wasi_random_get +__wasi_sched_yield +__wasi_sock_accept +__wasi_sock_recv +__wasi_sock_send +__wasi_sock_shutdown +__wasi_sockets_utils__any_addr +__wasi_sockets_utils__borrow_network +__wasi_sockets_utils__create_streams +__wasi_sockets_utils__drop_streams +__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__posix_family +__wasi_sockets_utils__stream +__wasi_sockets_utils__tcp_bind +__wasi_sockets_utils__udp_bind +__wasilibc_access +__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_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_register_preopened_fd +__wasilibc_rename_newat +__wasilibc_rename_oldat +__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 +_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 +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 +difftime +dirfd +dirname +div +dprintf +drand48 +drem +dremf +drop_tcp_socket +drop_udp_socket +drop_udp_socket_streams +duplocale +ecvt +encrypt +environ +environment_get_arguments +environment_get_environment +environment_initial_cwd +environment_list_string_free +environment_list_tuple2_string_string_free +environment_option_string_free +environment_tuple2_string_string_free +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 +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_borrow_directory_entry_stream +filesystem_descriptor_drop_borrow +filesystem_descriptor_drop_own +filesystem_descriptor_stat_free +filesystem_directory_entry_free +filesystem_directory_entry_stream_drop_borrow +filesystem_directory_entry_stream_drop_own +filesystem_filesystem_error_code +filesystem_list_u8_free +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 +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 +filesystem_method_descriptor_write_via_stream +filesystem_method_directory_entry_stream_read_directory_entry +filesystem_new_timestamp_free +filesystem_option_datetime_free +filesystem_option_directory_entry_free +filesystem_option_error_code_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_filesize_error_code_free +filesystem_result_metadata_hash_value_error_code_free +filesystem_result_option_directory_entry_error_code_free +filesystem_result_own_descriptor_error_code_free +filesystem_result_own_directory_entry_stream_error_code_free +filesystem_result_own_input_stream_error_code_free +filesystem_result_own_output_stream_error_code_free +filesystem_result_string_error_code_free +filesystem_result_tuple2_list_u8_bool_error_code_free +filesystem_result_void_error_code_free +filesystem_tuple2_list_u8_bool_free +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 +freeaddrinfo +freelocale +freopen +freopen64 +frexp +frexpf +frexpl +fscanf +fseek +fseeko +fseeko64 +fsetpos +fsetpos64 +fstat +fstatat +fsync +ftell +ftello +ftello64 +ftime +ftruncate +futimens +futimesat +fwide +fwprintf +fwrite +fwrite_unlocked +fwscanf +gai_strerror +gcvt +get_avphys_pages +get_nprocs +get_nprocs_conf +get_phys_pages +getaddrinfo +getc +getc_unlocked +getchar +getchar_unlocked +getcwd +getdate +getdate_err +getdelim +getdomainname +getentropy +getenv +gethostbyaddr +gethostbyname +gethostid +getline +getnameinfo +getopt +getopt_long +getopt_long_only +getpagesize +getpeername +getpid +getprotobyname +getrusage +getservbyname +getservbyport +getsockname +getsockopt +getsubopt +gettimeofday +getw +getwc +getwc_unlocked +getwchar +getwchar_unlocked +glob +glob64 +globfree +globfree64 +gmtime +gmtime_r +h_errno +hcreate +hcreate_r +hdestroy +hdestroy_r +hsearch +hsearch_r +hstrerror +htonl +htons +hypot +hypotf +hypotl +iconv +iconv_close +iconv_open +ilogb +ilogbf +ilogbl +imaxabs +imaxdiv +imports_string_dup +imports_string_free +imports_string_set +in6addr_any +in6addr_loopback +index +inet_aton +inet_ntop +inet_pton +initstate +insque +instance_network_instance_network +io_error_borrow_error +io_error_error_drop_borrow +io_error_error_drop_own +io_error_method_error_to_debug_string +ioctl +ip_name_lookup_borrow_resolve_address_stream +ip_name_lookup_ip_address_free +ip_name_lookup_method_resolve_address_stream_resolve_next_address +ip_name_lookup_method_resolve_address_stream_subscribe +ip_name_lookup_option_ip_address_free +ip_name_lookup_resolve_address_stream_drop_borrow +ip_name_lookup_resolve_address_stream_drop_own +ip_name_lookup_resolve_addresses +ip_name_lookup_result_option_ip_address_error_code_free +ip_name_lookup_result_own_resolve_address_stream_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_now +monotonic_clock_resolution +monotonic_clock_subscribe_duration +monotonic_clock_subscribe_instant +mrand48 +munmap +nan +nanf +nanl +nanosleep +nearbyint +nearbyintf +nearbyintl +network_borrow_network +network_ip_address_free +network_ip_socket_address_free +network_network_drop_borrow +network_network_drop_own +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 +poll_borrow_pollable +poll_list_borrow_pollable_free +poll_list_u32_free +poll_method_pollable_block +poll_method_pollable_ready +poll_poll +poll_pollable_drop_borrow +poll_pollable_drop_own +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 +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_insecure_seed +random_list_u8_free +read +readdir +readlink +readlinkat +readv +realloc +reallocarray +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 +sprintf +sqrt +sqrtf +sqrtl +srand +srand48 +srandom +sscanf +stat +stderr +stderr_get_stderr +stdin +stdin_get_stdin +stdout +stdout_get_stdout +stpcpy +stpncpy +strcasecmp +strcasecmp_l +strcasestr +strcat +strchr +strchrnul +strcmp +strcoll +strcoll_l +strcpy +strcspn +strdup +streams_borrow_input_stream +streams_borrow_output_stream +streams_input_stream_drop_borrow +streams_input_stream_drop_own +streams_list_u8_free +streams_method_input_stream_blocking_read +streams_method_input_stream_blocking_skip +streams_method_input_stream_read +streams_method_input_stream_skip +streams_method_input_stream_subscribe +streams_method_output_stream_blocking_flush +streams_method_output_stream_blocking_splice +streams_method_output_stream_blocking_write_and_flush +streams_method_output_stream_blocking_write_zeroes_and_flush +streams_method_output_stream_check_write +streams_method_output_stream_flush +streams_method_output_stream_splice +streams_method_output_stream_subscribe +streams_method_output_stream_write +streams_method_output_stream_write_zeroes +streams_output_stream_drop_borrow +streams_output_stream_drop_own +streams_result_list_u8_stream_error_free +streams_result_u64_stream_error_free +streams_result_void_stream_error_free +streams_stream_error_free +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 +tcp_accept +tcp_bind +tcp_borrow_tcp_socket +tcp_connect +tcp_create_socket_create_tcp_socket +tcp_create_socket_result_own_tcp_socket_error_code_free +tcp_getpeername +tcp_getsockname +tcp_getsockopt +tcp_ip_socket_address_free +tcp_listen +tcp_method_tcp_socket_accept +tcp_method_tcp_socket_address_family +tcp_method_tcp_socket_finish_bind +tcp_method_tcp_socket_finish_connect +tcp_method_tcp_socket_finish_listen +tcp_method_tcp_socket_hop_limit +tcp_method_tcp_socket_ipv6_only +tcp_method_tcp_socket_is_listening +tcp_method_tcp_socket_keep_alive_count +tcp_method_tcp_socket_keep_alive_enabled +tcp_method_tcp_socket_keep_alive_idle_time +tcp_method_tcp_socket_keep_alive_interval +tcp_method_tcp_socket_local_address +tcp_method_tcp_socket_receive_buffer_size +tcp_method_tcp_socket_remote_address +tcp_method_tcp_socket_send_buffer_size +tcp_method_tcp_socket_set_hop_limit +tcp_method_tcp_socket_set_ipv6_only +tcp_method_tcp_socket_set_keep_alive_count +tcp_method_tcp_socket_set_keep_alive_enabled +tcp_method_tcp_socket_set_keep_alive_idle_time +tcp_method_tcp_socket_set_keep_alive_interval +tcp_method_tcp_socket_set_listen_backlog_size +tcp_method_tcp_socket_set_receive_buffer_size +tcp_method_tcp_socket_set_send_buffer_size +tcp_method_tcp_socket_shutdown +tcp_method_tcp_socket_start_bind +tcp_method_tcp_socket_start_connect +tcp_method_tcp_socket_start_listen +tcp_method_tcp_socket_subscribe +tcp_recvfrom +tcp_result_bool_error_code_free +tcp_result_duration_error_code_free +tcp_result_ip_socket_address_error_code_free +tcp_result_tuple2_own_input_stream_own_output_stream_error_code_free +tcp_result_tuple3_own_tcp_socket_own_input_stream_own_output_stream_error_code_free +tcp_result_u32_error_code_free +tcp_result_u64_error_code_free +tcp_result_u8_error_code_free +tcp_result_void_error_code_free +tcp_sendto +tcp_setsockopt +tcp_shutdown +tcp_socket +tcp_tcp_socket_drop_borrow +tcp_tcp_socket_drop_own +tdelete +tdestroy +telldir +terminal_input_borrow_terminal_input +terminal_input_terminal_input_drop_borrow +terminal_input_terminal_input_drop_own +terminal_output_borrow_terminal_output +terminal_output_terminal_output_drop_borrow +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_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 +twalk +udp_accept +udp_bind +udp_borrow_incoming_datagram_stream +udp_borrow_outgoing_datagram_stream +udp_borrow_udp_socket +udp_connect +udp_create_socket_create_udp_socket +udp_create_socket_result_own_udp_socket_error_code_free +udp_getpeername +udp_getsockname +udp_getsockopt +udp_incoming_datagram_free +udp_incoming_datagram_stream_drop_borrow +udp_incoming_datagram_stream_drop_own +udp_ip_socket_address_free +udp_list_incoming_datagram_free +udp_list_outgoing_datagram_free +udp_list_u8_free +udp_listen +udp_method_incoming_datagram_stream_receive +udp_method_incoming_datagram_stream_subscribe +udp_method_outgoing_datagram_stream_check_send +udp_method_outgoing_datagram_stream_send +udp_method_outgoing_datagram_stream_subscribe +udp_method_udp_socket_address_family +udp_method_udp_socket_finish_bind +udp_method_udp_socket_ipv6_only +udp_method_udp_socket_local_address +udp_method_udp_socket_receive_buffer_size +udp_method_udp_socket_remote_address +udp_method_udp_socket_send_buffer_size +udp_method_udp_socket_set_ipv6_only +udp_method_udp_socket_set_receive_buffer_size +udp_method_udp_socket_set_send_buffer_size +udp_method_udp_socket_set_unicast_hop_limit +udp_method_udp_socket_start_bind +udp_method_udp_socket_stream +udp_method_udp_socket_subscribe +udp_method_udp_socket_unicast_hop_limit +udp_option_ip_socket_address_free +udp_outgoing_datagram_free +udp_outgoing_datagram_stream_drop_borrow +udp_outgoing_datagram_stream_drop_own +udp_recvfrom +udp_result_bool_error_code_free +udp_result_ip_socket_address_error_code_free +udp_result_list_incoming_datagram_error_code_free +udp_result_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_error_code_free +udp_result_u64_error_code_free +udp_result_u8_error_code_free +udp_result_void_error_code_free +udp_sendto +udp_setsockopt +udp_shutdown +udp_socket +udp_udp_socket_drop_borrow +udp_udp_socket_drop_own +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_now +wall_clock_resolution +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 diff --git a/expected/wasm32-wasi-preview2/include-all.c b/expected/wasm32-wasi-preview2/include-all.c new file mode 100644 index 000000000..54a1b6a4f --- /dev/null +++ b/expected/wasm32-wasi-preview2/include-all.c @@ -0,0 +1,173 @@ +#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 <__wasi_snapshot.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 diff --git a/expected/wasm32-wasi-preview2/predefined-macros.txt b/expected/wasm32-wasi-preview2/predefined-macros.txt new file mode 100644 index 000000000..4396d6345 --- /dev/null +++ b/expected/wasm32-wasi-preview2/predefined-macros.txt @@ -0,0 +1,3420 @@ +#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 __WASI_FILETYPE_BLOCK_DEVICE +#define DT_CHR __WASI_FILETYPE_CHARACTER_DEVICE +#define DT_DIR __WASI_FILETYPE_DIRECTORY +#define DT_FIFO __WASI_FILETYPE_SOCKET_STREAM +#define DT_LNK __WASI_FILETYPE_SYMBOLIC_LINK +#define DT_REG __WASI_FILETYPE_REGULAR_FILE +#define DT_UNKNOWN __WASI_FILETYPE_UNKNOWN +#define D_FMT 0x20029 +#define D_T_FMT 0x20028 +#define E2BIG __WASI_ERRNO_2BIG +#define EACCES __WASI_ERRNO_ACCES +#define EACCESS 2 +#define EADDRINUSE __WASI_ERRNO_ADDRINUSE +#define EADDRNOTAVAIL __WASI_ERRNO_ADDRNOTAVAIL +#define EAFNOSUPPORT __WASI_ERRNO_AFNOSUPPORT +#define EAGAIN __WASI_ERRNO_AGAIN +#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 __WASI_ERRNO_ALREADY +#define EBADF __WASI_ERRNO_BADF +#define EBADID 5 +#define EBADMSG __WASI_ERRNO_BADMSG +#define EBADOP 4 +#define EBUSY __WASI_ERRNO_BUSY +#define EC 247 +#define ECANCELED __WASI_ERRNO_CANCELED +#define ECHILD __WASI_ERRNO_CHILD +#define ECONNABORTED __WASI_ERRNO_CONNABORTED +#define ECONNREFUSED __WASI_ERRNO_CONNREFUSED +#define ECONNRESET __WASI_ERRNO_CONNRESET +#define EDEADLK __WASI_ERRNO_DEADLK +#define EDESTADDRREQ __WASI_ERRNO_DESTADDRREQ +#define EDOM __WASI_ERRNO_DOM +#define EDQUOT __WASI_ERRNO_DQUOT +#define EEXIST __WASI_ERRNO_EXIST +#define EEXISTS 6 +#define EFAULT __WASI_ERRNO_FAULT +#define EFBIG __WASI_ERRNO_FBIG +#define EFD_CLOEXEC O_CLOEXEC +#define EFD_NONBLOCK O_NONBLOCK +#define EFD_SEMAPHORE 1 +#define EHOSTUNREACH __WASI_ERRNO_HOSTUNREACH +#define EIDRM __WASI_ERRNO_IDRM +#define EILSEQ __WASI_ERRNO_ILSEQ +#define EINPROGRESS __WASI_ERRNO_INPROGRESS +#define EINTR __WASI_ERRNO_INTR +#define EINVAL __WASI_ERRNO_INVAL +#define EIO __WASI_ERRNO_IO +#define EISCONN __WASI_ERRNO_ISCONN +#define EISDIR __WASI_ERRNO_ISDIR +#define EL 248 +#define ELOOP __WASI_ERRNO_LOOP +#define EMFILE __WASI_ERRNO_MFILE +#define EMLINK __WASI_ERRNO_MLINK +#define EMSGSIZE __WASI_ERRNO_MSGSIZE +#define EMULTIHOP __WASI_ERRNO_MULTIHOP +#define ENAMETOOLONG __WASI_ERRNO_NAMETOOLONG +#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 __WASI_ERRNO_NETDOWN +#define ENETRESET __WASI_ERRNO_NETRESET +#define ENETUNREACH __WASI_ERRNO_NETUNREACH +#define ENFILE __WASI_ERRNO_NFILE +#define ENOBUFS __WASI_ERRNO_NOBUFS +#define ENODEV __WASI_ERRNO_NODEV +#define ENOENT __WASI_ERRNO_NOENT +#define ENOEXEC __WASI_ERRNO_NOEXEC +#define ENOLCK __WASI_ERRNO_NOLCK +#define ENOLINK __WASI_ERRNO_NOLINK +#define ENOMEM __WASI_ERRNO_NOMEM +#define ENOMSG __WASI_ERRNO_NOMSG +#define ENOPROTOOPT __WASI_ERRNO_NOPROTOOPT +#define ENOSPACE 3 +#define ENOSPC __WASI_ERRNO_NOSPC +#define ENOSYS __WASI_ERRNO_NOSYS +#define ENOTCAPABLE __WASI_ERRNO_NOTCAPABLE +#define ENOTCONN __WASI_ERRNO_NOTCONN +#define ENOTDIR __WASI_ERRNO_NOTDIR +#define ENOTEMPTY __WASI_ERRNO_NOTEMPTY +#define ENOTFOUND 1 +#define ENOTRECOVERABLE __WASI_ERRNO_NOTRECOVERABLE +#define ENOTSOCK __WASI_ERRNO_NOTSOCK +#define ENOTSUP __WASI_ERRNO_NOTSUP +#define ENOTTY __WASI_ERRNO_NOTTY +#define ENOUSER 7 +#define ENV_ESC 2 +#define ENV_USERVAR 3 +#define ENXIO __WASI_ERRNO_NXIO +#define EOF (-1) +#define EOPNOTSUPP ENOTSUP +#define EOR 239 +#define EOVERFLOW __WASI_ERRNO_OVERFLOW +#define EOWNERDEAD __WASI_ERRNO_OWNERDEAD +#define EPERM __WASI_ERRNO_PERM +#define EPIPE __WASI_ERRNO_PIPE +#define EPROTO __WASI_ERRNO_PROTO +#define EPROTONOSUPPORT __WASI_ERRNO_PROTONOSUPPORT +#define EPROTOTYPE __WASI_ERRNO_PROTOTYPE +#define ERA 0x2002C +#define ERANGE __WASI_ERRNO_RANGE +#define ERA_D_FMT 0x2002E +#define ERA_D_T_FMT 0x20030 +#define ERA_T_FMT 0x20031 +#define EROFS __WASI_ERRNO_ROFS +#define ERROR 05 +#define ESPIPE __WASI_ERRNO_SPIPE +#define ESRCH __WASI_ERRNO_SRCH +#define ESTALE __WASI_ERRNO_STALE +#define ETIMEDOUT __WASI_ERRNO_TIMEDOUT +#define ETXTBSY __WASI_ERRNO_TXTBSY +#define EUNDEF 0 +#define EWOULDBLOCK EAGAIN +#define EXDEV __WASI_ERRNO_XDEV +#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 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 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_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 __WASI_FDFLAGS_APPEND +#define O_CLOEXEC (0) +#define O_CREAT (__WASI_OFLAGS_CREAT << 12) +#define O_DIRECTORY (__WASI_OFLAGS_DIRECTORY << 12) +#define O_DSYNC __WASI_FDFLAGS_DSYNC +#define O_EXCL (__WASI_OFLAGS_EXCL << 12) +#define O_EXEC (0x02000000) +#define O_NOCTTY (0) +#define O_NOFOLLOW (0x01000000) +#define O_NONBLOCK __WASI_FDFLAGS_NONBLOCK +#define O_RDONLY (0x04000000) +#define O_RDWR (O_RDONLY | O_WRONLY) +#define O_RSYNC __WASI_FDFLAGS_RSYNC +#define O_SEARCH (0x08000000) +#define O_SYNC __WASI_FDFLAGS_SYNC +#define O_TRUNC (__WASI_OFLAGS_TRUNC << 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 __WASI_ADVICE_DONTNEED +#define POSIX_FADV_NOREUSE __WASI_ADVICE_NOREUSE +#define POSIX_FADV_NORMAL __WASI_ADVICE_NORMAL +#define POSIX_FADV_RANDOM __WASI_ADVICE_RANDOM +#define POSIX_FADV_SEQUENTIAL __WASI_ADVICE_SEQUENTIAL +#define POSIX_FADV_WILLNEED __WASI_ADVICE_WILLNEED +#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 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 __WASI_WHENCE_CUR +#define SEEK_END __WASI_WHENCE_END +#define SEEK_SET __WASI_WHENCE_SET +#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 __WASI_SDFLAGS_RD +#define SHUT_RDWR (SHUT_RD | SHUT_WR) +#define SHUT_WR __WASI_SDFLAGS_WR +#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 SOCK_CLOEXEC (0x00002000) +#define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM +#define SOCK_NONBLOCK (0x00004000) +#define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM +#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_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 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 (0xc000) +#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 __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME +#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_AXFR ns_t_axfr +#define T_CNAME ns_t_cname +#define T_DNAME ns_t_dname +#define T_EID ns_t_eid +#define T_FMT 0x2002A +#define T_FMT_AMPM 0x2002B +#define T_GPOS ns_t_gpos +#define T_HINFO ns_t_hinfo +#define T_ISDN ns_t_isdn +#define T_IXFR ns_t_ixfr +#define T_KEY ns_t_key +#define T_LOC ns_t_loc +#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_NIMLOC ns_t_nimloc +#define T_NS ns_t_ns +#define T_NSAP ns_t_nsap +#define T_NSAP_PTR ns_t_nsap_ptr +#define T_NULL ns_t_null +#define T_NXT ns_t_nxt +#define T_PTR ns_t_ptr +#define T_PX ns_t_px +#define T_RP ns_t_rp +#define T_RT ns_t_rt +#define T_SIG ns_t_sig +#define T_SOA ns_t_soa +#define T_SRV ns_t_srv +#define T_TSIG ns_t_tsig +#define T_TXT ns_t_txt +#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 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_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 _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_THREAD_ATTR_STACKADDR _POSIX_VERSION +#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION +#define _POSIX_THREAD_CPUTIME _POSIX_VERSION +#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 +#define _POSIX_THREAD_KEYS_MAX 128 +#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION +#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 _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_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_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_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 __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_ADVICE_DONTNEED (UINT8_C(4)) +#define __WASI_ADVICE_NOREUSE (UINT8_C(5)) +#define __WASI_ADVICE_NORMAL (UINT8_C(0)) +#define __WASI_ADVICE_RANDOM (UINT8_C(2)) +#define __WASI_ADVICE_SEQUENTIAL (UINT8_C(1)) +#define __WASI_ADVICE_WILLNEED (UINT8_C(3)) +#define __WASI_CLOCKID_MONOTONIC (UINT32_C(1)) +#define __WASI_CLOCKID_PROCESS_CPUTIME_ID (UINT32_C(2)) +#define __WASI_CLOCKID_REALTIME (UINT32_C(0)) +#define __WASI_CLOCKID_THREAD_CPUTIME_ID (UINT32_C(3)) +#define __WASI_DIRCOOKIE_START (UINT64_C(0)) +#define __WASI_ERRNO_2BIG (UINT16_C(1)) +#define __WASI_ERRNO_ACCES (UINT16_C(2)) +#define __WASI_ERRNO_ADDRINUSE (UINT16_C(3)) +#define __WASI_ERRNO_ADDRNOTAVAIL (UINT16_C(4)) +#define __WASI_ERRNO_AFNOSUPPORT (UINT16_C(5)) +#define __WASI_ERRNO_AGAIN (UINT16_C(6)) +#define __WASI_ERRNO_ALREADY (UINT16_C(7)) +#define __WASI_ERRNO_BADF (UINT16_C(8)) +#define __WASI_ERRNO_BADMSG (UINT16_C(9)) +#define __WASI_ERRNO_BUSY (UINT16_C(10)) +#define __WASI_ERRNO_CANCELED (UINT16_C(11)) +#define __WASI_ERRNO_CHILD (UINT16_C(12)) +#define __WASI_ERRNO_CONNABORTED (UINT16_C(13)) +#define __WASI_ERRNO_CONNREFUSED (UINT16_C(14)) +#define __WASI_ERRNO_CONNRESET (UINT16_C(15)) +#define __WASI_ERRNO_DEADLK (UINT16_C(16)) +#define __WASI_ERRNO_DESTADDRREQ (UINT16_C(17)) +#define __WASI_ERRNO_DOM (UINT16_C(18)) +#define __WASI_ERRNO_DQUOT (UINT16_C(19)) +#define __WASI_ERRNO_EXIST (UINT16_C(20)) +#define __WASI_ERRNO_FAULT (UINT16_C(21)) +#define __WASI_ERRNO_FBIG (UINT16_C(22)) +#define __WASI_ERRNO_HOSTUNREACH (UINT16_C(23)) +#define __WASI_ERRNO_IDRM (UINT16_C(24)) +#define __WASI_ERRNO_ILSEQ (UINT16_C(25)) +#define __WASI_ERRNO_INPROGRESS (UINT16_C(26)) +#define __WASI_ERRNO_INTR (UINT16_C(27)) +#define __WASI_ERRNO_INVAL (UINT16_C(28)) +#define __WASI_ERRNO_IO (UINT16_C(29)) +#define __WASI_ERRNO_ISCONN (UINT16_C(30)) +#define __WASI_ERRNO_ISDIR (UINT16_C(31)) +#define __WASI_ERRNO_LOOP (UINT16_C(32)) +#define __WASI_ERRNO_MFILE (UINT16_C(33)) +#define __WASI_ERRNO_MLINK (UINT16_C(34)) +#define __WASI_ERRNO_MSGSIZE (UINT16_C(35)) +#define __WASI_ERRNO_MULTIHOP (UINT16_C(36)) +#define __WASI_ERRNO_NAMETOOLONG (UINT16_C(37)) +#define __WASI_ERRNO_NETDOWN (UINT16_C(38)) +#define __WASI_ERRNO_NETRESET (UINT16_C(39)) +#define __WASI_ERRNO_NETUNREACH (UINT16_C(40)) +#define __WASI_ERRNO_NFILE (UINT16_C(41)) +#define __WASI_ERRNO_NOBUFS (UINT16_C(42)) +#define __WASI_ERRNO_NODEV (UINT16_C(43)) +#define __WASI_ERRNO_NOENT (UINT16_C(44)) +#define __WASI_ERRNO_NOEXEC (UINT16_C(45)) +#define __WASI_ERRNO_NOLCK (UINT16_C(46)) +#define __WASI_ERRNO_NOLINK (UINT16_C(47)) +#define __WASI_ERRNO_NOMEM (UINT16_C(48)) +#define __WASI_ERRNO_NOMSG (UINT16_C(49)) +#define __WASI_ERRNO_NOPROTOOPT (UINT16_C(50)) +#define __WASI_ERRNO_NOSPC (UINT16_C(51)) +#define __WASI_ERRNO_NOSYS (UINT16_C(52)) +#define __WASI_ERRNO_NOTCAPABLE (UINT16_C(76)) +#define __WASI_ERRNO_NOTCONN (UINT16_C(53)) +#define __WASI_ERRNO_NOTDIR (UINT16_C(54)) +#define __WASI_ERRNO_NOTEMPTY (UINT16_C(55)) +#define __WASI_ERRNO_NOTRECOVERABLE (UINT16_C(56)) +#define __WASI_ERRNO_NOTSOCK (UINT16_C(57)) +#define __WASI_ERRNO_NOTSUP (UINT16_C(58)) +#define __WASI_ERRNO_NOTTY (UINT16_C(59)) +#define __WASI_ERRNO_NXIO (UINT16_C(60)) +#define __WASI_ERRNO_OVERFLOW (UINT16_C(61)) +#define __WASI_ERRNO_OWNERDEAD (UINT16_C(62)) +#define __WASI_ERRNO_PERM (UINT16_C(63)) +#define __WASI_ERRNO_PIPE (UINT16_C(64)) +#define __WASI_ERRNO_PROTO (UINT16_C(65)) +#define __WASI_ERRNO_PROTONOSUPPORT (UINT16_C(66)) +#define __WASI_ERRNO_PROTOTYPE (UINT16_C(67)) +#define __WASI_ERRNO_RANGE (UINT16_C(68)) +#define __WASI_ERRNO_ROFS (UINT16_C(69)) +#define __WASI_ERRNO_SPIPE (UINT16_C(70)) +#define __WASI_ERRNO_SRCH (UINT16_C(71)) +#define __WASI_ERRNO_STALE (UINT16_C(72)) +#define __WASI_ERRNO_SUCCESS (UINT16_C(0)) +#define __WASI_ERRNO_TIMEDOUT (UINT16_C(73)) +#define __WASI_ERRNO_TXTBSY (UINT16_C(74)) +#define __WASI_ERRNO_XDEV (UINT16_C(75)) +#define __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP ((__wasi_eventrwflags_t)(1 << 0)) +#define __WASI_EVENTTYPE_CLOCK (UINT8_C(0)) +#define __WASI_EVENTTYPE_FD_READ (UINT8_C(1)) +#define __WASI_EVENTTYPE_FD_WRITE (UINT8_C(2)) +#define __WASI_FDFLAGS_APPEND ((__wasi_fdflags_t)(1 << 0)) +#define __WASI_FDFLAGS_DSYNC ((__wasi_fdflags_t)(1 << 1)) +#define __WASI_FDFLAGS_NONBLOCK ((__wasi_fdflags_t)(1 << 2)) +#define __WASI_FDFLAGS_RSYNC ((__wasi_fdflags_t)(1 << 3)) +#define __WASI_FDFLAGS_SYNC ((__wasi_fdflags_t)(1 << 4)) +#define __WASI_FILETYPE_BLOCK_DEVICE (UINT8_C(1)) +#define __WASI_FILETYPE_CHARACTER_DEVICE (UINT8_C(2)) +#define __WASI_FILETYPE_DIRECTORY (UINT8_C(3)) +#define __WASI_FILETYPE_REGULAR_FILE (UINT8_C(4)) +#define __WASI_FILETYPE_SOCKET_DGRAM (UINT8_C(5)) +#define __WASI_FILETYPE_SOCKET_STREAM (UINT8_C(6)) +#define __WASI_FILETYPE_SYMBOLIC_LINK (UINT8_C(7)) +#define __WASI_FILETYPE_UNKNOWN (UINT8_C(0)) +#define __WASI_FSTFLAGS_ATIM ((__wasi_fstflags_t)(1 << 0)) +#define __WASI_FSTFLAGS_ATIM_NOW ((__wasi_fstflags_t)(1 << 1)) +#define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)(1 << 2)) +#define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)(1 << 3)) +#define __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW ((__wasi_lookupflags_t)(1 << 0)) +#define __WASI_OFLAGS_CREAT ((__wasi_oflags_t)(1 << 0)) +#define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)(1 << 1)) +#define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)(1 << 2)) +#define __WASI_OFLAGS_TRUNC ((__wasi_oflags_t)(1 << 3)) +#define __WASI_PREOPENTYPE_DIR (UINT8_C(0)) +#define __WASI_RIFLAGS_RECV_PEEK ((__wasi_riflags_t)(1 << 0)) +#define __WASI_RIFLAGS_RECV_WAITALL ((__wasi_riflags_t)(1 << 1)) +#define __WASI_RIGHTS_FD_ADVISE ((__wasi_rights_t)(1 << 7)) +#define __WASI_RIGHTS_FD_ALLOCATE ((__wasi_rights_t)(1 << 8)) +#define __WASI_RIGHTS_FD_DATASYNC ((__wasi_rights_t)(1 << 0)) +#define __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)(1 << 3)) +#define __WASI_RIGHTS_FD_FILESTAT_GET ((__wasi_rights_t)(1 << 21)) +#define __WASI_RIGHTS_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 22)) +#define __WASI_RIGHTS_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 23)) +#define __WASI_RIGHTS_FD_READ ((__wasi_rights_t)(1 << 1)) +#define __WASI_RIGHTS_FD_READDIR ((__wasi_rights_t)(1 << 14)) +#define __WASI_RIGHTS_FD_SEEK ((__wasi_rights_t)(1 << 2)) +#define __WASI_RIGHTS_FD_SYNC ((__wasi_rights_t)(1 << 4)) +#define __WASI_RIGHTS_FD_TELL ((__wasi_rights_t)(1 << 5)) +#define __WASI_RIGHTS_FD_WRITE ((__wasi_rights_t)(1 << 6)) +#define __WASI_RIGHTS_PATH_CREATE_DIRECTORY ((__wasi_rights_t)(1 << 9)) +#define __WASI_RIGHTS_PATH_CREATE_FILE ((__wasi_rights_t)(1 << 10)) +#define __WASI_RIGHTS_PATH_FILESTAT_GET ((__wasi_rights_t)(1 << 18)) +#define __WASI_RIGHTS_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 19)) +#define __WASI_RIGHTS_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 20)) +#define __WASI_RIGHTS_PATH_LINK_SOURCE ((__wasi_rights_t)(1 << 11)) +#define __WASI_RIGHTS_PATH_LINK_TARGET ((__wasi_rights_t)(1 << 12)) +#define __WASI_RIGHTS_PATH_OPEN ((__wasi_rights_t)(1 << 13)) +#define __WASI_RIGHTS_PATH_READLINK ((__wasi_rights_t)(1 << 15)) +#define __WASI_RIGHTS_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)(1 << 25)) +#define __WASI_RIGHTS_PATH_RENAME_SOURCE ((__wasi_rights_t)(1 << 16)) +#define __WASI_RIGHTS_PATH_RENAME_TARGET ((__wasi_rights_t)(1 << 17)) +#define __WASI_RIGHTS_PATH_SYMLINK ((__wasi_rights_t)(1 << 24)) +#define __WASI_RIGHTS_PATH_UNLINK_FILE ((__wasi_rights_t)(1 << 26)) +#define __WASI_RIGHTS_POLL_FD_READWRITE ((__wasi_rights_t)(1 << 27)) +#define __WASI_RIGHTS_SOCK_ACCEPT ((__wasi_rights_t)(1 << 29)) +#define __WASI_RIGHTS_SOCK_SHUTDOWN ((__wasi_rights_t)(1 << 28)) +#define __WASI_ROFLAGS_RECV_DATA_TRUNCATED ((__wasi_roflags_t)(1 << 0)) +#define __WASI_SDFLAGS_RD ((__wasi_sdflags_t)(1 << 0)) +#define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)(1 << 1)) +#define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)(1 << 0)) +#define __WASI_WHENCE_CUR (UINT8_C(1)) +#define __WASI_WHENCE_END (UINT8_C(2)) +#define __WASI_WHENCE_SET (UINT8_C(0)) +#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 __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_environ_h +#define __wasi_libc_find_relpath_h +#define __wasi_libc_h +#define __wasi_libc_nocwd_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 __wasilibc_use_preview2 1 +#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 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 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 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-wasi-preview2/undefined-symbols.txt b/expected/wasm32-wasi-preview2/undefined-symbols.txt new file mode 100644 index 000000000..1a37471ea --- /dev/null +++ b/expected/wasm32-wasi-preview2/undefined-symbols.txt @@ -0,0 +1,210 @@ +__addtf3 +__divtf3 +__eqtf2 +__extenddftf2 +__extendsftf2 +__fixtfdi +__fixtfsi +__fixunstfsi +__floatsitf +__floatunsitf +__getf2 +__gttf2 +__heap_base +__heap_end +__imported_wasi_snapshot_preview1_args_get +__imported_wasi_snapshot_preview1_args_sizes_get +__imported_wasi_snapshot_preview1_clock_res_get +__imported_wasi_snapshot_preview1_clock_time_get +__imported_wasi_snapshot_preview1_environ_get +__imported_wasi_snapshot_preview1_environ_sizes_get +__imported_wasi_snapshot_preview1_fd_advise +__imported_wasi_snapshot_preview1_fd_allocate +__imported_wasi_snapshot_preview1_fd_close +__imported_wasi_snapshot_preview1_fd_datasync +__imported_wasi_snapshot_preview1_fd_fdstat_get +__imported_wasi_snapshot_preview1_fd_fdstat_set_flags +__imported_wasi_snapshot_preview1_fd_fdstat_set_rights +__imported_wasi_snapshot_preview1_fd_filestat_get +__imported_wasi_snapshot_preview1_fd_filestat_set_size +__imported_wasi_snapshot_preview1_fd_filestat_set_times +__imported_wasi_snapshot_preview1_fd_pread +__imported_wasi_snapshot_preview1_fd_prestat_dir_name +__imported_wasi_snapshot_preview1_fd_prestat_get +__imported_wasi_snapshot_preview1_fd_pwrite +__imported_wasi_snapshot_preview1_fd_read +__imported_wasi_snapshot_preview1_fd_readdir +__imported_wasi_snapshot_preview1_fd_renumber +__imported_wasi_snapshot_preview1_fd_seek +__imported_wasi_snapshot_preview1_fd_sync +__imported_wasi_snapshot_preview1_fd_tell +__imported_wasi_snapshot_preview1_fd_write +__imported_wasi_snapshot_preview1_path_create_directory +__imported_wasi_snapshot_preview1_path_filestat_get +__imported_wasi_snapshot_preview1_path_filestat_set_times +__imported_wasi_snapshot_preview1_path_link +__imported_wasi_snapshot_preview1_path_open +__imported_wasi_snapshot_preview1_path_readlink +__imported_wasi_snapshot_preview1_path_remove_directory +__imported_wasi_snapshot_preview1_path_rename +__imported_wasi_snapshot_preview1_path_symlink +__imported_wasi_snapshot_preview1_path_unlink_file +__imported_wasi_snapshot_preview1_poll_oneoff +__imported_wasi_snapshot_preview1_proc_exit +__imported_wasi_snapshot_preview1_random_get +__imported_wasi_snapshot_preview1_sched_yield +__imported_wasi_snapshot_preview1_sock_accept +__imported_wasi_snapshot_preview1_sock_recv +__imported_wasi_snapshot_preview1_sock_send +__imported_wasi_snapshot_preview1_sock_shutdown +__letf2 +__lttf2 +__netf2 +__stack_pointer +__subtf3 +__trunctfdf2 +__trunctfsf2 +__unordtf2 +__wasi_preview1_adapter_close_badfd +__wasi_preview1_adapter_open_badfd +__wasm_call_ctors +__wasm_import_environment_get_arguments +__wasm_import_environment_get_environment +__wasm_import_environment_initial_cwd +__wasm_import_exit_exit +__wasm_import_filesystem_descriptor_drop +__wasm_import_filesystem_directory_entry_stream_drop +__wasm_import_filesystem_filesystem_error_code +__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 +__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 +__wasm_import_filesystem_method_descriptor_write_via_stream +__wasm_import_filesystem_method_directory_entry_stream_read_directory_entry +__wasm_import_filesystem_preopens_get_directories +__wasm_import_instance_network_instance_network +__wasm_import_io_error_error_drop +__wasm_import_io_error_method_error_to_debug_string +__wasm_import_ip_name_lookup_method_resolve_address_stream_resolve_next_address +__wasm_import_ip_name_lookup_method_resolve_address_stream_subscribe +__wasm_import_ip_name_lookup_resolve_address_stream_drop +__wasm_import_ip_name_lookup_resolve_addresses +__wasm_import_monotonic_clock_now +__wasm_import_monotonic_clock_resolution +__wasm_import_monotonic_clock_subscribe_duration +__wasm_import_monotonic_clock_subscribe_instant +__wasm_import_network_network_drop +__wasm_import_poll_method_pollable_block +__wasm_import_poll_method_pollable_ready +__wasm_import_poll_poll +__wasm_import_poll_pollable_drop +__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_insecure_seed +__wasm_import_stderr_get_stderr +__wasm_import_stdin_get_stdin +__wasm_import_stdout_get_stdout +__wasm_import_streams_input_stream_drop +__wasm_import_streams_method_input_stream_blocking_read +__wasm_import_streams_method_input_stream_blocking_skip +__wasm_import_streams_method_input_stream_read +__wasm_import_streams_method_input_stream_skip +__wasm_import_streams_method_input_stream_subscribe +__wasm_import_streams_method_output_stream_blocking_flush +__wasm_import_streams_method_output_stream_blocking_splice +__wasm_import_streams_method_output_stream_blocking_write_and_flush +__wasm_import_streams_method_output_stream_blocking_write_zeroes_and_flush +__wasm_import_streams_method_output_stream_check_write +__wasm_import_streams_method_output_stream_flush +__wasm_import_streams_method_output_stream_splice +__wasm_import_streams_method_output_stream_subscribe +__wasm_import_streams_method_output_stream_write +__wasm_import_streams_method_output_stream_write_zeroes +__wasm_import_streams_output_stream_drop +__wasm_import_tcp_create_socket_create_tcp_socket +__wasm_import_tcp_method_tcp_socket_accept +__wasm_import_tcp_method_tcp_socket_address_family +__wasm_import_tcp_method_tcp_socket_finish_bind +__wasm_import_tcp_method_tcp_socket_finish_connect +__wasm_import_tcp_method_tcp_socket_finish_listen +__wasm_import_tcp_method_tcp_socket_hop_limit +__wasm_import_tcp_method_tcp_socket_ipv6_only +__wasm_import_tcp_method_tcp_socket_is_listening +__wasm_import_tcp_method_tcp_socket_keep_alive_count +__wasm_import_tcp_method_tcp_socket_keep_alive_enabled +__wasm_import_tcp_method_tcp_socket_keep_alive_idle_time +__wasm_import_tcp_method_tcp_socket_keep_alive_interval +__wasm_import_tcp_method_tcp_socket_local_address +__wasm_import_tcp_method_tcp_socket_receive_buffer_size +__wasm_import_tcp_method_tcp_socket_remote_address +__wasm_import_tcp_method_tcp_socket_send_buffer_size +__wasm_import_tcp_method_tcp_socket_set_hop_limit +__wasm_import_tcp_method_tcp_socket_set_ipv6_only +__wasm_import_tcp_method_tcp_socket_set_keep_alive_count +__wasm_import_tcp_method_tcp_socket_set_keep_alive_enabled +__wasm_import_tcp_method_tcp_socket_set_keep_alive_idle_time +__wasm_import_tcp_method_tcp_socket_set_keep_alive_interval +__wasm_import_tcp_method_tcp_socket_set_listen_backlog_size +__wasm_import_tcp_method_tcp_socket_set_receive_buffer_size +__wasm_import_tcp_method_tcp_socket_set_send_buffer_size +__wasm_import_tcp_method_tcp_socket_shutdown +__wasm_import_tcp_method_tcp_socket_start_bind +__wasm_import_tcp_method_tcp_socket_start_connect +__wasm_import_tcp_method_tcp_socket_start_listen +__wasm_import_tcp_method_tcp_socket_subscribe +__wasm_import_tcp_tcp_socket_drop +__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_udp_create_socket_create_udp_socket +__wasm_import_udp_incoming_datagram_stream_drop +__wasm_import_udp_method_incoming_datagram_stream_receive +__wasm_import_udp_method_incoming_datagram_stream_subscribe +__wasm_import_udp_method_outgoing_datagram_stream_check_send +__wasm_import_udp_method_outgoing_datagram_stream_send +__wasm_import_udp_method_outgoing_datagram_stream_subscribe +__wasm_import_udp_method_udp_socket_address_family +__wasm_import_udp_method_udp_socket_finish_bind +__wasm_import_udp_method_udp_socket_ipv6_only +__wasm_import_udp_method_udp_socket_local_address +__wasm_import_udp_method_udp_socket_receive_buffer_size +__wasm_import_udp_method_udp_socket_remote_address +__wasm_import_udp_method_udp_socket_send_buffer_size +__wasm_import_udp_method_udp_socket_set_ipv6_only +__wasm_import_udp_method_udp_socket_set_receive_buffer_size +__wasm_import_udp_method_udp_socket_set_send_buffer_size +__wasm_import_udp_method_udp_socket_set_unicast_hop_limit +__wasm_import_udp_method_udp_socket_start_bind +__wasm_import_udp_method_udp_socket_stream +__wasm_import_udp_method_udp_socket_subscribe +__wasm_import_udp_method_udp_socket_unicast_hop_limit +__wasm_import_udp_outgoing_datagram_stream_drop +__wasm_import_udp_udp_socket_drop +__wasm_import_wall_clock_now +__wasm_import_wall_clock_resolution diff --git a/expected/wasm32-wasi-threads/include-all.c b/expected/wasm32-wasi-threads/include-all.c index 28b592438..86b697064 100644 --- a/expected/wasm32-wasi-threads/include-all.c +++ b/expected/wasm32-wasi-threads/include-all.c @@ -60,6 +60,7 @@ #include <__typedef_suseconds_t.h> #include <__typedef_time_t.h> #include <__typedef_uid_t.h> +#include <__wasi_snapshot.h> #include #include #include diff --git a/expected/wasm32-wasi/include-all.c b/expected/wasm32-wasi/include-all.c index 297e48b14..2eafa8ad0 100644 --- a/expected/wasm32-wasi/include-all.c +++ b/expected/wasm32-wasi/include-all.c @@ -60,6 +60,7 @@ #include <__typedef_suseconds_t.h> #include <__typedef_time_t.h> #include <__typedef_uid_t.h> +#include <__wasi_snapshot.h> #include #include #include From fc38c7af173768039e9bddfdf47d9c65383f9a3e Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 12 Dec 2023 13:45:09 -0700 Subject: [PATCH 46/63] add instructions to `make-bindings.sh` Signed-off-by: Joel Dice --- make-bindings.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/make-bindings.sh b/make-bindings.sh index 1801f2fc2..e40483deb 100644 --- a/make-bindings.sh +++ b/make-bindings.sh @@ -1,7 +1,13 @@ #!/bin/bash -# As of this writing, the `wit` directory was copied from -# https://github.com/bytecodealliance/wasmtime/tree/759aa585496adfbe47aefb4fdf9608aabf8d64ac/crates/wasi/wit +# This script will regenerate the WASI Preview 2 bindings. To use it, first +# clone the wit directory from +# https://github.com/bytecodealliance/wasmtime/tree/release-16.0.0/crates/wasi/wit +# (or newer), install +# https://github.com/bytecodealliance/wit-bindgen/releases/tag/wit-bindgen-cli-0.16.0 +# (or newer), and then run the script. +# +# TODO: Automate the above instructions. set -e From 14757da55950d2227c4960f94db2e9ceca71a58f Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 12 Dec 2023 13:45:28 -0700 Subject: [PATCH 47/63] revert spurious whitespace changes Signed-off-by: Joel Dice --- .../cloudlibc/src/libc/sys/ioctl/ioctl.c | 138 +++++++++--------- 1 file changed, 69 insertions(+), 69 deletions(-) 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 3f58afe02..1ffddf0d3 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c @@ -2,17 +2,17 @@ // // SPDX-License-Identifier: BSD-2-Clause -#include -#include #include + #include +#include +#include #ifdef __wasilibc_use_preview2 #include #endif -int ioctl(int fildes, int request, ...) -{ +int ioctl(int fildes, int request, ...) { #ifdef __wasilibc_use_preview2 descriptor_table_entry_t* entry; if (descriptor_table_get_ref(fildes, &entry)) { @@ -44,80 +44,80 @@ int ioctl(int fildes, int request, ...) } #endif // __wasilibc_use_preview2 - switch (request) { + switch (request) { case FIONREAD: { - // Poll the file descriptor to determine how many bytes can be read. - __wasi_subscription_t subscriptions[2] = { - { - .u.tag = __WASI_EVENTTYPE_FD_READ, - .u.u.fd_read.file_descriptor = fildes, - }, - { - .u.tag = __WASI_EVENTTYPE_CLOCK, - .u.u.clock.id = __WASI_CLOCKID_MONOTONIC, - }, - }; - __wasi_event_t events[__arraycount(subscriptions)]; - size_t nevents; - __wasi_errno_t error = __wasi_poll_oneoff( - subscriptions, events, __arraycount(subscriptions), &nevents); - if (error != 0) { - errno = error; - return -1; - } + // Poll the file descriptor to determine how many bytes can be read. + __wasi_subscription_t subscriptions[2] = { + { + .u.tag = __WASI_EVENTTYPE_FD_READ, + .u.u.fd_read.file_descriptor = fildes, + }, + { + .u.tag = __WASI_EVENTTYPE_CLOCK, + .u.u.clock.id = __WASI_CLOCKID_MONOTONIC, + }, + }; + __wasi_event_t events[__arraycount(subscriptions)]; + size_t nevents; + __wasi_errno_t error = __wasi_poll_oneoff( + subscriptions, events, __arraycount(subscriptions), &nevents); + if (error != 0) { + errno = error; + return -1; + } - // Location where result should be written. - va_list ap; - va_start(ap, request); - int* result = va_arg(ap, int*); - va_end(ap); + // Location where result should be written. + va_list ap; + va_start(ap, request); + int *result = va_arg(ap, int *); + va_end(ap); - // Extract number of bytes for reading from poll results. - for (size_t i = 0; i < nevents; ++i) { - __wasi_event_t* event = &events[i]; - if (event->error != 0) { - errno = event->error; - return -1; - } - if (event->type == __WASI_EVENTTYPE_FD_READ) { - *result = event->fd_readwrite.nbytes; - return 0; - } + // Extract number of bytes for reading from poll results. + for (size_t i = 0; i < nevents; ++i) { + __wasi_event_t *event = &events[i]; + if (event->error != 0) { + errno = event->error; + return -1; + } + if (event->type == __WASI_EVENTTYPE_FD_READ) { + *result = event->fd_readwrite.nbytes; + return 0; } + } - // No data available for reading. - *result = 0; - return 0; + // No data available for reading. + *result = 0; + return 0; } case FIONBIO: { - // Obtain the current file descriptor flags. - __wasi_fdstat_t fds; - __wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds); - if (error != 0) { - errno = error; - return -1; - } + // Obtain the current file descriptor flags. + __wasi_fdstat_t fds; + __wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds); + if (error != 0) { + errno = error; + return -1; + } - // Toggle the non-blocking flag based on the argument. - va_list ap; - va_start(ap, request); - if (*va_arg(ap, const int*) != 0) - fds.fs_flags |= __WASI_FDFLAGS_NONBLOCK; - else - fds.fs_flags &= ~__WASI_FDFLAGS_NONBLOCK; - va_end(ap); + // Toggle the non-blocking flag based on the argument. + va_list ap; + va_start(ap, request); + if (*va_arg(ap, const int *) != 0) + fds.fs_flags |= __WASI_FDFLAGS_NONBLOCK; + else + fds.fs_flags &= ~__WASI_FDFLAGS_NONBLOCK; + va_end(ap); - // Update the file descriptor flags. - error = __wasi_fd_fdstat_set_flags(fildes, fds.fs_flags); - if (error != 0) { - errno = error; - return -1; - } - return 0; - } - default: - // Invalid request. - errno = EINVAL; + // Update the file descriptor flags. + error = __wasi_fd_fdstat_set_flags(fildes, fds.fs_flags); + if (error != 0) { + errno = error; return -1; + } + return 0; } + default: + // Invalid request. + errno = EINVAL; + return -1; + } } From f0c29d4211c474e242633ee73a16184c2759c063 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 12 Dec 2023 14:30:26 -0700 Subject: [PATCH 48/63] fix out-of-date comment in descriptor_table.c Signed-off-by: Joel Dice --- .../src/libc/sys/wasi_preview2/descriptor_table.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c index da4a0d004..c347d3bc9 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/descriptor_table.c @@ -12,13 +12,13 @@ * As of this writing, we still rely on the WASI Preview 1 adapter * (https://github.com/bytecodealliance/wasmtime/tree/main/crates/wasi-preview1-component-adapter) * to manage non-socket descriptors, so currently this table only tracks TCP and - * UDP sockets. We use the adapter's `adapter_open_badfd` and `fd_close` - * functions to reserve and later close descriptors to avoid confusion (e.g. if - * an application tries to use Preview 1 host functions directly for socket - * operations rather than go through `wasi-libc`). Eventually, we'll switch - * `wasi-libc` over to Preview 2 entirely, at which point we'll no longer need - * the adapter. At that point, all file descriptors will be managed exclusively - * in this table. + * UDP sockets. We use the adapter's `adapter_open_badfd` and + * `adapter_close_badfd` functions to reserve and later close descriptors to + * avoid confusion (e.g. if an application tries to use Preview 1 host functions + * directly for socket operations rather than go through `wasi-libc`). + * Eventually, we'll switch `wasi-libc` over to Preview 2 entirely, at which + * point we'll no longer need the adapter. At that point, all file descriptors + * will be managed exclusively in this table. */ #include From bc1b85a93dd446f728dbc322e4b4dee5fdca8ad1 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 15 Dec 2023 11:40:45 -0700 Subject: [PATCH 49/63] use AF_INET6 when creating a sockaddr_in6 Signed-off-by: Joel Dice --- libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c index 346b2675e..e2ca8e1b9 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/__utils.c @@ -189,7 +189,7 @@ void __wasi_sockets_utils__output_addr_write(const network_ip_socket_address_t i *output->v6.addrlen = sizeof(struct sockaddr_in6); *output->v6.addr = (struct sockaddr_in6) { - .sin6_family = AF_INET, + .sin6_family = AF_INET6, .sin6_port = htons(input_v6.port), .sin6_addr = { .s6_addr = { ip.f0 >> 8, ip.f0 & 0xFF, @@ -383,4 +383,4 @@ bool __wasi_sockets_utils__stream( } return true; -} \ No newline at end of file +} From 2a613962f03ed395ee94dcdf613ee370ae137b23 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 15 Dec 2023 11:40:54 -0700 Subject: [PATCH 50/63] implement `getaddrinfo` Signed-off-by: Joel Dice --- .../cloudlibc/src/libc/sys/socket/netdb.c | 139 +++++++++++++++++- 1 file changed, 135 insertions(+), 4 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c index a25c6d891..5e9ada012 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c @@ -1,19 +1,150 @@ #ifdef __wasilibc_use_preview2 #include +#include #include +#include "__utils.h" _Thread_local int h_errno = 0; +static int map_error(ip_name_lookup_error_code_t error) +{ + switch (error) { + case NETWORK_ERROR_CODE_OUT_OF_MEMORY: + return EAI_MEMORY; + case NETWORK_ERROR_CODE_NAME_UNRESOLVABLE: + return EAI_NONAME; + case NETWORK_ERROR_CODE_TEMPORARY_RESOLVER_FAILURE: + return EAI_AGAIN; + case NETWORK_ERROR_CODE_PERMANENT_RESOLVER_FAILURE: + return EAI_FAIL; + + default: + errno = __wasi_sockets_utils__map_error(error); + return EAI_SYSTEM; + } +} + int getaddrinfo(const char* restrict host, const char* restrict serv, const struct addrinfo* restrict hint, struct addrinfo** restrict res) { - // TODO wasi-sockets - abort(); + *res = NULL; + imports_string_t name = { .ptr = (uint8_t*) host, .len = strlen(host) }; + ip_name_lookup_own_resolve_address_stream_t stream; + ip_name_lookup_error_code_t error; + if (ip_name_lookup_resolve_addresses(__wasi_sockets_utils__borrow_network(), &name, &stream, &error)) { + ip_name_lookup_borrow_resolve_address_stream_t stream_borrow = ip_name_lookup_borrow_resolve_address_stream(stream); + while (true) { + ip_name_lookup_option_ip_address_t address; + if (ip_name_lookup_method_resolve_address_stream_resolve_next_address(stream_borrow, &address, &error)) { + if (address.is_some) { + int family; + struct sockaddr* addr; + socklen_t addrlen; + switch (address.val.tag) { + case NETWORK_IP_ADDRESS_IPV4: { + network_ipv4_address_t ip = address.val.val.ipv4; + + family = PF_INET; + addrlen = sizeof(struct sockaddr_in); + addr = malloc(addrlen); + if (addr == NULL) { + freeaddrinfo(*res); + return EAI_MEMORY; + } + + struct sockaddr_in sockaddr = { + .sin_family = AF_INET, + .sin_port = 0, + .sin_addr = { .s_addr = ip.f0 | (ip.f1 << 8) | (ip.f2 << 16) | (ip.f3 << 24) }, + }; + memcpy(addr, &sockaddr, addrlen); + break; + } + case NETWORK_IP_ADDRESS_IPV6: { + network_ipv6_address_t ip = address.val.val.ipv6; + + family = PF_INET6; + addrlen = sizeof(struct sockaddr_in6); + addr = malloc(addrlen); + if (addr == NULL) { + freeaddrinfo(*res); + return EAI_MEMORY; + } + + struct sockaddr_in6 sockaddr = { + .sin6_family = AF_INET6, + .sin6_port = 0, + .sin6_addr = { + .s6_addr = { + ip.f0 >> 8, + ip.f0 & 0xFF, + ip.f1 >> 8, + ip.f1 & 0xFF, + ip.f2 >> 8, + ip.f2 & 0xFF, + ip.f3 >> 8, + ip.f3 & 0xFF, + ip.f4 >> 8, + ip.f4 & 0xFF, + ip.f5 >> 8, + ip.f5 & 0xFF, + ip.f6 >> 8, + ip.f6 & 0xFF, + ip.f7 >> 8, + ip.f7 & 0xFF, + } }, + .sin6_flowinfo = 0, + .sin6_scope_id = 0, + }; + memcpy(addr, &sockaddr, addrlen); + break; + } + default: /* unreachable */ + abort(); + } + + struct addrinfo* result = malloc(sizeof(struct addrinfo)); + if (result == NULL) { + freeaddrinfo(*res); + return EAI_MEMORY; + } + + *result = (struct addrinfo) { + .ai_family = family, + .ai_flags = 0, + .ai_socktype = SOCK_STREAM, + .ai_protocol = 0, + .ai_addrlen = addrlen, + .ai_addr = addr, + .ai_canonname = NULL, + .ai_next = *res + }; + *res = result; + } else { + return 0; + } + } else if (error == NETWORK_ERROR_CODE_WOULD_BLOCK) { + ip_name_lookup_own_pollable_t pollable = ip_name_lookup_method_resolve_address_stream_subscribe(stream_borrow); + poll_borrow_pollable_t pollable_borrow = poll_borrow_pollable(pollable); + poll_method_pollable_block(pollable_borrow); + poll_pollable_drop_own(pollable); + } else { + freeaddrinfo(*res); + return map_error(error); + } + } + } else { + return map_error(error); + } } void freeaddrinfo(struct addrinfo* p) { - // TODO - abort(); + while (p) { + struct addrinfo* next = p->ai_next; + free(p->ai_addr); + free(p); + p = next; + } } int getnameinfo(const struct sockaddr* restrict sa, socklen_t salen, char* restrict host, socklen_t hostlen, char* restrict serv, socklen_t servlen, int flags) From b46fcaf2f7d41fdc9ccf209f8f67045b0fdedd86 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 15 Dec 2023 20:27:45 -0700 Subject: [PATCH 51/63] fix backwards logic in `ioctl` Signed-off-by: Joel Dice --- libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1ffddf0d3..c637f7eaf 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c @@ -23,7 +23,7 @@ int ioctl(int fildes, int request, ...) { case FIONBIO: { va_list ap; va_start(ap, request); - socket->blocking = *va_arg(ap, const int*) != 0; + socket->blocking = *va_arg(ap, const int*) == 0; va_end(ap); return 0; From ef83aa6147ad4ea285bccd14a7c8640edcb1bb39 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 15 Dec 2023 21:26:21 -0700 Subject: [PATCH 52/63] allow TCP_SOCKET_STATE_CONNECT_FAILED sockets to be polled Signed-off-by: Joel Dice --- .../cloudlibc/src/libc/poll/poll.c | 69 ++++++++++++------- 1 file changed, 45 insertions(+), 24 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c index c80532d06..dd030cbe8 100644 --- a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c +++ b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c @@ -140,6 +140,11 @@ typedef struct { static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) { + int event_count = 0; + for (size_t i = 0; i < nfds; ++i) { + fds[i].revents = 0; + } + size_t max_pollables = (2 * nfds) + 1; state_t states[max_pollables]; size_t state_index = 0; @@ -153,30 +158,41 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) switch (socket->state.tag) { case TCP_SOCKET_STATE_CONNECTING: { if ((pollfd->events & (POLLRDNORM | POLLWRNORM)) != 0) { - state_t state = { .pollable = socket->socket_pollable, + states[state_index++] = (state_t) { + .pollable = socket->socket_pollable, .pollfd = pollfd, .socket = socket, - .events = pollfd->events }; - states[state_index++] = state; + .events = pollfd->events + }; } break; } case TCP_SOCKET_STATE_CONNECTED: { if ((pollfd->events & POLLRDNORM) != 0) { - state_t state = { .pollable = socket->state.connected.input_pollable, + states[state_index++] = (state_t) { + .pollable = socket->state.connected.input_pollable, .pollfd = pollfd, .socket = socket, - .events = POLLRDNORM }; - states[state_index++] = state; + .events = POLLRDNORM + }; } if ((pollfd->events & POLLWRNORM) != 0) { - state_t state = { .pollable = socket->state.connected.output_pollable, + states[state_index++] = (state_t) { + .pollable = socket->state.connected.output_pollable, .pollfd = pollfd, .socket = socket, - .events = POLLWRNORM }; - states[state_index++] = state; + .events = POLLWRNORM + }; + } + break; + } + + case TCP_SOCKET_STATE_CONNECT_FAILED: { + if (pollfd->revents == 0) { + ++event_count; } + pollfd->revents |= pollfd->events; break; } @@ -197,6 +213,10 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) } } + if (event_count > 0 && timeout != 0) { + return event_count; + } + poll_borrow_pollable_t pollables[state_index + 1]; for (size_t i = 0; i < state_index; ++i) { pollables[i] = poll_borrow_pollable(states[i].pollable); @@ -213,11 +233,6 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) poll_list_borrow_pollable_t list = { .ptr = (poll_borrow_pollable_t*)&pollables, .len = pollable_count }; poll_poll(&list, &ready); - for (size_t i = 0; i < nfds; ++i) { - fds[i].revents = 0; - } - - int event_count = 0; for (size_t i = 0; i < ready.len; ++i) { size_t index = ready.ptr[i]; if (index < state_index) { @@ -231,12 +246,15 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) streams_own_pollable_t input_pollable = streams_method_input_stream_subscribe(input_stream_borrow); streams_borrow_output_stream_t output_stream_borrow = streams_borrow_output_stream(tuple.f1); streams_own_pollable_t output_pollable = streams_method_output_stream_subscribe(output_stream_borrow); - state->socket->state = (tcp_socket_state_t){ .tag = TCP_SOCKET_STATE_CONNECTED, .connected = { - .input_pollable = input_pollable, - .input = tuple.f0, - .output_pollable = output_pollable, - .output = tuple.f1, - } }; + state->socket->state = (tcp_socket_state_t) { + .tag = TCP_SOCKET_STATE_CONNECTED, + .connected = { + .input_pollable = input_pollable, + .input = tuple.f0, + .output_pollable = output_pollable, + .output = tuple.f1, + } + }; if (state->pollfd->revents == 0) { ++event_count; } @@ -244,9 +262,12 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) } else if (error == NETWORK_ERROR_CODE_WOULD_BLOCK) { // No events yet -- application will need to poll again } else { - state->socket->state = (tcp_socket_state_t){ .tag = TCP_SOCKET_STATE_CONNECT_FAILED, .connect_failed = { - .error_code = error, - } }; + state->socket->state = (tcp_socket_state_t) { + .tag = TCP_SOCKET_STATE_CONNECT_FAILED, + .connect_failed = { + .error_code = error, + } + }; if (state->pollfd->revents == 0) { ++event_count; } @@ -297,7 +318,7 @@ int poll(struct pollfd* fds, nfds_t nfds, int timeout) } else if (found_non_socket) { return poll_preview1(fds, nfds, timeout); } else if (timeout >= 0) { - return poll_preview2(fds, nfds, timeout); + return poll_preview2(fds, nfds, timeout); } else { errno = ENOTSUP; return -1; From 0b507849044f50bcbd98813888885aaa440f764f Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 19 Dec 2023 13:41:45 -0700 Subject: [PATCH 53/63] support TCP_SOCKET_STATE_LISTENING sockets in poll Signed-off-by: Joel Dice --- libc-bottom-half/cloudlibc/src/libc/poll/poll.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c index dd030cbe8..1c05e51fd 100644 --- a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c +++ b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c @@ -156,7 +156,8 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: { tcp_socket_t* socket = &(entry->tcp_socket); switch (socket->state.tag) { - case TCP_SOCKET_STATE_CONNECTING: { + case TCP_SOCKET_STATE_CONNECTING: + case TCP_SOCKET_STATE_LISTENING: { if ((pollfd->events & (POLLRDNORM | POLLWRNORM)) != 0) { states[state_index++] = (state_t) { .pollable = socket->socket_pollable, From 1db6e1a51d24d5a102d051c6617b6c4f088ff867 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 19 Dec 2023 13:42:47 -0700 Subject: [PATCH 54/63] return `getaddrinfo` results in order Also, stub out other netdb functions so they return errors instead of aborting. Signed-off-by: Joel Dice --- .../cloudlibc/src/libc/sys/socket/netdb.c | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c index 5e9ada012..6453585cc 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c @@ -26,7 +26,12 @@ static int map_error(ip_name_lookup_error_code_t error) int getaddrinfo(const char* restrict host, const char* restrict serv, const struct addrinfo* restrict hint, struct addrinfo** restrict res) { + if (host == NULL) { + host = "localhost"; + } + *res = NULL; + struct addrinfo* current = NULL; imports_string_t name = { .ptr = (uint8_t*) host, .len = strlen(host) }; ip_name_lookup_own_resolve_address_stream_t stream; ip_name_lookup_error_code_t error; @@ -116,9 +121,16 @@ int getaddrinfo(const char* restrict host, const char* restrict serv, const stru .ai_addrlen = addrlen, .ai_addr = addr, .ai_canonname = NULL, - .ai_next = *res + .ai_next = NULL, }; - *res = result; + + if (current) { + current->ai_next = result; + current = result; + } else { + current = result; + *res = result; + } } else { return 0; } @@ -156,36 +168,36 @@ int getnameinfo(const struct sockaddr* restrict sa, socklen_t salen, char* restr struct hostent* gethostbyname(const char* name) { // TODO - abort(); + return NULL; } struct hostent* gethostbyaddr(const void* addr, socklen_t len, int type) { // TODO - abort(); + return NULL; } const char* hstrerror(int err) { // TODO - abort(); + return "hstrerror: TODO"; } struct servent* getservbyname(const char* name, const char* proto) { // TODO - abort(); + return NULL; } struct servent* getservbyport(int port, const char* proto) { // TODO - abort(); + return NULL; } struct protoent* getprotobyname(const char* name) { // TODO - abort(); + return NULL; } #endif // __wasilibc_use_preview2 From 5b1ae5e8c4ed98a24612036389205512ba12252f Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 19 Dec 2023 17:06:09 -0700 Subject: [PATCH 55/63] honor ai_family hint in getaddrinfo Signed-off-by: Joel Dice --- libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c index 6453585cc..9ca07e17f 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c @@ -46,6 +46,10 @@ int getaddrinfo(const char* restrict host, const char* restrict serv, const stru socklen_t addrlen; switch (address.val.tag) { case NETWORK_IP_ADDRESS_IPV4: { + if (hint && hint->ai_family != AF_UNSPEC && hint->ai_family != AF_INET) { + continue; + } + network_ipv4_address_t ip = address.val.val.ipv4; family = PF_INET; @@ -65,6 +69,10 @@ int getaddrinfo(const char* restrict host, const char* restrict serv, const stru break; } case NETWORK_IP_ADDRESS_IPV6: { + if (hint && hint->ai_family != AF_UNSPEC && hint->ai_family != AF_INET6) { + continue; + } + network_ipv6_address_t ip = address.val.val.ipv6; family = PF_INET6; From 9c4d23a64eb0de0ed4271e646cf41df20ec6aa7a Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 19 Dec 2023 17:06:41 -0700 Subject: [PATCH 56/63] add UDP support to ioctl Signed-off-by: Joel Dice --- .../cloudlibc/src/libc/sys/ioctl/ioctl.c | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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 c637f7eaf..e3623f0dd 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c @@ -35,9 +35,27 @@ int ioctl(int fildes, int request, ...) { return -1; } } + + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: { + udp_socket_t* socket = &entry->udp_socket; + switch (request) { + case FIONBIO: { + va_list ap; + va_start(ap, request); + socket->blocking = *va_arg(ap, const int*) == 0; + va_end(ap); + + return 0; + } + + default: + // TODO wasi-sockets: anything else we should support? + errno = EINVAL; + return -1; + } + } default: - // TODO wasi-sockets: UDP errno = ENOPROTOOPT; return -1; } From 7c281696e1222cd674b9ab3d703bdca3d8ce38a9 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 19 Dec 2023 17:09:31 -0700 Subject: [PATCH 57/63] add fake SO_REUSEADDR support Signed-off-by: Joel Dice --- expected/wasm32-wasi-preview2/predefined-macros.txt | 1 + .../cloudlibc/src/libc/sys/socket/sockopt.c | 12 ++++++++++++ libc-bottom-half/headers/private/descriptor_table.h | 1 + .../headers/public/__header_sys_socket.h | 1 + 4 files changed, 15 insertions(+) diff --git a/expected/wasm32-wasi-preview2/predefined-macros.txt b/expected/wasm32-wasi-preview2/predefined-macros.txt index 4396d6345..4bef0e357 100644 --- a/expected/wasm32-wasi-preview2/predefined-macros.txt +++ b/expected/wasm32-wasi-preview2/predefined-macros.txt @@ -1660,6 +1660,7 @@ #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 diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c index df6187572..8a8cd19b4 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -93,6 +93,10 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, value = result; break; } + case SO_REUSEADDR: { + value = socket->fake_reuseaddr; + break; + } case SO_RCVTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself case SO_SNDTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself default: @@ -275,6 +279,14 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt return 0; } + case SO_REUSEADDR: { + // As of this writing, WASI has no support for changing SO_REUSEADDR + // -- it's enabled by default and cannot be disabled. To keep + // applications happy, we pretend to support enabling and disabling + // it. + socket->fake_reuseaddr = (intval != 0); + return 0; + } case SO_RCVTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself case SO_SNDTIMEO: // TODO wasi-sockets: emulate in wasi-libc itself default: diff --git a/libc-bottom-half/headers/private/descriptor_table.h b/libc-bottom-half/headers/private/descriptor_table.h index 63381b3fd..fdcaa64d6 100644 --- a/libc-bottom-half/headers/private/descriptor_table.h +++ b/libc-bottom-half/headers/private/descriptor_table.h @@ -44,6 +44,7 @@ typedef struct { poll_own_pollable_t socket_pollable; bool blocking; bool fake_nodelay; + bool fake_reuseaddr; network_ip_address_family_t family; tcp_socket_state_t state; } tcp_socket_t; diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index f39577468..635a14246 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -22,6 +22,7 @@ #define SOMAXCONN 128 +#define SO_REUSEADDR 2 #define SO_ERROR 4 #define SO_SNDBUF 7 #define SO_RCVBUF 8 From 69842d63f9868404c108e7e885720cde3efac160 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 20 Dec 2023 09:45:17 -0700 Subject: [PATCH 58/63] add UDP support to poll Signed-off-by: Joel Dice --- .../cloudlibc/src/libc/poll/poll.c | 65 ++++++++++++++++--- 1 file changed, 56 insertions(+), 9 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c index 1c05e51fd..3a9bd5c9a 100644 --- a/libc-bottom-half/cloudlibc/src/libc/poll/poll.c +++ b/libc-bottom-half/cloudlibc/src/libc/poll/poll.c @@ -134,7 +134,7 @@ static int poll_preview1(struct pollfd *fds, size_t nfds, int timeout) { typedef struct { poll_own_pollable_t pollable; struct pollfd* pollfd; - tcp_socket_t* socket; + descriptor_table_entry_t* entry; short events; } state_t; @@ -162,7 +162,7 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) states[state_index++] = (state_t) { .pollable = socket->socket_pollable, .pollfd = pollfd, - .socket = socket, + .entry = entry, .events = pollfd->events }; } @@ -174,7 +174,7 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) states[state_index++] = (state_t) { .pollable = socket->state.connected.input_pollable, .pollfd = pollfd, - .socket = socket, + .entry = entry, .events = POLLRDNORM }; } @@ -182,7 +182,7 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) states[state_index++] = (state_t) { .pollable = socket->state.connected.output_pollable, .pollfd = pollfd, - .socket = socket, + .entry = entry, .events = POLLWRNORM }; } @@ -204,8 +204,53 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) break; } + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: { + udp_socket_t* socket = &(entry->udp_socket); + switch (socket->state.tag) { + case UDP_SOCKET_STATE_UNBOUND: + case UDP_SOCKET_STATE_BOUND_NOSTREAMS: { + if (pollfd->revents == 0) { + ++event_count; + } + pollfd->revents |= pollfd->events; + break; + } + + case UDP_SOCKET_STATE_BOUND_STREAMING: + case UDP_SOCKET_STATE_CONNECTED: { + udp_socket_streams_t* streams; + if (socket->state.tag == UDP_SOCKET_STATE_BOUND_STREAMING) { + streams = &(socket->state.bound_streaming.streams); + } else { + streams = &(socket->state.connected.streams); + } + if ((pollfd->events & POLLRDNORM) != 0) { + states[state_index++] = (state_t) { + .pollable = streams->incoming_pollable, + .pollfd = pollfd, + .entry = entry, + .events = POLLRDNORM + }; + } + if ((pollfd->events & POLLWRNORM) != 0) { + states[state_index++] = (state_t) { + .pollable = streams->outgoing_pollable, + .pollfd = pollfd, + .entry = entry, + .events = POLLWRNORM + }; + } + break; + } + + default: + errno = ENOTSUP; + return -1; + } + break; + } + default: - // TODO wasi-sockets: UDP errno = ENOTSUP; return -1; } @@ -238,8 +283,10 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) size_t index = ready.ptr[i]; if (index < state_index) { state_t* state = &states[index]; - if (state->socket->state.tag == TCP_SOCKET_STATE_CONNECTING) { - tcp_borrow_tcp_socket_t borrow = tcp_borrow_tcp_socket(state->socket->socket); + if (state->entry->tag == DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET + && state->entry->tcp_socket.state.tag == TCP_SOCKET_STATE_CONNECTING) { + tcp_socket_t* socket = &(state->entry->tcp_socket); + tcp_borrow_tcp_socket_t borrow = tcp_borrow_tcp_socket(socket->socket); tcp_tuple2_own_input_stream_own_output_stream_t tuple; tcp_error_code_t error; if (tcp_method_tcp_socket_finish_connect(borrow, &tuple, &error)) { @@ -247,7 +294,7 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) streams_own_pollable_t input_pollable = streams_method_input_stream_subscribe(input_stream_borrow); streams_borrow_output_stream_t output_stream_borrow = streams_borrow_output_stream(tuple.f1); streams_own_pollable_t output_pollable = streams_method_output_stream_subscribe(output_stream_borrow); - state->socket->state = (tcp_socket_state_t) { + socket->state = (tcp_socket_state_t) { .tag = TCP_SOCKET_STATE_CONNECTED, .connected = { .input_pollable = input_pollable, @@ -263,7 +310,7 @@ static int poll_preview2(struct pollfd* fds, size_t nfds, int timeout) } else if (error == NETWORK_ERROR_CODE_WOULD_BLOCK) { // No events yet -- application will need to poll again } else { - state->socket->state = (tcp_socket_state_t) { + socket->state = (tcp_socket_state_t) { .tag = TCP_SOCKET_STATE_CONNECT_FAILED, .connect_failed = { .error_code = error, From c7eeb21bfdffa7b694de548c905d8589a388a5ef Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 20 Dec 2023 09:45:39 -0700 Subject: [PATCH 59/63] re-implement pselect using poll Signed-off-by: Joel Dice --- .../cloudlibc/src/libc/sys/select/pselect.c | 109 +++++++----------- 1 file changed, 40 insertions(+), 69 deletions(-) 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 fdc470ea8..9398edc6d 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c @@ -8,6 +8,7 @@ #include #include +#include int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, fd_set *restrict errorfds, const struct timespec *restrict timeout, @@ -33,93 +34,63 @@ int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, if (writefds == NULL) writefds = ∅ - // Determine the maximum number of events. - size_t maxevents = readfds->__nfds + writefds->__nfds + 1; - __wasi_subscription_t subscriptions[maxevents]; - size_t nsubscriptions = 0; - - // Convert the readfds set. + struct pollfd poll_fds[readfds->__nfds + writefds->__nfds]; + size_t poll_nfds = 0; + for (size_t i = 0; i < readfds->__nfds; ++i) { int fd = readfds->__fds[i]; if (fd < nfds) { - __wasi_subscription_t *subscription = &subscriptions[nsubscriptions++]; - *subscription = (__wasi_subscription_t){ - .userdata = fd, - .u.tag = __WASI_EVENTTYPE_FD_READ, - .u.u.fd_read.file_descriptor = fd, - }; + poll_fds[poll_nfds++] = (struct pollfd){ + .fd = fd, + .events = POLLRDNORM, + .revents = 0 + }; } } - - // Convert the writefds set. + for (size_t i = 0; i < writefds->__nfds; ++i) { int fd = writefds->__fds[i]; if (fd < nfds) { - __wasi_subscription_t *subscription = &subscriptions[nsubscriptions++]; - *subscription = (__wasi_subscription_t){ - .userdata = fd, - .u.tag = __WASI_EVENTTYPE_FD_WRITE, - .u.u.fd_write.file_descriptor = fd, - }; + poll_fds[poll_nfds++] = (struct pollfd){ + .fd = fd, + .events = POLLWRNORM, + .revents = 0 + }; } } - // Create extra event for the timeout. - if (timeout != NULL) { - __wasi_subscription_t *subscription = &subscriptions[nsubscriptions++]; - *subscription = (__wasi_subscription_t){ - .u.tag = __WASI_EVENTTYPE_CLOCK, - .u.u.clock.id = __WASI_CLOCKID_REALTIME, - }; - if (!timespec_to_timestamp_clamp(timeout, &subscription->u.u.clock.timeout)) { - errno = EINVAL; - return -1; - } - } + int poll_timeout; + if (timeout) { + uint64_t timeout_u64; + if (!timespec_to_timestamp_clamp(timeout, &timeout_u64) ) { + errno = EINVAL; + return -1; + } - // Execute poll(). - size_t nevents; - __wasi_event_t events[nsubscriptions]; - __wasi_errno_t error = - __wasi_poll_oneoff(subscriptions, events, nsubscriptions, &nevents); - if (error != 0) { - // WASI's poll requires at least one subscription, or else it returns - // `EINVAL`. Since a `pselect` with nothing to wait for is valid in POSIX, - // return `ENOTSUP` to indicate that we don't support that case. - // - // Wasm has no signal handling, so if none of the user-provided `pollfd` - // elements, nor the timeout, led us to producing even one subscription - // to wait for, there would be no way for the poll to wake up. WASI - // returns `EINVAL` in this case, but for users of `poll`, `ENOTSUP` is - // more likely to be understood. - if (nsubscriptions == 0) - errno = ENOTSUP; - else - errno = error; - return -1; - } + if (timeout_u64 > INT_MAX) { + timeout_u64 = INT_MAX; + } - // Test for EBADF. - for (size_t i = 0; i < nevents; ++i) { - const __wasi_event_t *event = &events[i]; - if ((event->type == __WASI_EVENTTYPE_FD_READ || - event->type == __WASI_EVENTTYPE_FD_WRITE) && - event->error == __WASI_ERRNO_BADF) { - errno = EBADF; + poll_timeout = (int) timeout_u64; + } else { + poll_timeout = -1; + }; + + if (poll(poll_fds, poll_nfds, poll_timeout) < 0) { return -1; - } } - // Clear and set entries in the result sets. FD_ZERO(readfds); FD_ZERO(writefds); - for (size_t i = 0; i < nevents; ++i) { - const __wasi_event_t *event = &events[i]; - if (event->type == __WASI_EVENTTYPE_FD_READ) { - readfds->__fds[readfds->__nfds++] = event->userdata; - } else if (event->type == __WASI_EVENTTYPE_FD_WRITE) { - writefds->__fds[writefds->__nfds++] = event->userdata; - } + for (size_t i = 0; i < poll_nfds; ++i) { + struct pollfd* pollfd = poll_fds + i; + if ((pollfd->revents & POLLRDNORM) != 0) { + readfds->__fds[readfds->__nfds++] = pollfd->fd; + } + if ((pollfd->revents & POLLWRNORM) != 0) { + writefds->__fds[writefds->__nfds++] = pollfd->fd; + } } + return readfds->__nfds + writefds->__nfds; } From 32f3a06ee8e6702a0c3ce221c54b26a2bf206830 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 20 Dec 2023 09:59:47 -0700 Subject: [PATCH 60/63] convert nanoseconds to milliseconds in pselect Signed-off-by: Joel Dice --- libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c | 3 +++ 1 file changed, 3 insertions(+) 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 9398edc6d..875db99ed 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c @@ -67,6 +67,9 @@ int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, return -1; } + // Convert nanoseconds to milliseconds: + timeout_u64 /= 1000000; + if (timeout_u64 > INT_MAX) { timeout_u64 = INT_MAX; } From f3adffed1182a39bcee649d27de01ba76446d844 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Wed, 20 Dec 2023 10:51:37 -0700 Subject: [PATCH 61/63] return zero from recv on STREAMS_STREAM_ERROR_CLOSED Signed-off-by: Joel Dice --- libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c index a80e3b52b..e3c87b268 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c @@ -50,9 +50,13 @@ ssize_t tcp_recvfrom(tcp_socket_t* socket, uint8_t* buffer, size_t length, int f streams_list_u8_t result; streams_stream_error_t error; if (!streams_method_input_stream_read(rx_borrow, length, &result, &error)) { - // TODO wasi-sockets: wasi-sockets has no way to recover TCP stream errors yet. - errno = EPIPE; - return -1; + if (error.tag == STREAMS_STREAM_ERROR_CLOSED) { + return 0; + } else { + // TODO wasi-sockets: wasi-sockets has no way to recover TCP stream errors yet. + errno = EPIPE; + return -1; + } } if (result.len) { From a3fb845d3ad03abd754db5f0f047bd365789e951 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 26 Jan 2024 07:53:32 -0700 Subject: [PATCH 62/63] update bindings to WASI 0.2.0 Signed-off-by: Joel Dice --- .../wasm32-wasi-preview2/defined-symbols.txt | 5 - .../undefined-symbols.txt | 4 - .../cloudlibc/src/libc/sys/socket/sockopt.c | 36 -- .../src/libc/sys/wasi_preview2/preview2.c | 394 ++++++------------ .../wasi_preview2/preview2_component_type.o | Bin 26798 -> 25728 bytes libc-bottom-half/headers/private/preview2.h | 249 +++++------ make-bindings.sh | 59 ++- 7 files changed, 297 insertions(+), 450 deletions(-) diff --git a/expected/wasm32-wasi-preview2/defined-symbols.txt b/expected/wasm32-wasi-preview2/defined-symbols.txt index de15caffa..ea203c27d 100644 --- a/expected/wasm32-wasi-preview2/defined-symbols.txt +++ b/expected/wasm32-wasi-preview2/defined-symbols.txt @@ -1279,7 +1279,6 @@ tcp_method_tcp_socket_finish_bind tcp_method_tcp_socket_finish_connect tcp_method_tcp_socket_finish_listen tcp_method_tcp_socket_hop_limit -tcp_method_tcp_socket_ipv6_only tcp_method_tcp_socket_is_listening tcp_method_tcp_socket_keep_alive_count tcp_method_tcp_socket_keep_alive_enabled @@ -1290,7 +1289,6 @@ tcp_method_tcp_socket_receive_buffer_size tcp_method_tcp_socket_remote_address tcp_method_tcp_socket_send_buffer_size tcp_method_tcp_socket_set_hop_limit -tcp_method_tcp_socket_set_ipv6_only tcp_method_tcp_socket_set_keep_alive_count tcp_method_tcp_socket_set_keep_alive_enabled tcp_method_tcp_socket_set_keep_alive_idle_time @@ -1386,12 +1384,10 @@ udp_method_outgoing_datagram_stream_send udp_method_outgoing_datagram_stream_subscribe udp_method_udp_socket_address_family udp_method_udp_socket_finish_bind -udp_method_udp_socket_ipv6_only udp_method_udp_socket_local_address udp_method_udp_socket_receive_buffer_size udp_method_udp_socket_remote_address udp_method_udp_socket_send_buffer_size -udp_method_udp_socket_set_ipv6_only udp_method_udp_socket_set_receive_buffer_size udp_method_udp_socket_set_send_buffer_size udp_method_udp_socket_set_unicast_hop_limit @@ -1404,7 +1400,6 @@ udp_outgoing_datagram_free udp_outgoing_datagram_stream_drop_borrow udp_outgoing_datagram_stream_drop_own udp_recvfrom -udp_result_bool_error_code_free udp_result_ip_socket_address_error_code_free udp_result_list_incoming_datagram_error_code_free udp_result_tuple2_own_incoming_datagram_stream_own_outgoing_datagram_stream_error_code_free diff --git a/expected/wasm32-wasi-preview2/undefined-symbols.txt b/expected/wasm32-wasi-preview2/undefined-symbols.txt index 1a37471ea..b98dc7113 100644 --- a/expected/wasm32-wasi-preview2/undefined-symbols.txt +++ b/expected/wasm32-wasi-preview2/undefined-symbols.txt @@ -152,7 +152,6 @@ __wasm_import_tcp_method_tcp_socket_finish_bind __wasm_import_tcp_method_tcp_socket_finish_connect __wasm_import_tcp_method_tcp_socket_finish_listen __wasm_import_tcp_method_tcp_socket_hop_limit -__wasm_import_tcp_method_tcp_socket_ipv6_only __wasm_import_tcp_method_tcp_socket_is_listening __wasm_import_tcp_method_tcp_socket_keep_alive_count __wasm_import_tcp_method_tcp_socket_keep_alive_enabled @@ -163,7 +162,6 @@ __wasm_import_tcp_method_tcp_socket_receive_buffer_size __wasm_import_tcp_method_tcp_socket_remote_address __wasm_import_tcp_method_tcp_socket_send_buffer_size __wasm_import_tcp_method_tcp_socket_set_hop_limit -__wasm_import_tcp_method_tcp_socket_set_ipv6_only __wasm_import_tcp_method_tcp_socket_set_keep_alive_count __wasm_import_tcp_method_tcp_socket_set_keep_alive_enabled __wasm_import_tcp_method_tcp_socket_set_keep_alive_idle_time @@ -191,12 +189,10 @@ __wasm_import_udp_method_outgoing_datagram_stream_send __wasm_import_udp_method_outgoing_datagram_stream_subscribe __wasm_import_udp_method_udp_socket_address_family __wasm_import_udp_method_udp_socket_finish_bind -__wasm_import_udp_method_udp_socket_ipv6_only __wasm_import_udp_method_udp_socket_local_address __wasm_import_udp_method_udp_socket_receive_buffer_size __wasm_import_udp_method_udp_socket_remote_address __wasm_import_udp_method_udp_socket_send_buffer_size -__wasm_import_udp_method_udp_socket_set_ipv6_only __wasm_import_udp_method_udp_socket_set_receive_buffer_size __wasm_import_udp_method_udp_socket_set_send_buffer_size __wasm_import_udp_method_udp_socket_set_unicast_hop_limit diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c index 8a8cd19b4..af9f427a6 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/sockopt.c @@ -149,16 +149,6 @@ int tcp_getsockopt(tcp_socket_t* socket, int level, int optname, value = result; break; } - case IPV6_V6ONLY: { - bool result; - if (!tcp_method_tcp_socket_ipv6_only(socket_borrow, &result, &error)) { - errno = __wasi_sockets_utils__map_error(error); - return -1; - } - - value = result; - break; - } default: errno = ENOPROTOOPT; return -1; @@ -345,14 +335,6 @@ int tcp_setsockopt(tcp_socket_t* socket, int level, int optname, const void* opt return 0; } - case IPV6_V6ONLY: { - if (!tcp_method_tcp_socket_set_ipv6_only(socket_borrow, intval != 0, &error)) { - errno = __wasi_sockets_utils__map_error(error); - return -1; - } - - return 0; - } default: errno = ENOPROTOOPT; return -1; @@ -518,16 +500,6 @@ int udp_getsockopt(udp_socket_t* socket, int level, int optname, value = result; break; } - case IPV6_V6ONLY: { - bool result; - if (!udp_method_udp_socket_ipv6_only(socket_borrow, &result, &error)) { - errno = __wasi_sockets_utils__map_error(error); - return -1; - } - - value = result; - break; - } default: errno = ENOPROTOOPT; return -1; @@ -632,14 +604,6 @@ int udp_setsockopt(udp_socket_t* socket, int level, int optname, const void* opt return 0; } - case IPV6_V6ONLY: { - if (!udp_method_udp_socket_set_ipv6_only(socket_borrow, intval != 0, &error)) { - errno = __wasi_sockets_utils__map_error(error); - return -1; - } - - return 0; - } default: errno = ENOPROTOOPT; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c index 634b9a5fe..cea5178d9 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c @@ -2,382 +2,370 @@ #include "preview2.h" -__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-12-05"), __import_name__("get-environment"))) +__attribute__((__import_module__("wasi:cli/environment@0.2.0"), __import_name__("get-environment"))) extern void __wasm_import_environment_get_environment(int32_t); -__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-12-05"), __import_name__("get-arguments"))) +__attribute__((__import_module__("wasi:cli/environment@0.2.0"), __import_name__("get-arguments"))) extern void __wasm_import_environment_get_arguments(int32_t); -__attribute__((__import_module__("wasi:cli/environment@0.2.0-rc-2023-12-05"), __import_name__("initial-cwd"))) +__attribute__((__import_module__("wasi:cli/environment@0.2.0"), __import_name__("initial-cwd"))) extern void __wasm_import_environment_initial_cwd(int32_t); -__attribute__((__import_module__("wasi:cli/exit@0.2.0-rc-2023-12-05"), __import_name__("exit"))) +__attribute__((__import_module__("wasi:cli/exit@0.2.0"), __import_name__("exit"))) extern void __wasm_import_exit_exit(int32_t); -__attribute__((__import_module__("wasi:io/error@0.2.0-rc-2023-11-10"), __import_name__("[method]error.to-debug-string"))) +__attribute__((__import_module__("wasi:io/error@0.2.0"), __import_name__("[method]error.to-debug-string"))) extern void __wasm_import_io_error_method_error_to_debug_string(int32_t, int32_t); -__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-11-10"), __import_name__("[method]pollable.ready"))) +__attribute__((__import_module__("wasi:io/poll@0.2.0"), __import_name__("[method]pollable.ready"))) extern int32_t __wasm_import_poll_method_pollable_ready(int32_t); -__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-11-10"), __import_name__("[method]pollable.block"))) +__attribute__((__import_module__("wasi:io/poll@0.2.0"), __import_name__("[method]pollable.block"))) extern void __wasm_import_poll_method_pollable_block(int32_t); -__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-11-10"), __import_name__("poll"))) +__attribute__((__import_module__("wasi:io/poll@0.2.0"), __import_name__("poll"))) extern void __wasm_import_poll_poll(int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]input-stream.read"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]input-stream.read"))) extern void __wasm_import_streams_method_input_stream_read(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]input-stream.blocking-read"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]input-stream.blocking-read"))) extern void __wasm_import_streams_method_input_stream_blocking_read(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]input-stream.skip"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]input-stream.skip"))) extern void __wasm_import_streams_method_input_stream_skip(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]input-stream.blocking-skip"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]input-stream.blocking-skip"))) extern void __wasm_import_streams_method_input_stream_blocking_skip(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]input-stream.subscribe"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]input-stream.subscribe"))) extern int32_t __wasm_import_streams_method_input_stream_subscribe(int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.check-write"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]output-stream.check-write"))) extern void __wasm_import_streams_method_output_stream_check_write(int32_t, int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.write"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]output-stream.write"))) extern void __wasm_import_streams_method_output_stream_write(int32_t, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.blocking-write-and-flush"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]output-stream.blocking-write-and-flush"))) extern void __wasm_import_streams_method_output_stream_blocking_write_and_flush(int32_t, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.flush"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]output-stream.flush"))) extern void __wasm_import_streams_method_output_stream_flush(int32_t, int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.blocking-flush"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]output-stream.blocking-flush"))) extern void __wasm_import_streams_method_output_stream_blocking_flush(int32_t, int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.subscribe"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]output-stream.subscribe"))) extern int32_t __wasm_import_streams_method_output_stream_subscribe(int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.write-zeroes"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]output-stream.write-zeroes"))) extern void __wasm_import_streams_method_output_stream_write_zeroes(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.blocking-write-zeroes-and-flush"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]output-stream.blocking-write-zeroes-and-flush"))) extern void __wasm_import_streams_method_output_stream_blocking_write_zeroes_and_flush(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.splice"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]output-stream.splice"))) extern void __wasm_import_streams_method_output_stream_splice(int32_t, int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[method]output-stream.blocking-splice"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[method]output-stream.blocking-splice"))) extern void __wasm_import_streams_method_output_stream_blocking_splice(int32_t, int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:cli/stdin@0.2.0-rc-2023-12-05"), __import_name__("get-stdin"))) +__attribute__((__import_module__("wasi:cli/stdin@0.2.0"), __import_name__("get-stdin"))) extern int32_t __wasm_import_stdin_get_stdin(void); -__attribute__((__import_module__("wasi:cli/stdout@0.2.0-rc-2023-12-05"), __import_name__("get-stdout"))) +__attribute__((__import_module__("wasi:cli/stdout@0.2.0"), __import_name__("get-stdout"))) extern int32_t __wasm_import_stdout_get_stdout(void); -__attribute__((__import_module__("wasi:cli/stderr@0.2.0-rc-2023-12-05"), __import_name__("get-stderr"))) +__attribute__((__import_module__("wasi:cli/stderr@0.2.0"), __import_name__("get-stderr"))) extern int32_t __wasm_import_stderr_get_stderr(void); -__attribute__((__import_module__("wasi:cli/terminal-stdin@0.2.0-rc-2023-12-05"), __import_name__("get-terminal-stdin"))) +__attribute__((__import_module__("wasi:cli/terminal-stdin@0.2.0"), __import_name__("get-terminal-stdin"))) extern void __wasm_import_terminal_stdin_get_terminal_stdin(int32_t); -__attribute__((__import_module__("wasi:cli/terminal-stdout@0.2.0-rc-2023-12-05"), __import_name__("get-terminal-stdout"))) +__attribute__((__import_module__("wasi:cli/terminal-stdout@0.2.0"), __import_name__("get-terminal-stdout"))) extern void __wasm_import_terminal_stdout_get_terminal_stdout(int32_t); -__attribute__((__import_module__("wasi:cli/terminal-stderr@0.2.0-rc-2023-12-05"), __import_name__("get-terminal-stderr"))) +__attribute__((__import_module__("wasi:cli/terminal-stderr@0.2.0"), __import_name__("get-terminal-stderr"))) extern void __wasm_import_terminal_stderr_get_terminal_stderr(int32_t); -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10"), __import_name__("now"))) +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0"), __import_name__("now"))) extern int64_t __wasm_import_monotonic_clock_now(void); -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10"), __import_name__("resolution"))) +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0"), __import_name__("resolution"))) extern int64_t __wasm_import_monotonic_clock_resolution(void); -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10"), __import_name__("subscribe-instant"))) +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0"), __import_name__("subscribe-instant"))) extern int32_t __wasm_import_monotonic_clock_subscribe_instant(int64_t); -__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10"), __import_name__("subscribe-duration"))) +__attribute__((__import_module__("wasi:clocks/monotonic-clock@0.2.0"), __import_name__("subscribe-duration"))) extern int32_t __wasm_import_monotonic_clock_subscribe_duration(int64_t); -__attribute__((__import_module__("wasi:clocks/wall-clock@0.2.0-rc-2023-11-10"), __import_name__("now"))) +__attribute__((__import_module__("wasi:clocks/wall-clock@0.2.0"), __import_name__("now"))) extern void __wasm_import_wall_clock_now(int32_t); -__attribute__((__import_module__("wasi:clocks/wall-clock@0.2.0-rc-2023-11-10"), __import_name__("resolution"))) +__attribute__((__import_module__("wasi:clocks/wall-clock@0.2.0"), __import_name__("resolution"))) extern void __wasm_import_wall_clock_resolution(int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.read-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.read-via-stream"))) extern void __wasm_import_filesystem_method_descriptor_read_via_stream(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.write-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.write-via-stream"))) extern void __wasm_import_filesystem_method_descriptor_write_via_stream(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.append-via-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.append-via-stream"))) extern void __wasm_import_filesystem_method_descriptor_append_via_stream(int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.advise"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.advise"))) extern void __wasm_import_filesystem_method_descriptor_advise(int32_t, int64_t, int64_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.sync-data"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.sync-data"))) extern void __wasm_import_filesystem_method_descriptor_sync_data(int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.get-flags"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.get-flags"))) extern void __wasm_import_filesystem_method_descriptor_get_flags(int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.get-type"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.get-type"))) extern void __wasm_import_filesystem_method_descriptor_get_type(int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.set-size"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.set-size"))) extern void __wasm_import_filesystem_method_descriptor_set_size(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.set-times"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.set-times"))) extern void __wasm_import_filesystem_method_descriptor_set_times(int32_t, int32_t, int64_t, int32_t, int32_t, int64_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.read"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.read"))) extern void __wasm_import_filesystem_method_descriptor_read(int32_t, int64_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.write"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.write"))) extern void __wasm_import_filesystem_method_descriptor_write(int32_t, int32_t, int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.read-directory"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.read-directory"))) extern void __wasm_import_filesystem_method_descriptor_read_directory(int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.sync"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.sync"))) extern void __wasm_import_filesystem_method_descriptor_sync(int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.create-directory-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.create-directory-at"))) extern void __wasm_import_filesystem_method_descriptor_create_directory_at(int32_t, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.stat"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.stat"))) extern void __wasm_import_filesystem_method_descriptor_stat(int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.stat-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.stat-at"))) extern void __wasm_import_filesystem_method_descriptor_stat_at(int32_t, int32_t, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.set-times-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.set-times-at"))) extern void __wasm_import_filesystem_method_descriptor_set_times_at(int32_t, int32_t, int32_t, int32_t, int32_t, int64_t, int32_t, int32_t, int64_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.link-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.link-at"))) extern void __wasm_import_filesystem_method_descriptor_link_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.open-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.open-at"))) extern void __wasm_import_filesystem_method_descriptor_open_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.readlink-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.readlink-at"))) extern void __wasm_import_filesystem_method_descriptor_readlink_at(int32_t, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.remove-directory-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.remove-directory-at"))) extern void __wasm_import_filesystem_method_descriptor_remove_directory_at(int32_t, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.rename-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.rename-at"))) extern void __wasm_import_filesystem_method_descriptor_rename_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.symlink-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.symlink-at"))) extern void __wasm_import_filesystem_method_descriptor_symlink_at(int32_t, int32_t, int32_t, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.unlink-file-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.unlink-file-at"))) extern void __wasm_import_filesystem_method_descriptor_unlink_file_at(int32_t, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.is-same-object"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.is-same-object"))) extern int32_t __wasm_import_filesystem_method_descriptor_is_same_object(int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.metadata-hash"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.metadata-hash"))) extern void __wasm_import_filesystem_method_descriptor_metadata_hash(int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]descriptor.metadata-hash-at"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]descriptor.metadata-hash-at"))) extern void __wasm_import_filesystem_method_descriptor_metadata_hash_at(int32_t, int32_t, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[method]directory-entry-stream.read-directory-entry"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[method]directory-entry-stream.read-directory-entry"))) extern void __wasm_import_filesystem_method_directory_entry_stream_read_directory_entry(int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("filesystem-error-code"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("filesystem-error-code"))) extern void __wasm_import_filesystem_filesystem_error_code(int32_t, int32_t); -__attribute__((__import_module__("wasi:filesystem/preopens@0.2.0-rc-2023-11-10"), __import_name__("get-directories"))) +__attribute__((__import_module__("wasi:filesystem/preopens@0.2.0"), __import_name__("get-directories"))) extern void __wasm_import_filesystem_preopens_get_directories(int32_t); -__attribute__((__import_module__("wasi:sockets/instance-network@0.2.0-rc-2023-11-10"), __import_name__("instance-network"))) +__attribute__((__import_module__("wasi:sockets/instance-network@0.2.0"), __import_name__("instance-network"))) extern int32_t __wasm_import_instance_network_instance_network(void); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.start-bind"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]udp-socket.start-bind"))) extern void __wasm_import_udp_method_udp_socket_start_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, int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.finish-bind"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]udp-socket.finish-bind"))) extern void __wasm_import_udp_method_udp_socket_finish_bind(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.stream"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]udp-socket.stream"))) extern void __wasm_import_udp_method_udp_socket_stream(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, int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.local-address"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]udp-socket.local-address"))) extern void __wasm_import_udp_method_udp_socket_local_address(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.remote-address"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]udp-socket.remote-address"))) extern void __wasm_import_udp_method_udp_socket_remote_address(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.address-family"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]udp-socket.address-family"))) extern int32_t __wasm_import_udp_method_udp_socket_address_family(int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.ipv6-only"))) -extern void __wasm_import_udp_method_udp_socket_ipv6_only(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.set-ipv6-only"))) -extern void __wasm_import_udp_method_udp_socket_set_ipv6_only(int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.unicast-hop-limit"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]udp-socket.unicast-hop-limit"))) extern void __wasm_import_udp_method_udp_socket_unicast_hop_limit(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.set-unicast-hop-limit"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]udp-socket.set-unicast-hop-limit"))) extern void __wasm_import_udp_method_udp_socket_set_unicast_hop_limit(int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.receive-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]udp-socket.receive-buffer-size"))) extern void __wasm_import_udp_method_udp_socket_receive_buffer_size(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.set-receive-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]udp-socket.set-receive-buffer-size"))) extern void __wasm_import_udp_method_udp_socket_set_receive_buffer_size(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.send-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]udp-socket.send-buffer-size"))) extern void __wasm_import_udp_method_udp_socket_send_buffer_size(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.set-send-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]udp-socket.set-send-buffer-size"))) extern void __wasm_import_udp_method_udp_socket_set_send_buffer_size(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]udp-socket.subscribe"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]udp-socket.subscribe"))) extern int32_t __wasm_import_udp_method_udp_socket_subscribe(int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]incoming-datagram-stream.receive"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]incoming-datagram-stream.receive"))) extern void __wasm_import_udp_method_incoming_datagram_stream_receive(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]incoming-datagram-stream.subscribe"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]incoming-datagram-stream.subscribe"))) extern int32_t __wasm_import_udp_method_incoming_datagram_stream_subscribe(int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]outgoing-datagram-stream.check-send"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]outgoing-datagram-stream.check-send"))) extern void __wasm_import_udp_method_outgoing_datagram_stream_check_send(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]outgoing-datagram-stream.send"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]outgoing-datagram-stream.send"))) extern void __wasm_import_udp_method_outgoing_datagram_stream_send(int32_t, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[method]outgoing-datagram-stream.subscribe"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[method]outgoing-datagram-stream.subscribe"))) extern int32_t __wasm_import_udp_method_outgoing_datagram_stream_subscribe(int32_t); -__attribute__((__import_module__("wasi:sockets/udp-create-socket@0.2.0-rc-2023-11-10"), __import_name__("create-udp-socket"))) +__attribute__((__import_module__("wasi:sockets/udp-create-socket@0.2.0"), __import_name__("create-udp-socket"))) extern void __wasm_import_udp_create_socket_create_udp_socket(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.start-bind"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.start-bind"))) extern void __wasm_import_tcp_method_tcp_socket_start_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, int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.finish-bind"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.finish-bind"))) extern void __wasm_import_tcp_method_tcp_socket_finish_bind(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.start-connect"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.start-connect"))) extern void __wasm_import_tcp_method_tcp_socket_start_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, int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.finish-connect"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.finish-connect"))) extern void __wasm_import_tcp_method_tcp_socket_finish_connect(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.start-listen"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.start-listen"))) extern void __wasm_import_tcp_method_tcp_socket_start_listen(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.finish-listen"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.finish-listen"))) extern void __wasm_import_tcp_method_tcp_socket_finish_listen(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.accept"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.accept"))) extern void __wasm_import_tcp_method_tcp_socket_accept(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.local-address"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.local-address"))) extern void __wasm_import_tcp_method_tcp_socket_local_address(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.remote-address"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.remote-address"))) extern void __wasm_import_tcp_method_tcp_socket_remote_address(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.is-listening"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.is-listening"))) extern int32_t __wasm_import_tcp_method_tcp_socket_is_listening(int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.address-family"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.address-family"))) extern int32_t __wasm_import_tcp_method_tcp_socket_address_family(int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.ipv6-only"))) -extern void __wasm_import_tcp_method_tcp_socket_ipv6_only(int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-ipv6-only"))) -extern void __wasm_import_tcp_method_tcp_socket_set_ipv6_only(int32_t, int32_t, int32_t); - -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-listen-backlog-size"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.set-listen-backlog-size"))) extern void __wasm_import_tcp_method_tcp_socket_set_listen_backlog_size(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.keep-alive-enabled"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.keep-alive-enabled"))) extern void __wasm_import_tcp_method_tcp_socket_keep_alive_enabled(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-keep-alive-enabled"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.set-keep-alive-enabled"))) extern void __wasm_import_tcp_method_tcp_socket_set_keep_alive_enabled(int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.keep-alive-idle-time"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.keep-alive-idle-time"))) extern void __wasm_import_tcp_method_tcp_socket_keep_alive_idle_time(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-keep-alive-idle-time"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.set-keep-alive-idle-time"))) extern void __wasm_import_tcp_method_tcp_socket_set_keep_alive_idle_time(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.keep-alive-interval"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.keep-alive-interval"))) extern void __wasm_import_tcp_method_tcp_socket_keep_alive_interval(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-keep-alive-interval"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.set-keep-alive-interval"))) extern void __wasm_import_tcp_method_tcp_socket_set_keep_alive_interval(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.keep-alive-count"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.keep-alive-count"))) extern void __wasm_import_tcp_method_tcp_socket_keep_alive_count(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-keep-alive-count"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.set-keep-alive-count"))) extern void __wasm_import_tcp_method_tcp_socket_set_keep_alive_count(int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.hop-limit"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.hop-limit"))) extern void __wasm_import_tcp_method_tcp_socket_hop_limit(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-hop-limit"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.set-hop-limit"))) extern void __wasm_import_tcp_method_tcp_socket_set_hop_limit(int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.receive-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.receive-buffer-size"))) extern void __wasm_import_tcp_method_tcp_socket_receive_buffer_size(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-receive-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.set-receive-buffer-size"))) extern void __wasm_import_tcp_method_tcp_socket_set_receive_buffer_size(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.send-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.send-buffer-size"))) extern void __wasm_import_tcp_method_tcp_socket_send_buffer_size(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.set-send-buffer-size"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.set-send-buffer-size"))) extern void __wasm_import_tcp_method_tcp_socket_set_send_buffer_size(int32_t, int64_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.subscribe"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.subscribe"))) extern int32_t __wasm_import_tcp_method_tcp_socket_subscribe(int32_t); -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[method]tcp-socket.shutdown"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[method]tcp-socket.shutdown"))) extern void __wasm_import_tcp_method_tcp_socket_shutdown(int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/tcp-create-socket@0.2.0-rc-2023-11-10"), __import_name__("create-tcp-socket"))) +__attribute__((__import_module__("wasi:sockets/tcp-create-socket@0.2.0"), __import_name__("create-tcp-socket"))) extern void __wasm_import_tcp_create_socket_create_tcp_socket(int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10"), __import_name__("resolve-addresses"))) +__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, int32_t, int32_t, int32_t); -__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10"), __import_name__("[method]resolve-address-stream.resolve-next-address"))) +__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, int32_t); -__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10"), __import_name__("[method]resolve-address-stream.subscribe"))) +__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:random/random@0.2.0-rc-2023-11-10"), __import_name__("get-random-bytes"))) +__attribute__((__import_module__("wasi:random/random@0.2.0"), __import_name__("get-random-bytes"))) extern void __wasm_import_random_get_random_bytes(int64_t, int32_t); -__attribute__((__import_module__("wasi:random/random@0.2.0-rc-2023-11-10"), __import_name__("get-random-u64"))) +__attribute__((__import_module__("wasi:random/random@0.2.0"), __import_name__("get-random-u64"))) extern int64_t __wasm_import_random_get_random_u64(void); -__attribute__((__import_module__("wasi:random/insecure@0.2.0-rc-2023-11-10"), __import_name__("get-insecure-random-bytes"))) +__attribute__((__import_module__("wasi:random/insecure@0.2.0"), __import_name__("get-insecure-random-bytes"))) extern void __wasm_import_random_insecure_get_insecure_random_bytes(int64_t, int32_t); -__attribute__((__import_module__("wasi:random/insecure@0.2.0-rc-2023-11-10"), __import_name__("get-insecure-random-u64"))) +__attribute__((__import_module__("wasi:random/insecure@0.2.0"), __import_name__("get-insecure-random-u64"))) extern int64_t __wasm_import_random_insecure_get_insecure_random_u64(void); -__attribute__((__import_module__("wasi:random/insecure-seed@0.2.0-rc-2023-11-10"), __import_name__("insecure-seed"))) +__attribute__((__import_module__("wasi:random/insecure-seed@0.2.0"), __import_name__("insecure-seed"))) extern void __wasm_import_random_insecure_seed_insecure_seed(int32_t); __attribute__((__weak__, __export_name__("cabi_realloc"))) @@ -425,7 +413,7 @@ void exit_result_void_void_free(exit_result_void_void_t *ptr) { } } -__attribute__((__import_module__("wasi:io/error@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]error"))) +__attribute__((__import_module__("wasi:io/error@0.2.0"), __import_name__("[resource-drop]error"))) extern void __wasm_import_io_error_error_drop(int32_t handle); void io_error_error_drop_own(io_error_own_error_t handle) { @@ -440,7 +428,7 @@ io_error_borrow_error_t io_error_borrow_error(io_error_own_error_t arg) { return (io_error_borrow_error_t) { arg.__handle }; } -__attribute__((__import_module__("wasi:io/poll@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]pollable"))) +__attribute__((__import_module__("wasi:io/poll@0.2.0"), __import_name__("[resource-drop]pollable"))) extern void __wasm_import_poll_pollable_drop(int32_t handle); void poll_pollable_drop_own(poll_own_pollable_t handle) { @@ -479,7 +467,7 @@ void streams_stream_error_free(streams_stream_error_t *ptr) { } } -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]input-stream"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[resource-drop]input-stream"))) extern void __wasm_import_streams_input_stream_drop(int32_t handle); void streams_input_stream_drop_own(streams_own_input_stream_t handle) { @@ -494,7 +482,7 @@ streams_borrow_input_stream_t streams_borrow_input_stream(streams_own_input_stre return (streams_borrow_input_stream_t) { arg.__handle }; } -__attribute__((__import_module__("wasi:io/streams@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]output-stream"))) +__attribute__((__import_module__("wasi:io/streams@0.2.0"), __import_name__("[resource-drop]output-stream"))) extern void __wasm_import_streams_output_stream_drop(int32_t handle); void streams_output_stream_drop_own(streams_own_output_stream_t handle) { @@ -539,7 +527,7 @@ void streams_result_void_stream_error_free(streams_result_void_stream_error_t *p } } -__attribute__((__import_module__("wasi:cli/terminal-input@0.2.0-rc-2023-12-05"), __import_name__("[resource-drop]terminal-input"))) +__attribute__((__import_module__("wasi:cli/terminal-input@0.2.0"), __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) { @@ -554,7 +542,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.2.0-rc-2023-12-05"), __import_name__("[resource-drop]terminal-output"))) +__attribute__((__import_module__("wasi:cli/terminal-output@0.2.0"), __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) { @@ -607,7 +595,7 @@ void filesystem_directory_entry_free(filesystem_directory_entry_t *ptr) { imports_string_free(&ptr->name); } -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]descriptor"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __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) { @@ -622,7 +610,7 @@ filesystem_borrow_descriptor_t filesystem_borrow_descriptor(filesystem_own_descr return (filesystem_borrow_descriptor_t) { arg.__handle }; } -__attribute__((__import_module__("wasi:filesystem/types@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]directory-entry-stream"))) +__attribute__((__import_module__("wasi:filesystem/types@0.2.0"), __import_name__("[resource-drop]directory-entry-stream"))) extern void __wasm_import_filesystem_directory_entry_stream_drop(int32_t handle); void filesystem_directory_entry_stream_drop_own(filesystem_own_directory_entry_stream_t handle) { @@ -755,7 +743,7 @@ void filesystem_preopens_list_tuple2_own_descriptor_string_free(filesystem_preop } } -__attribute__((__import_module__("wasi:sockets/network@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]network"))) +__attribute__((__import_module__("wasi:sockets/network@0.2.0"), __import_name__("[resource-drop]network"))) extern void __wasm_import_network_network_drop(int32_t handle); void network_network_drop_own(network_own_network_t handle) { @@ -820,7 +808,7 @@ void udp_outgoing_datagram_free(udp_outgoing_datagram_t *ptr) { udp_option_ip_socket_address_free(&ptr->remote_address); } -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]udp-socket"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[resource-drop]udp-socket"))) extern void __wasm_import_udp_udp_socket_drop(int32_t handle); void udp_udp_socket_drop_own(udp_own_udp_socket_t handle) { @@ -835,7 +823,7 @@ udp_borrow_udp_socket_t udp_borrow_udp_socket(udp_own_udp_socket_t arg) { return (udp_borrow_udp_socket_t) { arg.__handle }; } -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]incoming-datagram-stream"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[resource-drop]incoming-datagram-stream"))) extern void __wasm_import_udp_incoming_datagram_stream_drop(int32_t handle); void udp_incoming_datagram_stream_drop_own(udp_own_incoming_datagram_stream_t handle) { @@ -850,7 +838,7 @@ udp_borrow_incoming_datagram_stream_t udp_borrow_incoming_datagram_stream(udp_ow return (udp_borrow_incoming_datagram_stream_t) { arg.__handle }; } -__attribute__((__import_module__("wasi:sockets/udp@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]outgoing-datagram-stream"))) +__attribute__((__import_module__("wasi:sockets/udp@0.2.0"), __import_name__("[resource-drop]outgoing-datagram-stream"))) extern void __wasm_import_udp_outgoing_datagram_stream_drop(int32_t handle); void udp_outgoing_datagram_stream_drop_own(udp_own_outgoing_datagram_stream_t handle) { @@ -884,12 +872,6 @@ void udp_result_ip_socket_address_error_code_free(udp_result_ip_socket_address_e } } -void udp_result_bool_error_code_free(udp_result_bool_error_code_t *ptr) { - if (!ptr->is_err) { - } else { - } -} - void udp_result_u8_error_code_free(udp_result_u8_error_code_t *ptr) { if (!ptr->is_err) { } else { @@ -937,7 +919,7 @@ void tcp_ip_socket_address_free(tcp_ip_socket_address_t *ptr) { network_ip_socket_address_free(ptr); } -__attribute__((__import_module__("wasi:sockets/tcp@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]tcp-socket"))) +__attribute__((__import_module__("wasi:sockets/tcp@0.2.0"), __import_name__("[resource-drop]tcp-socket"))) extern void __wasm_import_tcp_tcp_socket_drop(int32_t handle); void tcp_tcp_socket_drop_own(tcp_own_tcp_socket_t handle) { @@ -1017,7 +999,7 @@ void ip_name_lookup_ip_address_free(ip_name_lookup_ip_address_t *ptr) { network_ip_address_free(ptr); } -__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10"), __import_name__("[resource-drop]resolve-address-stream"))) +__attribute__((__import_module__("wasi:sockets/ip-name-lookup@0.2.0"), __import_name__("[resource-drop]resolve-address-stream"))) extern void __wasm_import_ip_name_lookup_resolve_address_stream_drop(int32_t handle); void ip_name_lookup_resolve_address_stream_drop_own(ip_name_lookup_own_resolve_address_stream_t handle) { @@ -3096,58 +3078,6 @@ udp_ip_address_family_t udp_method_udp_socket_address_family(udp_borrow_udp_sock return ret; } -bool udp_method_udp_socket_ipv6_only(udp_borrow_udp_socket_t self, bool *ret, udp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_udp_method_udp_socket_ipv6_only((self).__handle, ptr); - udp_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 udp_method_udp_socket_set_ipv6_only(udp_borrow_udp_socket_t self, bool value, udp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_udp_method_udp_socket_set_ipv6_only((self).__handle, value, ptr); - udp_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 udp_method_udp_socket_unicast_hop_limit(udp_borrow_udp_socket_t self, uint8_t *ret, udp_error_code_t *err) { __attribute__((__aligned__(1))) uint8_t ret_area[2]; @@ -3839,58 +3769,6 @@ tcp_ip_address_family_t tcp_method_tcp_socket_address_family(tcp_borrow_tcp_sock return ret; } -bool tcp_method_tcp_socket_ipv6_only(tcp_borrow_tcp_socket_t self, bool *ret, tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_tcp_method_tcp_socket_ipv6_only((self).__handle, ptr); - tcp_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 tcp_method_tcp_socket_set_ipv6_only(tcp_borrow_tcp_socket_t self, bool value, tcp_error_code_t *err) { - __attribute__((__aligned__(1))) - uint8_t ret_area[2]; - int32_t ptr = (int32_t) &ret_area; - __wasm_import_tcp_method_tcp_socket_set_ipv6_only((self).__handle, value, ptr); - tcp_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 tcp_method_tcp_socket_set_listen_backlog_size(tcp_borrow_tcp_socket_t self, uint64_t value, tcp_error_code_t *err) { __attribute__((__aligned__(1))) uint8_t ret_area[2]; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2_component_type.o b/libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2_component_type.o index 37590f0c22ad6905a28fe69fd6203f8fd61fee10..edd5ee4616b829e7c83dcd0e223cef20bcf6b02c 100644 GIT binary patch delta 2749 zcmeHJTW=dx5I(cJzQj)BB)*V1ak7bXZ5$`5XoXtp#8E368YxPXhPF!6ZoKPcTYJ~+ zuG<7rTzKFKp;jZrMMyN2kU&7B$~?E>tvn#LeL*VX_FkaB05R)Z5>X*Q;sy1^KA!W< z%s1be@j09K;p*3Lt(E)a?)A1IVGWWT-rB#w3lK)nfpFNtyiLHoigrmgbS)0XkCKxIm|z=tj=AE5hDjbSFa{HhF@f<$UIP%I zx#moUnr|JH0KC9l-*b@k!XyaHp%{j4@W59xs``jxjF747RzkURdL|<+XA~P)j!r<^ zSc2i({6`SP311LD=Z+Qvwe+SXt5pI{uNRo3WZ|96_48j-_=gNe9l()-rE2g49xH5S zg=2-_PBwbJs-@Fg56nq)$i%zVpM@rgLoSh9((;lxkhRbqsj(XC#wIW1k(+=(MM$=AN9v(hY zssDK526W-0L>IP=zXX2#)2aZk@W*K`FOFad(8WYT^n3akf{vwpmLqM5>fcOnt&h6`|cCnhSez7poG z{s8pgM*oD+E3jzE^u=5gneNOD3B8~KJ{}I?)T|eM^Pb**SZ#t_Jw+R|qj9B-1KzB( zHf$(nK4Y1e*n%5a@5S<;FjWz7*r z^m-8nyHGsos2|;S>%*~=abb*y5N-~J@WJ3sV!C&sr`gd>gS^Kr=MBkHbqyxxi`v3I z9&h%yV=f*I_7UX*c&m~8tl!Qs7Wd=1GkzGr`=MXM2YuK$HboxWp>+P19}Rb0-e(~4nZOr7FMmU!_c zWqnzf3|Ukz(F4pBB|{NSTG6(l=T}x2H8q=6WL2`1%z8|GIjphS4fm)#U`WamYPnNc_N_|VicPK-#;h`5)SgVecu)R;{{vrt|5*S4 delta 3783 zcmeHKOKcle6n%GQY{&60j_n91P4M{d*yC?ol@?XDshWl$B|*?uidyQ%6FQ0Qac9O! zgFq%5qzVbuys}_Xfs`E!RAjM5>4F7FNM%7KDj;Fah6Q4U1aCY}9ZyoFD_D?~rF+ji z@7(Vjzxxe*{yp6BQjZ?C#^Tg_(3)C+D87>&jdIc=mrZALTqetLGD46? z2r-D38Z`h0d{3x|;VDdJ=)h?PnLeUnxL|=IFv!45k|@zY1B=<5tJo8e;WB9h>VO97 zVx>~LUg1@oc9$TgRHObbatLoQpFjY!29H}u#!xh(@Q%%mZ&GpaW1rof>p?m>Gg>Tw z46;%dYP1oVKBnPc&}r+5Q1zcM6z9c;0yG1GCwV23h)o}ESF;t6Q3KEe|C#7%lJus* z6X*rguZ|R&9z>>TwE=hRBP6;wt{BJd{dl}>@S0{ijRyEvhl?TImB9B;O~m?fq`N(U z911U0g<7e?k>u1H3T;QGZ}F`0*umVljjt2O_Wn!%GI|Fd0u&6S-LzY2?N+@y-@yEU zS{p`HwQcm^Et6S4G*rK`ZefOz=^1ahOsJbf6Nl5P8FeGm<|Q>tThQb3COL3NNVn@0M17-|3-qT53ZHedy4bHeXJ8V4<~-JK zZ-4D{TOo!YkB{{`@E_xIi9~1WmxKy0ugeNwP1Pk{tn)QlKmKG}w0EZNQ4sx*9n}$e z*_R-Ludo4~y~*Zby1m7&Q}!kpAP~B(E5Tt1;(GAxaEM^m_F}?#D>w-e{97>3L>UxN zY2AFS%w2CRE%6d33vcldVNgVM;FXZu5d{HyVq-+CFEj}^oKUwC@`OsR$&Fj8rCXfD z%Z-X6uOSZ4&nB$N-J@|7!QP)ugIxJxqd*Qur0C)S^PyL=|LllSbgT#cDuc_~7Sxs&XZzTNq{rF(}hq#|oApv6X;GyIh(weU%SAzXt-t0-)QZ-sREFhc$C)9#GmP6INZsYRH~K5YD)V#C}(q-*T_OEEx26=dB4g8 zfg|4MXLK2jGu@J?A2&j^E=tP2*-;-S23c%?OkD&$f=oYM!kO&Vqb1sTx{sFV(Gopc zqW_mA+P}VWbHN)v{BK=?Y+8JOVZ`6tzm@xl&;TW?%$Z(jSE F{s&3=w;KQe diff --git a/libc-bottom-half/headers/private/preview2.h b/libc-bottom-half/headers/private/preview2.h index f7581c715..d1dfaec6e 100644 --- a/libc-bottom-half/headers/private/preview2.h +++ b/libc-bottom-half/headers/private/preview2.h @@ -674,12 +674,14 @@ typedef uint8_t network_error_code_t; #define NETWORK_ERROR_CODE_ADDRESS_IN_USE 12 // The remote address is not reachable #define NETWORK_ERROR_CODE_REMOTE_UNREACHABLE 13 -// The connection was forcefully rejected +// The TCP connection was forcefully rejected #define NETWORK_ERROR_CODE_CONNECTION_REFUSED 14 -// The connection was reset. +// The TCP connection was reset. #define NETWORK_ERROR_CODE_CONNECTION_RESET 15 -// A connection was aborted. +// 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 @@ -725,14 +727,20 @@ typedef struct { #define NETWORK_IP_ADDRESS_IPV6 1 typedef struct { + // sin_port uint16_t port; + // sin_addr network_ipv4_address_t address; } network_ipv4_socket_address_t; typedef struct { + // 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; @@ -847,14 +855,6 @@ typedef struct { } val; } udp_result_ip_socket_address_error_code_t; -typedef struct { - bool is_err; - union { - bool ok; - udp_error_code_t err; - } val; -} udp_result_bool_error_code_t; - typedef struct { bool is_err; union { @@ -1081,7 +1081,7 @@ typedef struct { uint64_t f1; } random_insecure_seed_tuple2_u64_u64_t; -// Imported Functions from `wasi:cli/environment@0.2.0-rc-2023-12-05` +// 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 @@ -1097,11 +1097,11 @@ extern void environment_get_arguments(environment_list_string_t *ret); // directory, interpreting `.` as shorthand for this. extern bool environment_initial_cwd(imports_string_t *ret); -// Imported Functions from `wasi:cli/exit@0.2.0-rc-2023-12-05` +// Imported Functions from `wasi:cli/exit@0.2.0` // Exit the current instance and any linked instances. extern void exit_exit(exit_result_void_void_t *status); -// Imported Functions from `wasi:io/error@0.2.0-rc-2023-11-10` +// Imported Functions from `wasi:io/error@0.2.0` // Returns a string that is suitable to assist humans in debugging // this error. // @@ -1111,7 +1111,7 @@ extern void exit_exit(exit_result_void_void_t *status); // hazard. extern void io_error_method_error_to_debug_string(io_error_borrow_error_t self, imports_string_t *ret); -// Imported Functions from `wasi:io/poll@0.2.0-rc-2023-11-10` +// 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. @@ -1142,9 +1142,14 @@ extern void poll_method_pollable_block(poll_borrow_pollable_t self); // being reaedy for I/O. extern void poll_poll(poll_list_borrow_pollable_t *in, poll_list_u32_t *ret); -// Imported Functions from `wasi:io/streams@0.2.0-rc-2023-11-10` +// 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 @@ -1195,6 +1200,12 @@ extern streams_own_pollable_t streams_method_input_stream_subscribe(streams_borr 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. // @@ -1304,31 +1315,31 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // 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-rc-2023-12-05` + // 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-rc-2023-12-05` + // 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-rc-2023-12-05` + // 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-rc-2023-12-05` + // 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-rc-2023-12-05` + // 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-rc-2023-12-05` + // 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-rc-2023-11-10` + // 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 @@ -1345,7 +1356,7 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // 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-rc-2023-11-10` + // 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 @@ -1365,7 +1376,7 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // 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-rc-2023-11-10` + // 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. @@ -1595,34 +1606,36 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // 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-rc-2023-11-10` + // 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-rc-2023-11-10` + // 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-rc-2023-11-10` + // 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. // - // Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. - // - // # Typical `start` errors + // # Typical errors // - `invalid-argument`: The `local-address` has the wrong address family. (EAFNOSUPPORT, EFAULT on Windows) // - `invalid-state`: The socket is already bound. (EINVAL) - // - // # Typical `finish` errors // - `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 // - // - @@ -1658,7 +1671,6 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // // # Typical errors // - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - // - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) // - `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. @@ -1704,16 +1716,6 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // // 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); - // Whether IPv4 compatibility (dual-stack) mode is disabled or not. - // - // Equivalent to the IPV6_V6ONLY socket option. - // - // # Typical errors - // - `not-supported`: (get/set) `this` socket is an IPv4 socket. - // - `invalid-state`: (set) The socket is already bound. - // - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) - extern bool udp_method_udp_socket_ipv6_only(udp_borrow_udp_socket_t self, bool *ret, udp_error_code_t *err); - extern bool udp_method_udp_socket_set_ipv6_only(udp_borrow_udp_socket_t self, bool value, udp_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. @@ -1799,7 +1801,6 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // // # Typical errors // - `invalid-argument`: The `remote-address` has the wrong address family. (EAFNOSUPPORT) - // - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) // - `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) @@ -1824,10 +1825,11 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // 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-rc-2023-11-10` + // 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, @@ -1846,31 +1848,40 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // - 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-rc-2023-11-10` + // 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. // - // When a socket is not explicitly bound, the first invocation to a listen or connect operation will - // implicitly bind the socket. + // 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. // - // Unlike in POSIX, this function is async. This enables interactive WASI hosts to inject permission prompts. - // - // # Typical `start` errors + // # 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, but the socket has `ipv6-only` enabled. (EINVAL) + // - `invalid-argument`: `local-address` is an IPv4-mapped IPv6 address. (EINVAL) // - `invalid-state`: The socket is already bound. (EINVAL) - // - // # Typical `finish` errors // - `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 // - // - @@ -1881,39 +1892,40 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // Connect to a remote endpoint. // // On success: - // - the socket is transitioned into the Connection state + // - the socket is transitioned into the `connection` state. // - a pair of streams is returned that can be used to read & write to the connection // - // POSIX mentions: - // > If connect() fails, the state of the socket is unspecified. Conforming applications should - // > close the file descriptor and create a new socket before attempting to reconnect. - // - // WASI prescribes the following behavior: - // - If `connect` fails because an input/state validation error, the socket should remain usable. - // - If a connection was actually attempted but failed, the socket should become unusable for further network communication. - // Besides `drop`, any method after such a failure may return an error. + // 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 `start` errors + // # 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, but the socket has `ipv6-only` enabled. (EINVAL, EADDRNOTAVAIL on Illumos) - // - `invalid-argument`: `remote-address` is a non-IPv4-mapped IPv6 address, but the socket was bound to a specific IPv4-mapped IPv6 address. (or vice versa) + // - `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 Connection state. (EISCONN) - // - `invalid-state`: The socket is already in the Listener state. (EOPNOTSUPP, EINVAL on Windows) - // - // # Typical `finish` errors + // - `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. + // - `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 // - // - @@ -1923,22 +1935,24 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se 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 Listener state. + // Transitions the socket into the `listening` state. // - // Unlike POSIX: - // - this function is async. This enables interactive WASI hosts to inject permission prompts. - // - the socket must already be explicitly bound. + // Unlike POSIX, the socket must already be explicitly bound. // - // # Typical `start` errors + // # Typical errors // - `invalid-state`: The socket is not bound to any local address. (EDESTADDRREQ) - // - `invalid-state`: The socket is already in the Connection state. (EISCONN, EINVAL on BSD) - // - `invalid-state`: The socket is already in the Listener state. - // - // # Typical `finish` 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) - // - `not-in-progress`: A `listen` operation is not in progress. + // - `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 // - // - @@ -1948,9 +1962,8 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se 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 Connection state. The following properties are inherited from the listener socket: + // The returned socket is bound and in the `connected` state. The following properties are inherited from the listener socket: // - `address-family` - // - `ipv6-only` // - `keep-alive-enabled` // - `keep-alive-idle-time` // - `keep-alive-interval` @@ -1963,7 +1976,7 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // a pair of streams that can be used to read & write to the connection. // // # Typical errors - // - `invalid-state`: Socket is not in the Listener state. (EINVAL) + // - `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) @@ -2002,7 +2015,7 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // - // - 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 listening for new connections. + // 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); @@ -2010,16 +2023,6 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // // 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); - // Whether IPv4 compatibility (dual-stack) mode is disabled or not. - // - // Equivalent to the IPV6_V6ONLY socket option. - // - // # Typical errors - // - `invalid-state`: (set) The socket is already bound. - // - `not-supported`: (get/set) `this` socket is an IPv4 socket. - // - `not-supported`: (set) Host does not support dual-stack sockets. (Implementations are not required to.) - extern bool tcp_method_tcp_socket_ipv6_only(tcp_borrow_tcp_socket_t self, bool *ret, tcp_error_code_t *err); - extern bool tcp_method_tcp_socket_set_ipv6_only(tcp_borrow_tcp_socket_t self, bool value, tcp_error_code_t *err); // Hints the desired listen queue size. Implementations are free to ignore this. // // If the provided value is 0, an `invalid-argument` error is returned. @@ -2028,7 +2031,7 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // # 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 already in the Connection state. + // - `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. // @@ -2083,8 +2086,6 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // // # Typical errors // - `invalid-argument`: (set) The TTL value must be 1 or higher. - // - `invalid-state`: (set) The socket is already in the Connection state. - // - `invalid-state`: (set) The socket is already in the Listener state. 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. @@ -2097,30 +2098,45 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // // # Typical errors // - `invalid-argument`: (set) The provided value was 0. - // - `invalid-state`: (set) The socket is already in the Connection state. - // - `invalid-state`: (set) The socket is already in the Listener state. 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 will resolve once the socket is ready for I/O. + // 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 more data from the peer. All subsequent read - // operations on the `input-stream` associated with this socket will return an End Of Stream indication. - // Any data still in the receive queue at time of calling `shutdown` will be discarded. - // - send: the socket is not expecting to send any more data to the peer. All subsequent write - // operations on the `output-stream` associated with this socket will return an error. - // - both: same effect as receive & send combined. + // - `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 Connection state. (ENOTCONN) + // - `invalid-state`: The socket is not in the `connected` state. (ENOTCONN) // // # References // - @@ -2129,13 +2145,14 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // - 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-rc-2023-11-10` + // 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`/`listen`/`connect` + // 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. @@ -2151,7 +2168,7 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // - 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-rc-2023-11-10` + // 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. @@ -2193,7 +2210,7 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // 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-rc-2023-11-10` + // 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 @@ -2213,7 +2230,7 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // represented as a `u64`. extern uint64_t random_get_random_u64(void); - // Imported Functions from `wasi:random/insecure@0.2.0-rc-2023-11-10` + // 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 @@ -2229,7 +2246,7 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se // `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-rc-2023-11-10` + // 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 @@ -2407,8 +2424,6 @@ extern bool streams_method_output_stream_write(streams_borrow_output_stream_t se void udp_result_ip_socket_address_error_code_free(udp_result_ip_socket_address_error_code_t *ptr); - void udp_result_bool_error_code_free(udp_result_bool_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); diff --git a/make-bindings.sh b/make-bindings.sh index e40483deb..cd5985858 100644 --- a/make-bindings.sh +++ b/make-bindings.sh @@ -2,8 +2,7 @@ # This script will regenerate the WASI Preview 2 bindings. To use it, first # clone the wit directory from -# https://github.com/bytecodealliance/wasmtime/tree/release-16.0.0/crates/wasi/wit -# (or newer), install +# https://github.com/WebAssembly/wasi-cli/tree/main/wit, install # https://github.com/bytecodealliance/wit-bindgen/releases/tag/wit-bindgen-cli-0.16.0 # (or newer), and then run the script. # @@ -11,34 +10,34 @@ set -e -wit-bindgen c --world wasi:cli/imports@0.2.0-rc-2023-12-05 \ - --rename wasi:clocks/monotonic-clock@0.2.0-rc-2023-11-10=monotonic_clock \ - --rename wasi:clocks/wall-clock@0.2.0-rc-2023-11-10=wall_clock \ - --rename wasi:filesystem/preopens@0.2.0-rc-2023-11-10=filesystem_preopens \ - --rename wasi:filesystem/types@0.2.0-rc-2023-11-10=filesystem \ - --rename wasi:io/error@0.2.0-rc-2023-11-10=io_error \ - --rename wasi:io/poll@0.2.0-rc-2023-11-10=poll \ - --rename wasi:io/streams@0.2.0-rc-2023-11-10=streams \ - --rename wasi:random/insecure-seed@0.2.0-rc-2023-11-10=random_insecure_seed \ - --rename wasi:random/insecure@0.2.0-rc-2023-11-10=random_insecure \ - --rename wasi:random/random@0.2.0-rc-2023-11-10=random \ - --rename wasi:sockets/instance-network@0.2.0-rc-2023-11-10=instance_network \ - --rename wasi:sockets/ip-name-lookup@0.2.0-rc-2023-11-10=ip_name_lookup \ - --rename wasi:sockets/network@0.2.0-rc-2023-11-10=network \ - --rename wasi:sockets/tcp-create-socket@0.2.0-rc-2023-11-10=tcp_create_socket \ - --rename wasi:sockets/tcp@0.2.0-rc-2023-11-10=tcp \ - --rename wasi:sockets/udp-create-socket@0.2.0-rc-2023-11-10=udp_create_socket \ - --rename wasi:sockets/udp@0.2.0-rc-2023-11-10=udp \ - --rename wasi:cli/environment@0.2.0-rc-2023-12-05=environment \ - --rename wasi:cli/exit@0.2.0-rc-2023-12-05=exit \ - --rename wasi:cli/stdin@0.2.0-rc-2023-12-05=stdin \ - --rename wasi:cli/stdout@0.2.0-rc-2023-12-05=stdout \ - --rename wasi:cli/stderr@0.2.0-rc-2023-12-05=stderr \ - --rename wasi:cli/terminal-input@0.2.0-rc-2023-12-05=terminal_input \ - --rename wasi:cli/terminal-output@0.2.0-rc-2023-12-05=terminal_output \ - --rename wasi:cli/terminal-stdin@0.2.0-rc-2023-12-05=terminal_stdin \ - --rename wasi:cli/terminal-stdout@0.2.0-rc-2023-12-05=terminal_stdout \ - --rename wasi:cli/terminal-stderr@0.2.0-rc-2023-12-05=terminal_stderr \ +wit-bindgen c --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 mv imports.h libc-bottom-half/headers/private/preview2.h sed 's/#include "imports.h"/#include "preview2.h"/' < imports.c > libc-bottom-half/cloudlibc/src/libc/sys/wasi_preview2/preview2.c From 60e34285f8f6e8eca75eab02f69a30ee29914f38 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 26 Jan 2024 09:35:38 -0700 Subject: [PATCH 63/63] update tests to use Wasmtime 17 Signed-off-by: Joel Dice --- test/Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/Makefile b/test/Makefile index baf1be287..80ed1234c 100644 --- a/test/Makefile +++ b/test/Makefile @@ -27,12 +27,11 @@ LIBC_TEST = $(DOWNDIR)/libc-test LIBC_TEST_PATCH = $(CURDIR)/libc-test.patch LIBRT_URL ?= https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-16/libclang_rt.builtins-wasm32-wasi-16.0.tar.gz LIBRT = $(DOWNDIR)/lib/wasi/libclang_rt.builtins-wasm32.a -# TODO: switch to Wasmtime 16 once it's released -WASMTIME_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/dev/wasmtime-dev-x86_64-linux.tar.xz +WASMTIME_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/v17.0.0/wasmtime-v17.0.0-x86_64-linux.tar.xz WASMTIME = $(DOWNDIR)/$(shell basename $(WASMTIME_URL) .tar.xz)/wasmtime WASM_TOOLS_URL ?= https://github.com/bytecodealliance/wasm-tools/releases/download/wasm-tools-1.0.54/wasm-tools-1.0.54-x86_64-linux.tar.gz WASM_TOOLS = $(DOWNDIR)/$(shell basename $(WASM_TOOLS_URL) .tar.gz)/wasm-tools -ADAPTER_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/dev/wasi_snapshot_preview1.command.wasm +ADAPTER_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/v17.0.0/wasi_snapshot_preview1.command.wasm ADAPTER = $(DOWNDIR)/wasi_snapshot_preview1.command.wasm TO_DOWNLOAD = $(LIBC_TEST) $(LIBRT) $(WASMTIME)