From 1300509c4836ece78cff23f1134311e98ca98bf2 Mon Sep 17 00:00:00 2001 From: Nicola Krumschmidt Date: Wed, 16 Oct 2024 22:13:41 +0200 Subject: [PATCH] Add wasm32-wasip2 definitions necessary for socket2 support --- libc-test/semver/wasi-p2.txt | 16 ++++++++++++++++ src/wasi/p2.rs | 25 +++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/libc-test/semver/wasi-p2.txt b/libc-test/semver/wasi-p2.txt index bb79dfd0dc1e8..c2bb8ce791c58 100644 --- a/libc-test/semver/wasi-p2.txt +++ b/libc-test/semver/wasi-p2.txt @@ -11,30 +11,42 @@ sockaddr_storage addrinfo ip_mreq ipv6_mreq +linger SHUT_RD SHUT_WR SHUT_RDWR MSG_NOSIGNAL MSG_PEEK SO_REUSEADDR +SO_TYPE SO_ERROR SO_BROADCAST +SO_SNDBUF +SO_RCVBUF +SO_KEEPALIVE SO_LINGER +SO_ACCEPTCONN +SO_PROTOCOL +SO_DOMAIN SO_RCVTIMEO SO_SNDTIMEO SOCK_DGRAM SOCK_STREAM +SOCK_NONBLOCK SOL_SOCKET +AF_UNSPEC AF_INET AF_INET6 IPPROTO_IP IPPROTO_TCP +IPPROTO_UDP IPPROTO_IPV6 IP_TTL IP_MULTICAST_TTL IP_MULTICAST_LOOP IP_ADD_MEMBERSHIP IP_DROP_MEMBERSHIP +IPV6_UNICAST_HOPS IPV6_MULTICAST_LOOP IPV6_JOIN_GROUP IPV6_LEAVE_GROUP @@ -42,12 +54,16 @@ IPV6_V6ONLY IPV6_ADD_MEMBERSHIP IPV6_DROP_MEMBERSHIP TCP_NODELAY +TCP_KEEPIDLE +TCP_KEEPINTVL +TCP_KEEPCNT EAI_SYSTEM socket connect bind listen accept +accept4 getsockname getpeername sendto diff --git a/src/wasi/p2.rs b/src/wasi/p2.rs index 3e8eb95fcd1a5..d6381be451389 100644 --- a/src/wasi/p2.rs +++ b/src/wasi/p2.rs @@ -62,6 +62,11 @@ s! { pub ipv6mr_multiaddr: in6_addr, pub ipv6mr_interface: ::c_uint, } + + pub struct linger { + pub l_onoff: ::c_int, + pub l_linger: ::c_int, + } } pub const SHUT_RD: ::c_int = 1 << 0; @@ -72,22 +77,32 @@ pub const MSG_NOSIGNAL: ::c_int = 0x4000; pub const MSG_PEEK: ::c_int = 0x0002; pub const SO_REUSEADDR: ::c_int = 2; +pub const SO_TYPE: ::c_int = 3; pub const SO_ERROR: ::c_int = 4; pub const SO_BROADCAST: ::c_int = 6; +pub const SO_SNDBUF: ::c_int = 7; +pub const SO_RCVBUF: ::c_int = 8; +pub const SO_KEEPALIVE: ::c_int = 9; pub const SO_LINGER: ::c_int = 13; +pub const SO_ACCEPTCONN: ::c_int = 30; +pub const SO_PROTOCOL: ::c_int = 38; +pub const SO_DOMAIN: ::c_int = 39; pub const SO_RCVTIMEO: ::c_int = 66; pub const SO_SNDTIMEO: ::c_int = 67; pub const SOCK_DGRAM: ::c_int = 5; pub const SOCK_STREAM: ::c_int = 6; +pub const SOCK_NONBLOCK: ::c_int = 0x00004000; pub const SOL_SOCKET: ::c_int = 0x7fffffff; +pub const AF_UNSPEC: ::c_int = 0; pub const AF_INET: ::c_int = 1; pub const AF_INET6: ::c_int = 2; pub const IPPROTO_IP: ::c_int = 0; pub const IPPROTO_TCP: ::c_int = 6; +pub const IPPROTO_UDP: ::c_int = 17; pub const IPPROTO_IPV6: ::c_int = 41; pub const IP_TTL: ::c_int = 2; @@ -96,6 +111,7 @@ pub const IP_MULTICAST_LOOP: ::c_int = 34; pub const IP_ADD_MEMBERSHIP: ::c_int = 35; pub const IP_DROP_MEMBERSHIP: ::c_int = 36; +pub const IPV6_UNICAST_HOPS: ::c_int = 16; pub const IPV6_MULTICAST_LOOP: ::c_int = 19; pub const IPV6_JOIN_GROUP: ::c_int = 20; pub const IPV6_LEAVE_GROUP: ::c_int = 21; @@ -105,6 +121,9 @@ pub const IPV6_ADD_MEMBERSHIP: ::c_int = IPV6_JOIN_GROUP; pub const IPV6_DROP_MEMBERSHIP: ::c_int = IPV6_LEAVE_GROUP; pub const TCP_NODELAY: ::c_int = 1; +pub const TCP_KEEPIDLE: ::c_int = 4; +pub const TCP_KEEPINTVL: ::c_int = 5; +pub const TCP_KEEPCNT: ::c_int = 6; pub const EAI_SYSTEM: ::c_int = -11; @@ -114,6 +133,12 @@ extern "C" { pub fn bind(socket: ::c_int, addr: *const sockaddr, addrlen: socklen_t) -> ::c_int; pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int; pub fn accept(socket: ::c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> ::c_int; + pub fn accept4( + socket: ::c_int, + addr: *mut sockaddr, + addrlen: *mut socklen_t, + flags: ::c_int, + ) -> ::c_int; pub fn getsockname(socket: ::c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> ::c_int; pub fn getpeername(socket: ::c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> ::c_int;