Skip to content

Commit

Permalink
implement getsockname, getpeername, and getaddrinfo
Browse files Browse the repository at this point in the history
This also includes stubs for `gethostbyname`, `gethostbyaddr`, etc. which were
necessary to get CPython to build.  I believe it will be possible to implement
them all properly at some point, but don't have the bandwidth at the moment.

Signed-off-by: Joel Dice <[email protected]>
Co-authored-by: Dave Bakker <[email protected]>
Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej and badeend committed Mar 27, 2024
1 parent a2ed34e commit 5c6ffc3
Show file tree
Hide file tree
Showing 7 changed files with 537 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ LIBC_BOTTOM_HALF_OMIT_SOURCES := \
$(LIBC_BOTTOM_HALF_SOURCES)/accept-wasip2.c \
$(LIBC_BOTTOM_HALF_SOURCES)/shutdown.c \
$(LIBC_BOTTOM_HALF_SOURCES)/sockopt.c \
$(LIBC_BOTTOM_HALF_SOURCES)/poll-wasip2.c
$(LIBC_BOTTOM_HALF_SOURCES)/poll-wasip2.c \
$(LIBC_BOTTOM_HALF_SOURCES)/getsockpeername.c \
$(LIBC_BOTTOM_HALF_SOURCES)/netdb.c
LIBC_BOTTOM_HALF_ALL_SOURCES := $(filter-out $(LIBC_BOTTOM_HALF_OMIT_SOURCES),$(LIBC_BOTTOM_HALF_ALL_SOURCES))
# Omit p2-specific headers from include-all.c test.
INCLUDE_ALL_CLAUSES := -not -name wasip2.h -not -name descriptor_table.h
Expand Down Expand Up @@ -495,7 +497,6 @@ MUSL_OMIT_HEADERS += \
"sys/auxv.h" \
"pwd.h" "shadow.h" "grp.h" \
"mntent.h" \
"netdb.h" \
"resolv.h" \
"pty.h" \
"setjmp.h" \
Expand All @@ -519,6 +520,10 @@ MUSL_OMIT_HEADERS += \
"sys/sysmacros.h" \
"aio.h"

ifeq ($(WASI_SNAPSHOT), p1)
MUSL_OMIT_HEADERS += "netdb.h"
endif

ifeq ($(THREAD_MODEL), single)
# Remove headers not supported in single-threaded mode.
MUSL_OMIT_HEADERS += "pthread.h"
Expand Down
16 changes: 16 additions & 0 deletions expected/wasm32-wasip2/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,7 @@ fputws_unlocked
fread
fread_unlocked
free
freeaddrinfo
freelocale
freopen
freopen64
Expand Down Expand Up @@ -742,6 +743,7 @@ get_avphys_pages
get_nprocs
get_nprocs_conf
get_phys_pages
getaddrinfo
getc
getc_unlocked
getchar
Expand All @@ -753,14 +755,22 @@ 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
Expand All @@ -775,12 +785,14 @@ globfree
globfree64
gmtime
gmtime_r
h_errno
hcreate
hcreate_r
hdestroy
hdestroy_r
hsearch
hsearch_r
hstrerror
htonl
htons
hypot
Expand Down Expand Up @@ -1246,6 +1258,8 @@ tcp_bind
tcp_borrow_tcp_socket
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
Expand Down Expand Up @@ -1338,6 +1352,8 @@ udp_borrow_outgoing_datagram_stream
udp_borrow_udp_socket
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
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip2/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
#include <memory.h>
#include <monetary.h>
#include <mqueue.h>
#include <netdb.h>
#include <netinet/icmp6.h>
#include <netinet/igmp.h>
#include <netinet/in.h>
Expand Down
41 changes: 41 additions & 0 deletions expected/wasm32-wasip2/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
#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
Expand Down Expand Up @@ -192,6 +199,24 @@
#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
Expand Down Expand Up @@ -489,6 +514,7 @@
#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
Expand Down Expand Up @@ -1239,6 +1265,14 @@
#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
Expand All @@ -1257,6 +1291,9 @@
#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
Expand Down Expand Up @@ -1968,6 +2005,7 @@
#define TOREAD 00004
#define TOWRITE 00002
#define TRANSIENT 4
#define TRY_AGAIN 2
#define TSGID 02000
#define TSS_DTOR_ITERATIONS 4
#define TSUID 04000
Expand Down Expand Up @@ -2173,6 +2211,7 @@
#define _MATH_H
#define _MONETARY_H
#define _MQUEUE_H
#define _NETDB_H
#define _NETINET_ICMP6_H
#define _NETINET_IGMP_H
#define _NETINET_IN_H
Expand Down Expand Up @@ -3281,6 +3320,8 @@
#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)
Expand Down
Loading

0 comments on commit 5c6ffc3

Please sign in to comment.