summaryrefslogtreecommitdiffstats
path: root/libc-bottom-half/headers/private/wasi
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:08:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-26 16:08:03 +0000
commitf1db79e6e5c383cf76f3bf0dd42115d19591a72b (patch)
tree3f9509008e8a130c45b7e31b1520d66d720493ec /libc-bottom-half/headers/private/wasi
parentAdding upstream version 0.0~git20230821.ec4566b. (diff)
downloadwasi-libc-upstream.tar.xz
wasi-libc-upstream.zip
Adding upstream version 0.0~git20240411.9e8c542.upstream/0.0_git20240411.9e8c542upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-bottom-half/headers/private/wasi')
-rw-r--r--libc-bottom-half/headers/private/wasi/descriptor_table.h127
-rw-r--r--libc-bottom-half/headers/private/wasi/sockets_utils.h53
2 files changed, 180 insertions, 0 deletions
diff --git a/libc-bottom-half/headers/private/wasi/descriptor_table.h b/libc-bottom-half/headers/private/wasi/descriptor_table.h
new file mode 100644
index 0000000..8e9a90d
--- /dev/null
+++ b/libc-bottom-half/headers/private/wasi/descriptor_table.h
@@ -0,0 +1,127 @@
+#ifndef DESCRIPTOR_TABLE_H
+#define DESCRIPTOR_TABLE_H
+
+#include <wasi/wasip2.h>
+
+typedef struct {
+ int dummy;
+} tcp_socket_state_unbound_t;
+typedef struct {
+ int dummy;
+} tcp_socket_state_bound_t;
+typedef struct {
+ int dummy;
+} tcp_socket_state_connecting_t;
+typedef struct {
+ int dummy;
+} tcp_socket_state_listening_t;
+
+typedef struct {
+ 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 {
+ network_error_code_t error_code;
+} tcp_socket_state_connect_failed_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 {
+ 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;
+ bool fake_nodelay;
+ bool fake_reuseaddr;
+ network_ip_address_family_t family;
+ tcp_socket_state_t state;
+} tcp_socket_t;
+
+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 {
+ int dummy;
+} udp_socket_state_unbound_t;
+typedef struct {
+ int dummy;
+} udp_socket_state_bound_nostreams_t;
+
+typedef struct {
+ udp_socket_streams_t streams; // Streams have no remote_address
+} udp_socket_state_bound_streaming_t;
+
+typedef struct {
+ 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_NOSTREAMS,
+ UDP_SOCKET_STATE_BOUND_STREAMING,
+ UDP_SOCKET_STATE_CONNECTED,
+ } tag;
+ union {
+ udp_socket_state_unbound_t unbound;
+ 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;
+
+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;
+
+// This is a tagged union. When adding/removing/renaming cases, be sure to keep the tag and union definitions in sync.
+typedef struct {
+ 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);
+
+bool descriptor_table_get_ref(int fd, descriptor_table_entry_t **entry);
+
+bool descriptor_table_remove(int fd, descriptor_table_entry_t *entry);
+
+#endif
diff --git a/libc-bottom-half/headers/private/wasi/sockets_utils.h b/libc-bottom-half/headers/private/wasi/sockets_utils.h
new file mode 100644
index 0000000..93cf1f4
--- /dev/null
+++ b/libc-bottom-half/headers/private/wasi/sockets_utils.h
@@ -0,0 +1,53 @@
+#ifndef __wasi_sockets_utils_h
+#define __wasi_sockets_utils_h
+
+#include <netinet/in.h>
+
+#include <wasi/descriptor_table.h>
+
+typedef struct {
+ enum {
+ OUTPUT_SOCKADDR_NULL,
+ OUTPUT_SOCKADDR_V4,
+ OUTPUT_SOCKADDR_V6,
+ } tag;
+ union {
+ struct {
+ int dummy;
+ } 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(
+ 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);
+int __wasi_sockets_utils__udp_bind(udp_socket_t *socket,
+ network_ip_socket_address_t *address);
+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