Skip to content

fix(libkernel): create pipes with pipe and fcntl on macOS, where pipe2 needs macOS 27 - #19903

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
XIIYAZ:fix/libkernel-pipe2-macos-before-27
Nov 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
XIIYAZ:fix/libkernel-pipe2-macos-before-27

Conversation

@XIIYAZ

@XIIYAZ XIIYAZ commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

What

pipe2_nid_postfix calls the host ::pipe2 on every non-Windows host. In the macOS 27 SDK, sys/unistd.h declares pipe2 (and dup3) with __API_AVAILABLE(macos(27.0), ...), and the libraries are built with a lower minimum version (LC_BUILD_VERSION minos 26.0 here), so pipe2 is weakly imported. On macOS 26 it resolves to null, and the first guest pipe or pipe2 jumps to address 0:

* thread #1, stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
  * frame #0: 0x0000000000000000
    frame #1: libkernel.prx`pipe2_nid_postfix + 79

The compiler reports it as 'pipe2' is only available on macOS 27.0 or newer at Stdio.cpp:767. With an SDK older than 27, pipe2 is not declared and the file does not compile.

On macOS the pipe is now made with pipe, then FD_CLOEXEC and O_NONBLOCK are set with fcntl when requested; if either fcntl fails, both descriptors are closed and the call fails with that errno. This works on every macOS version and SDK. Unlike pipe2, close-on-exec is not set atomically with the creation, so a concurrent fork/exec in another thread can inherit the descriptors in that window. Linux and Windows are unchanged.

Tested

macOS 26.7.3, Apple M4, Xcode SDK 27.2, Apple clang 21.0.0, CMake 4.4.4, Ninja, full build (-DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DCMAKE_OSX_ARCHITECTURES=x86_64, tests run under Rosetta) on main with #17425, #11049 and #11437 merged locally for the other macOS build breaks.

  • Full ctest before: 5002/5082 passed; 35 failures were segfaults.
  • After this change, rerunning the 80 failures: 32 pass that failed before (4 other tests also passed on a rerun without this change and are left out as flaky). The 32: guest_dup, guest_file_timestamps, guest_filesystem, guest_fstatfs, guest_fstatvfs, guest_getrlimit, guest_host_standard_error, guest_host_streams, guest_kernel_fcntl, guest_kernel_fcntl_sync, guest_kernel_fstat, guest_kernel_ioctl_fionread, guest_kernel_pipe2, guest_kernel_sock_names, guest_kernel_socket_shutdown, guest_kernel_sys_aio, guest_kernel_sys_dup, guest_kernel_sys_pselect, guest_kernel_sys_pwrite, guest_kernel_sys_pwrite_patched, guest_kernel_web_forwards, guest_kqueue, guest_pipe_fault, guest_poll, guest_posix_filesystem, guest_posix_scalar_io, guest_select, guest_socket_descriptor_flags, guest_socket_events, guest_socket_on_non_socket, guest_socket_rights, guest_terminal.
  • The 'pipe2' is only available on macOS 27.0 or newer warning for Stdio.cpp is gone.

python3 tools/check_conventions.py --base origin/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@XIIYAZ XIIYAZ mentioned this pull request Nov 14, 2026
@JJenkx

JJenkx commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 968b63f5f8, merged onto main 74900e8b0f (968b63f5f8, 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_deferred_module_sweep_no_arguments, 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_clock, guest_kernel_clocks_nanosleep, guest_kernel_errors, guest_kernel_fcntl, guest_kernel_fcntl_sync, guest_kernel_fstat, guest_kernel_gettimeofday, guest_kernel_ioctl_fionread, guest_kernel_is_stack, guest_kernel_login_bounds, guest_kernel_pipe2, guest_kernel_pread_pwrite, guest_kernel_pthread_cond_np_bounds, guest_kernel_pthread_key_dtor_order, guest_kernel_pthread_once, guest_kernel_pthread_sync, guest_kernel_rename, guest_kernel_resident_fmem_export, guest_kernel_resident_fmem_export_patched, guest_kernel_rwlockattr_settype, guest_kernel_sig_pending, guest_kernel_sigaction_sets, guest_kernel_sigset, guest_kernel_sock_names, guest_kernel_socket_dontwait, guest_kernel_socket_shutdown, guest_kernel_software_version_bounds, guest_kernel_stack_protect, guest_kernel_sync, guest_kernel_sysconf_params, 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_contention, 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_ptr, 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_race, 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_sendmsg_memory, guest_setrlimit, guest_shm_open, guest_sigaltstack, guest_signal_context, 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_sync_wakeups, 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.

@github-actions

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 6936 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7121 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7447 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 9293 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 9297 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 9302 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 12682 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 12688 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 12700 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 12965 core/libs/prx/libkernel/File/src/Stdio.cpp

@oneandonlydean
oneandonlydean merged commit f8ca507 into boykopovar:main Nov 14, 2026
14 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.

3 participants