Skip to content

Commit d0b57d3

Browse files
committed
Add wasm32-wasip2 definitions necessary for std::net support
1 parent 5c8a32d commit d0b57d3

File tree

3 files changed

+238
-0
lines changed

3 files changed

+238
-0
lines changed

libc-test/semver/wasi-p2.txt

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
sa_family_t
2+
in_port_t
3+
in_addr_t
4+
socklen_t
5+
sockaddr
6+
in_addr
7+
sockaddr_in
8+
in6_addr
9+
sockaddr_in6
10+
sockaddr_storage
11+
addrinfo
12+
ip_mreq
13+
ipv6_mreq
14+
SHUT_RD
15+
SHUT_WR
16+
SHUT_RDWR
17+
MSG_NOSIGNAL
18+
MSG_PEEK
19+
SO_REUSEADDR
20+
SO_ERROR
21+
SO_BROADCAST
22+
SO_RCVTIMEO
23+
SO_SNDTIMEO
24+
SOCK_DGRAM
25+
SOCK_STREAM
26+
SOL_SOCKET
27+
AF_INET
28+
AF_INET6
29+
IPPROTO_IP
30+
IPPROTO_TCP
31+
IPPROTO_IPV6
32+
IP_TTL
33+
IP_MULTICAST_TTL
34+
IP_MULTICAST_LOOP
35+
IP_ADD_MEMBERSHIP
36+
IP_DROP_MEMBERSHIP
37+
IPV6_MULTICAST_LOOP
38+
IPV6_JOIN_GROUP
39+
IPV6_LEAVE_GROUP
40+
IPV6_V6ONLY
41+
IPV6_ADD_MEMBERSHIP
42+
IPV6_DROP_MEMBERSHIP
43+
TCP_NODELAY
44+
EAI_SYSTEM
45+
socket
46+
connect
47+
bind
48+
listen
49+
accept
50+
getsockname
51+
getpeername
52+
sendto
53+
recvfrom
54+
getsockopt
55+
setsockopt
56+
getaddrinfo
57+
freeaddrinfo
58+
gai_strerror

src/wasi.rs renamed to src/wasi/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -882,3 +882,10 @@ extern "C" {
882882

883883
pub fn __errno_location() -> *mut ::c_int;
884884
}
885+
886+
cfg_if! {
887+
if #[cfg(target_env = "p2")] {
888+
mod p2;
889+
pub use self::p2::*;
890+
}
891+
}

src/wasi/p2.rs

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
pub type sa_family_t = ::c_ushort;
2+
pub type in_port_t = ::c_ushort;
3+
pub type in_addr_t = ::c_uint;
4+
5+
pub type socklen_t = ::c_uint;
6+
7+
s! {
8+
#[repr(align(16))]
9+
pub struct sockaddr {
10+
pub sa_family: sa_family_t,
11+
pub sa_data: [::c_char; 0],
12+
}
13+
14+
pub struct in_addr {
15+
pub s_addr: in_addr_t,
16+
}
17+
18+
#[repr(align(16))]
19+
pub struct sockaddr_in {
20+
pub sin_family: sa_family_t,
21+
pub sin_port: in_port_t,
22+
pub sin_addr: in_addr,
23+
}
24+
25+
#[repr(align(4))]
26+
pub struct in6_addr {
27+
pub s6_addr: [::c_uchar; 16],
28+
}
29+
30+
#[repr(align(16))]
31+
pub struct sockaddr_in6 {
32+
pub sin6_family: sa_family_t,
33+
pub sin6_port: in_port_t,
34+
pub sin6_flowinfo: ::c_uint,
35+
pub sin6_addr: in6_addr,
36+
pub sin6_scope_id: ::c_uint,
37+
}
38+
39+
#[repr(align(16))]
40+
pub struct sockaddr_storage {
41+
pub ss_family: sa_family_t,
42+
pub __ss_data: [::c_char; 32],
43+
}
44+
45+
pub struct addrinfo {
46+
pub ai_flags: ::c_int,
47+
pub ai_family: ::c_int,
48+
pub ai_socktype: ::c_int,
49+
pub ai_protocol: ::c_int,
50+
pub ai_addrlen: socklen_t,
51+
pub ai_addr: *mut sockaddr,
52+
pub ai_canonname: *mut ::c_char,
53+
pub ai_next: *mut addrinfo,
54+
}
55+
56+
pub struct ip_mreq {
57+
pub imr_multiaddr: in_addr,
58+
pub imr_interface: in_addr,
59+
}
60+
61+
pub struct ipv6_mreq {
62+
pub ipv6mr_multiaddr: in6_addr,
63+
pub ipv6mr_interface: ::c_uint,
64+
}
65+
}
66+
67+
pub const SHUT_RD: ::c_int = 1 << 0;
68+
pub const SHUT_WR: ::c_int = 1 << 1;
69+
pub const SHUT_RDWR: ::c_int = SHUT_RD | SHUT_WR;
70+
71+
pub const MSG_NOSIGNAL: ::c_int = 0x4000;
72+
pub const MSG_PEEK: ::c_int = 0x0002;
73+
74+
pub const SO_REUSEADDR: ::c_int = 2;
75+
pub const SO_ERROR: ::c_int = 4;
76+
pub const SO_BROADCAST: ::c_int = 6;
77+
pub const SO_RCVTIMEO: ::c_int = 20;
78+
pub const SO_SNDTIMEO: ::c_int = 21;
79+
80+
pub const SOCK_DGRAM: ::c_int = 5;
81+
pub const SOCK_STREAM: ::c_int = 6;
82+
83+
pub const SOL_SOCKET: ::c_int = 0x7fffffff;
84+
85+
pub const AF_INET: ::c_int = 1;
86+
pub const AF_INET6: ::c_int = 2;
87+
88+
pub const IPPROTO_IP: ::c_int = 0;
89+
pub const IPPROTO_TCP: ::c_int = 6;
90+
pub const IPPROTO_IPV6: ::c_int = 41;
91+
92+
pub const IP_TTL: ::c_int = 2;
93+
pub const IP_MULTICAST_TTL: ::c_int = 33;
94+
pub const IP_MULTICAST_LOOP: ::c_int = 34;
95+
pub const IP_ADD_MEMBERSHIP: ::c_int = 35;
96+
pub const IP_DROP_MEMBERSHIP: ::c_int = 36;
97+
98+
pub const IPV6_MULTICAST_LOOP: ::c_int = 19;
99+
pub const IPV6_JOIN_GROUP: ::c_int = 20;
100+
pub const IPV6_LEAVE_GROUP: ::c_int = 21;
101+
pub const IPV6_V6ONLY: ::c_int = 26;
102+
103+
pub const IPV6_ADD_MEMBERSHIP: ::c_int = IPV6_JOIN_GROUP;
104+
pub const IPV6_DROP_MEMBERSHIP: ::c_int = IPV6_LEAVE_GROUP;
105+
106+
pub const TCP_NODELAY: ::c_int = 1;
107+
108+
pub const EAI_SYSTEM: ::c_int = -11;
109+
110+
#[cfg_attr(
111+
feature = "rustc-dep-of-std",
112+
link(
113+
name = "c",
114+
kind = "static",
115+
modifiers = "-bundle",
116+
cfg(target_feature = "crt-static")
117+
)
118+
)]
119+
#[cfg_attr(
120+
feature = "rustc-dep-of-std",
121+
link(name = "c", cfg(not(target_feature = "crt-static")))
122+
)]
123+
extern "C" {
124+
pub fn socket(domain: ::c_int, type_: ::c_int, protocol: ::c_int) -> ::c_int;
125+
pub fn connect(fd: ::c_int, name: *const sockaddr, addrlen: socklen_t) -> ::c_int;
126+
pub fn bind(socket: ::c_int, addr: *const sockaddr, addrlen: socklen_t) -> ::c_int;
127+
pub fn listen(socket: ::c_int, backlog: ::c_int) -> ::c_int;
128+
pub fn accept(socket: ::c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> ::c_int;
129+
130+
pub fn getsockname(socket: ::c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> ::c_int;
131+
pub fn getpeername(socket: ::c_int, addr: *mut sockaddr, addrlen: *mut socklen_t) -> ::c_int;
132+
133+
pub fn sendto(
134+
socket: ::c_int,
135+
buffer: *const ::c_void,
136+
length: ::size_t,
137+
flags: ::c_int,
138+
addr: *const sockaddr,
139+
addrlen: socklen_t,
140+
) -> ::ssize_t;
141+
pub fn recvfrom(
142+
socket: ::c_int,
143+
buffer: *mut ::c_void,
144+
length: ::size_t,
145+
flags: ::c_int,
146+
addr: *mut sockaddr,
147+
addrlen: *mut socklen_t,
148+
) -> ::ssize_t;
149+
150+
pub fn getsockopt(
151+
sockfd: ::c_int,
152+
level: ::c_int,
153+
optname: ::c_int,
154+
optval: *mut ::c_void,
155+
optlen: *mut socklen_t,
156+
) -> ::c_int;
157+
pub fn setsockopt(
158+
sockfd: ::c_int,
159+
level: ::c_int,
160+
optname: ::c_int,
161+
optval: *const ::c_void,
162+
optlen: socklen_t,
163+
) -> ::c_int;
164+
165+
pub fn getaddrinfo(
166+
host: *const ::c_char,
167+
serv: *const ::c_char,
168+
hint: *const addrinfo,
169+
res: *mut *mut addrinfo,
170+
) -> ::c_int;
171+
pub fn freeaddrinfo(p: *mut addrinfo);
172+
pub fn gai_strerror(ecode: ::c_int) -> *const ::c_char;
173+
}

0 commit comments

Comments
 (0)