build(libusb): build libusb without pipe2 on macOS, where pipe2 needs macOS 27 #19920

Merged
XIIYAZ merged 1 commit from upstream-pr/19920 into main 2026-11-15 02:16:41 +00:00
XIIYAZ commented 2026-11-14 08:10:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XIIYAZ on 2026-11-14T08:10:07Z.


What

libusb-cmake sets HAVE_PIPE2 from check_function_exists(pipe2 HAVE_PIPE2). The macOS 27 SDK declares pipe2 with __API_AVAILABLE(macos(27.0), ...), so the check passes, usbi_create_event calls pipe2, and with a lower minimum version the symbol is weakly imported and null on macOS 26. sceUsbdInit then jumps to address 0:

* stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #1: libSceUsbd.prx`usbi_create_event + 20
    frame #2: libSceUsbd.prx`usbi_io_init + 248
    frame #3: libSceUsbd.prx`libusb_init_context + 704
    frame #4: libSceUsbd.prx`sceUsbdInit + 65

The compiler also warns 'pipe2' is only available on macOS 27.0 or newer at events_posix.c:87.

On Apple, HAVE_PIPE2 is now preset to false before add_subdirectory(3rdparty/libusb-cmake); check_function_exists skips a variable that is already defined, so libusb takes its own pipe + fcntl(FD_CLOEXEC) path, which works on every macOS version. No third-party file changes; Linux and Windows are unchanged. This is the libusb side of the libkernel pipe2 call fixed in #19903.

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 under Rosetta) on main with #17425, #11049, #11437 and #19903 merged locally:

  • Before: guest_usbd segfaults with the backtrace above.
  • After: the generated libusb config.h has /* #undef HAVE_PIPE2 */, the events_posix.c availability warning is gone, and guest_usbd passes.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5309082137 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19920). Originally posted by [XIIYAZ](https://github.com/XIIYAZ) on 2026-11-14T08:10:07Z. --- ### What libusb-cmake sets `HAVE_PIPE2` from `check_function_exists(pipe2 HAVE_PIPE2)`. The macOS 27 SDK declares `pipe2` with `__API_AVAILABLE(macos(27.0), ...)`, so the check passes, `usbi_create_event` calls `pipe2`, and with a lower minimum version the symbol is weakly imported and null on macOS 26. `sceUsbdInit` then jumps to address 0: ``` * stop reason = EXC_BAD_ACCESS (code=1, address=0x0) frame #1: libSceUsbd.prx`usbi_create_event + 20 frame #2: libSceUsbd.prx`usbi_io_init + 248 frame #3: libSceUsbd.prx`libusb_init_context + 704 frame #4: libSceUsbd.prx`sceUsbdInit + 65 ``` The compiler also warns `'pipe2' is only available on macOS 27.0 or newer` at `events_posix.c:87`. On Apple, `HAVE_PIPE2` is now preset to false before `add_subdirectory(3rdparty/libusb-cmake)`; `check_function_exists` skips a variable that is already defined, so libusb takes its own `pipe` + `fcntl(FD_CLOEXEC)` path, which works on every macOS version. No third-party file changes; Linux and Windows are unchanged. This is the libusb side of the `libkernel` `pipe2` call fixed in #19903. ### 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 under Rosetta) on `main` with #17425, #11049, #11437 and #19903 merged locally: - Before: `guest_usbd` segfaults with the backtrace above. - After: the generated libusb `config.h` has `/* #undef HAVE_PIPE2 */`, the `events_posix.c` availability warning is gone, and `guest_usbd` passes. `python3 tools/check_conventions.py --base origin/main` passes. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!19920
No description provided.