diff --git a/Makefile b/Makefile index 18471e2b..6b512a6e 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -245,6 +247,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), p2) +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)/, \ @@ -383,6 +392,10 @@ ASMFLAGS += -matomics CFLAGS += -I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) endif +ifeq ($(WASI_SNAPSHOT), p2) +EXTRA_CFLAGS += -D__wasilibc_use_wasip2 +endif + # Expose the public headers to the implementation. We use `-isystem` for # purpose for two reasons: # @@ -495,7 +508,6 @@ MUSL_OMIT_HEADERS += \ "sys/auxv.h" \ "pwd.h" "shadow.h" "grp.h" \ "mntent.h" \ - "netdb.h" \ "resolv.h" \ "pty.h" \ "setjmp.h" \ @@ -519,6 +531,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" diff --git a/expected/wasm32-wasip2/defined-symbols.txt b/expected/wasm32-wasip2/defined-symbols.txt deleted file mode 100644 index 3b11fb41..00000000 --- a/expected/wasm32-wasip2/defined-symbols.txt +++ /dev/null @@ -1,1484 +0,0 @@ -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_wasip2 -__component_type_object_force_link_wasip2_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 -chmod -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 -duplocale -ecvt -encrypt -environ -environment_get_arguments -environment_get_environment -environment_initial_cwd -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 -fchmod -fchmodat -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_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 -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 -freelocale -freopen -freopen64 -frexp -frexpf -frexpl -fscanf -fseek -fseeko -fseeko64 -fsetpos -fsetpos64 -fstat -fstatat -fstatvfs -fsync -ftell -ftello -ftello64 -ftime -ftruncate -futimens -futimesat -fwide -fwprintf -fwrite -fwrite_unlocked -fwscanf -gcvt -get_avphys_pages -get_nprocs -get_nprocs_conf -get_phys_pages -getc -getc_unlocked -getchar -getchar_unlocked -getcwd -getdate -getdate_err -getdelim -getdomainname -getentropy -getenv -gethostid -getline -getopt -getopt_long -getopt_long_only -getpagesize -getpid -getrusage -getsockopt -getsubopt -gettimeofday -getw -getwc -getwc_unlocked -getwchar -getwchar_unlocked -glob -glob64 -globfree -globfree64 -gmtime -gmtime_r -hcreate -hcreate_r -hdestroy -hdestroy_r -hsearch -hsearch_r -htonl -htons -hypot -hypotf -hypotl -iconv -iconv_close -iconv_open -ilogb -ilogbf -ilogbl -imaxabs -imaxdiv -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_method_pollable_block -poll_method_pollable_ready -poll_poll -poll_pollable_drop_borrow -poll_pollable_drop_own -poll_wasip2 -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 -read -readdir -readlink -readlinkat -readv -realloc -reallocarray -realpath -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 -statvfs -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_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_create_socket_create_tcp_socket -tcp_create_socket_result_own_tcp_socket_error_code_free -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_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_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_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_setsockopt -tcp_shutdown -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_create_socket_create_udp_socket -udp_create_socket_result_own_udp_socket_error_code_free -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_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_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_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_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_setsockopt -udp_shutdown -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 -wasip2_list_string_free -wasip2_list_tuple2_string_string_free -wasip2_list_u32_free -wasip2_list_u8_free -wasip2_option_string_free -wasip2_string_dup -wasip2_string_free -wasip2_string_set -wasip2_tuple2_string_string_free -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-wasip2/include-all.c b/expected/wasm32-wasip2/include-all.c index 045fd1ef..b2fd79b1 100644 --- a/expected/wasm32-wasip2/include-all.c +++ b/expected/wasm32-wasip2/include-all.c @@ -102,6 +102,7 @@ #include #include #include +#include #include #include #include diff --git a/expected/wasm32-wasip2/predefined-macros.txt b/expected/wasm32-wasip2/predefined-macros.txt index 20add244..b8c3730b 100644 --- a/expected/wasm32-wasip2/predefined-macros.txt +++ b/expected/wasm32-wasip2/predefined-macros.txt @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -3194,7 +3233,7 @@ #define __wasilibc___typedef_suseconds_t_h #define __wasilibc___typedef_time_t_h #define __wasilibc___typedef_uid_t_h -#define __wasilibc_use_wasip2 +#define __wasilibc_use_wasip2 1 #define __wasm 1 #define __wasm32 1 #define __wasm32__ 1 @@ -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) diff --git a/libc-bottom-half/sources/getsockpeername.c b/libc-bottom-half/sources/getsockpeername.c new file mode 100644 index 00000000..463c233f --- /dev/null +++ b/libc-bottom-half/sources/getsockpeername.c @@ -0,0 +1,229 @@ +#include +#include + +#include +#include + +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; + } + + 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); + if (!tcp_method_tcp_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 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; + } + + 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); + if (!tcp_method_tcp_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 udp_getsockname(udp_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; + } + + 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) +{ + 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) +{ + 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_getsockname(&entry->tcp_socket, addr, addrlen); + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + return udp_getsockname(&entry->udp_socket, addr, addrlen); + default: + errno = EOPNOTSUPP; + return -1; + } +} + +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; + } + + switch (entry->tag) { + case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: + return tcp_getpeername(&entry->tcp_socket, addr, addrlen); + case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: + return udp_getpeername(&entry->udp_socket, addr, addrlen); + default: + errno = EOPNOTSUPP; + return -1; + } +} diff --git a/libc-bottom-half/sources/netdb.c b/libc-bottom-half/sources/netdb.c new file mode 100644 index 00000000..c30a3967 --- /dev/null +++ b/libc-bottom-half/sources/netdb.c @@ -0,0 +1,238 @@ +#include +#include +#include + +#include + +_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; + } +} + +static int add_addr(ip_name_lookup_option_ip_address_t address, + const struct addrinfo *restrict hint, + struct addrinfo **restrict current, + struct addrinfo **restrict res) +{ + int family; + struct sockaddr *addr; + socklen_t addrlen; + switch (address.val.tag) { + case NETWORK_IP_ADDRESS_IPV4: { + if (hint && hint->ai_family != AF_UNSPEC && + hint->ai_family != AF_INET) { + return 0; + } + + 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: { + if (hint && hint->ai_family != AF_UNSPEC && + hint->ai_family != AF_INET6) { + return 0; + } + + 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 = NULL, + }; + + if (*current) { + (*current)->ai_next = result; + *current = result; + } else { + *current = result; + *res = result; + } + + return 0; +} + +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; + wasip2_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 error = add_addr(address, hint, + ¤t, res); + if (error) { + return error; + } + } 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) +{ + 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) +{ + // TODO wasi-sockets + abort(); +} + +struct hostent *gethostbyname(const char *name) +{ + // TODO wasi-sockets + return NULL; +} + +struct hostent *gethostbyaddr(const void *addr, socklen_t len, int type) +{ + // TODO wasi-sockets + return NULL; +} + +const char *hstrerror(int err) +{ + // TODO wasi-sockets + return "hstrerror: TODO"; +} + +struct servent *getservbyname(const char *name, const char *proto) +{ + // TODO wasi-sockets + return NULL; +} + +struct servent *getservbyport(int port, const char *proto) +{ + // TODO wasi-sockets + return NULL; +} + +struct protoent *getprotobyname(const char *name) +{ + // TODO wasi-sockets + return NULL; +} diff --git a/libc-top-half/musl/include/netdb.h b/libc-top-half/musl/include/netdb.h index d096c781..f9797bc8 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()) +#elif (defined __wasilibc_use_wasip2) +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/libc-top-half/musl/include/sys/socket.h b/libc-top-half/musl/include/sys/socket.h index 4d6a139d..29189e39 100644 --- a/libc-top-half/musl/include/sys/socket.h +++ b/libc-top-half/musl/include/sys/socket.h @@ -417,7 +417,7 @@ int listen (int, int); 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 */ +#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict); int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); #endif @@ -434,7 +434,7 @@ 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 */ +#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) int setsockopt (int, int, int, const void *, socklen_t); #endif