Skip to content

fix(libkernel): send to INADDR_ANY through 127.0.0.1 on macOS - #17878

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
Alexius0815:contrib/macos-inaddr-any-sendto
Dec 4, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
Alexius0815:contrib/macos-inaddr-any-sendto

Conversation

@Alexius0815

@Alexius0815 Alexius0815 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What

On macOS, a datagram sent to 0.0.0.0 or ::ffff:0.0.0.0 fails with EHOSTUNREACH (65). This makes guest_socket_port_zero fail. The change applies AnyPS5's existing loopback mapping to these destinations in the Darwin sendto path, matching the mapping used on Windows by #15782.

FreeBSD 11.4's in_pcbconnect_setup selects the first local IPv4 address for an unspecified destination. Loopback is AnyPS5's approximation for this case. The connect path already passes the guest test on macOS and is unchanged.

Tested

Apple M4 (Mac16,13), macOS 27.2, Release x86-64 under Rosetta 2. CTest ran serially with the final v4 diffs on Mac integration stack b05b1c4c93a2 (main 02452319 with Mac build fixes). The review commit is based on main 7259cce111.

  • Baseline: guest_socket_port_zero fails with errno 65.
  • UDP-only arm: guest_socket_port_zero passes. The separate guest_socket_options failure remains.
  • IPv4-only variant: the test still fails for ::ffff:0.0.0.0.
  • Combined UDP and TCP arm: 95 of 97 socket and network tests pass, one is skipped (guest_net_raw_protocol), and guest_sce_net hits the known epoll closed-stream failure.

Checklist

  • Based on current main; no other open PR implements the same change
  • One topic per PR
  • No comments added to source code
  • No new stubs or third-party code
  • No investigation files added to the repository
  • Generic behavior, independent of title
  • Depends on: none
  • Fixes: none
  • Unblocks: none known
  • GPUs tested: n/a
  • AI-assisted: yes

Summary by CodeRabbit

  • Bug Fixes
    • UDP sends to unspecified Internet destinations now apply loopback handling on macOS, matching the existing behavior on Windows. This makes destination handling more consistent across the two platforms when sending UDP traffic to an unspecified address.

On macOS a datagram sent to 0.0.0.0 or ::ffff:0.0.0.0 failed with
EHOSTUNREACH, so guest_socket_port_zero failed at "sendto INADDR_ANY
must reach 127.0.0.1". FreeBSD 11.4 picks a local address for an
unspecified IPv4 destination.

sendto on macOS now maps the unspecified destination to 127.0.0.1
through LoopbackForUnspecifiedInet, the helper the Windows path
already uses. connect is unchanged because macOS already reaches the
local host there.
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 8605 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12682 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12688 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12700 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 12965 core/libs/prx/libkernel/Socket/src/Udp.cpp
PR 16826 core/libs/prx/libkernel/Socket/src/Udp.cpp

@JJenkx

JJenkx commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 0a7cf3a1d3, merged onto main 39a172839a (9ef651464a, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • exec_arguments, guest_addresses, guest_aio, guest_aio_bad_descriptors, guest_amm_pool, guest_app_icon, guest_app_info, guest_append_streams, guest_append_writes, guest_available_cpumask, guest_closed_standard_descriptors_windows, guest_closed_standard_streams_load_windows, guest_cond_recursive_mutex, guest_cond_timedwait, guest_cond_unowned_mutex, guest_coredump_attach, guest_coredump_user_data, guest_cpu_time_clocks, guest_credentials, guest_current_cpu, guest_deferred_module_sweep, guest_deferred_module_sweep_failed, guest_direct_memory_for_app, guest_directory_buffer, guest_directory_close, guest_directory_entries, guest_directory_removed_entries, guest_directory_rewind, guest_dup, guest_dynamic_loader, guest_dynamic_loader_variant_names, guest_elf_phdr_match, guest_equeue_events, guest_exception_fault, guest_exception_handler, guest_execvp, guest_file_timestamps, guest_file_vector, guest_file_vector_memory, guest_filesystem, guest_freebsd_clocks, guest_fstat_fault, guest_fstatfs, guest_getitimer, guest_getlogin, guest_getrlimit, guest_getrusage, guest_host_standard_buffering_windows, guest_host_standard_error_windows, guest_host_streams, guest_itimer, guest_itimer_pending_default, guest_itimer_short_expiry, guest_jit_shared_memory, guest_kernel_errors, guest_kernel_fcntl, guest_kernel_fcntl_sync, guest_kernel_is_stack, guest_kernel_rename, guest_kernel_resident_fmem_export, guest_kernel_resident_fmem_export_patched, guest_kernel_stack_protect, guest_kernel_sync, guest_kill, guest_kqueue, guest_kqueue_cleared_race, guest_low_address_memory, guest_memory, guest_mlock, guest_mmap_executable, guest_mmap_fixed_anonymous, guest_module_info, guest_mprotect_unmapped, guest_msync, guest_mutex_contention, guest_mutex_raise_exception, guest_named_shm_windows_mapping, guest_nanosleep, guest_nanosleep_long_request, guest_nanosleep_timer_self_test, guest_once, guest_operation_mode, guest_output_pointer_fault, guest_page_table_stats, guest_parent_process, guest_path_name_length, guest_pipe_fault, guest_poll, guest_positioned_close, guest_positioned_race, guest_posix_cond_broadcast, guest_posix_exit, guest_posix_mutex_trylock, guest_posix_named_sem, guest_posix_sem_init, guest_posix_sem_post, guest_posix_specific, guest_process_abi_type, guest_process_arguments, guest_process_time, guest_process_time_counter, guest_process_time_counter_scaled, guest_process_time_rdtsc, guest_process_time_rdtsc_scaled, guest_process_time_scaled, guest_process_time_tsc, guest_process_time_tsc_scaled, guest_protection_report, guest_pthread_atfork, guest_pthread_attr, guest_pthread_attr_errors, guest_pthread_attr_stack, guest_pthread_barrier, guest_pthread_cancel, guest_pthread_cancel_recovery, guest_pthread_cancel_recovery_coarse, guest_pthread_cond, guest_pthread_cond_setname, guest_pthread_condattr, guest_pthread_destroyed_objects, guest_pthread_destructor_lifetime, guest_pthread_detach_attr, guest_pthread_final_release_race, guest_pthread_frame_chain, guest_pthread_getname, guest_pthread_handle_after_exit, guest_pthread_join_detach, guest_pthread_join_self, guest_pthread_key, guest_pthread_mutex_errors, guest_pthread_mutex_prioceiling, guest_pthread_mutex_spin, guest_pthread_mutexattr, guest_pthread_posix_calls, guest_pthread_released_handle, guest_pthread_rename, guest_pthread_rwlock, guest_pthread_schedparam, guest_pthread_second_join, guest_pthread_sem, guest_pthread_setname, guest_pthread_spin, guest_pthread_stack, guest_pthread_start, guest_pthread_timed_locks, guest_pthread_yield, guest_raise_exception, guest_raise_exiting_thread, guest_raise_in_host_code, guest_raise_in_system_call, guest_raise_leaves_host_code, guest_raise_nested_sleep, guest_raise_short_sleep, guest_raise_short_sleep_without_wake, guest_recvmsg_memory, guest_rename_dot, guest_rtprio_thread, guest_rwlock_retire, guest_sandbox_certificate_failure, guest_sandbox_certificate_trust, guest_sandbox_certificates, guest_sandbox_random_word, guest_sanitizer_replace_tables, guest_sched_params, guest_sched_priority, guest_select, guest_select_wait, guest_sem_canceled_wake, guest_sem_canceled_wake_coarse, guest_sem_getvalue_uninit, guest_semaphore, guest_semaphore_handoff, guest_semaphore_trace, guest_sendfile, guest_setrlimit, guest_shm_open, guest_sigaltstack, guest_signal_handler_mask, guest_signal_interrupt, guest_signal_sets, guest_signals, guest_sigtimedwait, guest_sleep_wake, guest_sleep_wake_coarse, guest_socket_address_length, guest_socket_connect_listening, guest_socket_descriptor_flags, guest_socket_descriptors, guest_socket_error, guest_socket_events, guest_socket_on_non_socket, guest_socket_options, guest_socket_options_multicast, guest_socket_pair, guest_socket_port_zero, guest_socket_read_write, guest_socket_send_before_connect, guest_socket_stream_options, guest_socket_timeouts, guest_software_version, guest_stream_close, guest_sync_on_address, guest_sysarch, guest_system_command, guest_system_configuration, guest_system_flexible_memory, guest_tcp, guest_terminal, guest_termios_speed, guest_thermal_sensors, guest_thread_cpu_clock, guest_thread_sanitizer, guest_thread_self, guest_timed_wait_cpu, guest_tls_get_addr, guest_truncate, guest_truncate_extend, guest_truncate_race, guest_udp, guest_umtx_op, guest_underscore_entries, guest_underscore_jumps, guest_unwind_module_info, guest_user_context, guest_user_context_exit, guest_usleep, guest_wait_trace, guest_waitpid, guest_windows_directory_link_types, host_cpu, host_performance_process_invalid, host_performance_session, kernel_error, nid_patcher_symbol_versions, param_json_parser, param_sfo_parser pass in 3 of 3 runs, none skipped.

AI-assisted: yes.

@kurexw kurexw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on macOS 27.2, Apple Silicon (M4), full build (x86-64 under Rosetta 2). This PR was merged alone onto main 04f7633 with git merge --no-ff. I ran the 56 socket and net tests (guest_socket_*, guest_poll, guest_refused_connect, guest_sce_net, guest_net_*, guest_kernel_socket*) three times on main and three times with this PR.

  • guest_socket_port_zero fails in all three runs on main ("sendto INADDR_ANY must reach 127.0.0.1 (errno 65)") and passes in all three runs with this PR.
  • No other test changes. In one run, guest_socket_read_write failed with ECONNRESET. That test is flaky on main too (1 failure in 10 runs on main, 0 in 10 with this PR), so this PR is not the cause.
  • This PR and #17879 conflict in core/libs/prx/libkernel/Socket/src/Udp.cpp, so whichever merges second needs a rebase.

@Romannachwievor

Copy link
Copy Markdown
Contributor

Tested on an Apple M1 (macOS 26.5, Apple clang 21.0.0), x86_64 Release under Rosetta 2. The tree was main 245210b07e with #17425 and #11049, which the macOS build needs. I applied this PR's diff (head 0a7cf3a1d3) on top.

guest_socket_port_zero: fails 3 of 3 runs without this PR (sendto INADDR_ANY must reach 127.0.0.1 (errno 65)) and passes 3 of 3 with it.

AI-assisted: yes (Claude Code)

@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head 0a7cf3a1d3, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#17478, #21223, #24030, #24201, #14202, #18889, #19531, #21641, #21773, #22468, #22471, #23239, #23255, #23484, #23869, #23992, #24311, #18425, #21195, #21255, #22989, #23507, #23886, #14582, #19666, #19899, #20138, #21656, #21746). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
none: no test of its own in this PR - -

Whole batch: the full ctest -j 12 (6522 tests) on the RTX 3080 has 4 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. The 2125 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

The change applies the existing unspecified-address loopback mapping to Darwin sendto and the inspected implementation covers IPv4 and IPv4-mapped IPv6.

What I ran

Reviewed head 0a7cf3a1d353f2c325c9e5d267dae841fde38b6f. No commands or tests were run; the author-reported test results were not independently verified.

Results

Check Result Note
Diff and changed code passed One changed source file read
Tests not run No tests run during review

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports macOS test results in the PR description; they were not independently confirmed. files.json was unavailable in the provided review bundle, so I could not compare the read files against its reviewed list. No test, build, or platform behavior was run. Read: description.md, commits.md, manifest.json, diff.patch, and core/libs/prx/libkernel/Socket/src/Udp.cpp lines 400–460 and 1990–2029. Excluded: no paths were available from files.json.

To get this to a good state

Nothing is required.

@NobleBrains NobleBrains left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed on macOS 15.

Setup: Apple M4, macOS 15.7.9, Apple clang 17.0.0 (clang-1700.6.3.2), x86_64 Release under Rosetta, BUILD_TESTING=ON. These are the OS and compiler generation of the macos-15 runner.
Tree: main 93d64f2d1e + the open macOS build fixes #27201, #27739, #27843, #17425, #27827, #27767 (main does not build on macOS without them, see #28168), + #22091, #28369, #28075, #28076, #28284, then #17878, #20161, #25134, #26806, #22932, #28373, #27828, #27950, #27582, #24311 merged one after another. All merged cleanly.

guest_socket_port_zero failures
same tree before this PR 3/3
with this PR at 0a7cf3a1d3 0/5

Full ctest -j 6 after all of them: 7047/7066 pass. Compared with the run before the second group of merges, no test fails that passed before.

AI-assisted: yes (Claude Code)

@ligmaSec ligmaSec left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing guest_socket_port_zero regression passed with this head integrated on Linux. The changed branch reuses the established IPv4 and IPv4-mapped loopback conversion for Darwin sendto. The conversion itself still needs a macOS run.

AI-assisted: yes.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: macOS UDP destination conversion

Layer / File(s) Summary
Enable destination conversion on macOS
core/libs/prx/libkernel/Socket/src/Udp.cpp
The platform guard includes macOS. sendto_nid_postfix applies LoopbackForUnspecifiedInet to destinations before sending on macOS.

Suggested reviewers: ragbie, brajankw

Change: Bug fix

Merge Risk: Minimal · up to 56d21

On macOS, UDP sends to 0.0.0.0 are now routed through loopback, matching the existing Windows behavior and fixing the reported EHOSTUNREACH failure. The change is small and local, and I found no merge-blocking risk.

Architecture risk: Low · up to 56d21

The UDP send path now converts unspecified destinations to loopback on macOS as well as Windows when the helper's condition matches.

Changed areas: core

Review details

Systems and components

  • observed — 1 changed file mapped to core.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f429fbce-bfc6-4a99-85e1-31e21197864a
Commits

Reviewing files that changed from the base of the PR and between 87a06f5 and 56d2119.

Files selected for processing: 1

  • core/libs/prx/libkernel/Socket/src/Udp.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this; the points below are optional.

What I ran

Reviewed head 56d2119552631118a9c0ab2bd15d8a4bad1c54d7. I read the prepared description, commits, manifest, diff, and the changed file’s relevant helper, address conversion, sendto, and connect sections with repo_read.py. No tests or builds were run.

Results

Check Result Note
Changed code review passed Mapping is limited to unspecified IPv4 destinations and IPv4-mapped IPv6 destinations.
Tests and build not run The author reports macOS test results; I did not independently verify them.

Negative control

Not run; no test was run.

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

The reported macOS test results and behavior on physical consoles were not independently verified. The reviewed file was core/libs/prx/libkernel/Socket/src/Udp.cpp; files.json lists no excluded files.

To get this to a good state

Nothing is required.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Dec 4, 2026
@oneandonlydean
oneandonlydean merged commit df9c237 into boykopovar:main Dec 4, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants