feat(usbd): add native synchronous USB backend #2224

Closed
obojeoboje wants to merge 1 commit from upstream-pr/2224 into main
obojeoboje commented 2026-10-09 12:10:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by obojeoboje on 2026-10-09T12:10:21Z.


What

Replace 22 throwing libSceUsbd exports with a synchronous host USB backend using libusb 1.0.30. Previously the library always returned an empty device list and threw on all device operations. It now enumerates real host devices, reads device/configuration/string descriptors, manages device references and handles, claims/releases interfaces, performs control transfers, and exposes native configuration/reset/driver operations.

Add libusb as a pinned submodule (libusb/libusb-cmake, tag v1.0.30-0, commit c8477c10ac2ac6b1718d4d498e102b9f18b776f5) and build it statically from source. Linux uses the bundled netlink enumeration backend rather than a system libudev dependency. Hide native libusb exports from the guest library.

Use the signatures, native descriptor layouts and USB error conversion documented by shadPS4 usbd.h and usbd.cpp, with locally written wrappers. Own a separate reference-counted libusb context and convert the guest's 64-bit timeval fields to the host representation.

Transfer allocation/free and interrupt-transfer preparation work, preserving the guest callback pointer. Asynchronous submit/cancel and sceUsbdCheckConnected remain throwing stubs. Host permissions and USB drivers apply; console lifecycle and invalid-argument error precedence remain unverified. Record these limits in TechnicalDebt and remove the obsolete no-device silent-stub entry.

The progress scanner changes from 2578/3044 (84.69%) to 2600/3044 (85.41%), +22 implementations and +0.72 percentage points.

Tested

Windows, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON:

  • Native USB tests enumerated 9 host devices, read cached device descriptors and available configuration descriptors, checked device/list reference lifetimes, repeated initialization/exit, transfer allocation/preparation, SysV guest callback invocation, invalid arguments, and remaining throwing paths.

  • Deterministic control-transfer tests replace only the native libusb control-transfer call at link time. They verify setup fields, byte counts and buffer output, error conversion (including OTHER), zero/maximum/invalid lengths, string-descriptor requests, and that invalid calls never reach the backend.

  • Native libusb functions are not exported from the built guest library.

  • Test registration and conventions checks passed.

  • cmake --build build --parallel 12 completed successfully, as did cmake --build build --target libs --parallel 12.

  • ctest --test-dir build --output-on-failure --parallel 4 --timeout 30: 506 passed, 1 skipped (guest_video_out_wqhd_detection_no_vulkan), 1 timed out (agc_driver_flat_store). The timeout was 30.06 s; no timeout setting was raised.

  • Re-ran agc_driver_flat_store, guest_usbd and guest_usbd_control sequentially with the same 30-second limit: all 3 passed (24.19 s, 0.10 s, 0.01 s respectively).

No game or homebrew was tested. Physical devices were enumerated and their descriptors read; control-transfer payload tests used the test backend. Linux has not been tested locally.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4800212981 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2224). Originally posted by [obojeoboje](https://github.com/obojeoboje) on 2026-10-09T12:10:21Z. --- ### What Replace 22 throwing `libSceUsbd` exports with a synchronous host USB backend using libusb 1.0.30. Previously the library always returned an empty device list and threw on all device operations. It now enumerates real host devices, reads device/configuration/string descriptors, manages device references and handles, claims/releases interfaces, performs control transfers, and exposes native configuration/reset/driver operations. Add libusb as a pinned submodule (`libusb/libusb-cmake`, tag `v1.0.30-0`, commit `c8477c10ac2ac6b1718d4d498e102b9f18b776f5`) and build it statically from source. Linux uses the bundled netlink enumeration backend rather than a system libudev dependency. Hide native libusb exports from the guest library. Use the signatures, native descriptor layouts and USB error conversion documented by [shadPS4 usbd.h](https://github.com/shadps4-emu/shadPS4/blob/0fe263a4760dfbfa973366890061749b4af0de97/src/core/libraries/usbd/usbd.h) and [usbd.cpp](https://github.com/shadps4-emu/shadPS4/blob/0fe263a4760dfbfa973366890061749b4af0de97/src/core/libraries/usbd/usbd.cpp), with locally written wrappers. Own a separate reference-counted libusb context and convert the guest's 64-bit timeval fields to the host representation. Transfer allocation/free and interrupt-transfer preparation work, preserving the guest callback pointer. Asynchronous submit/cancel and `sceUsbdCheckConnected` remain throwing stubs. Host permissions and USB drivers apply; console lifecycle and invalid-argument error precedence remain unverified. Record these limits in TechnicalDebt and remove the obsolete no-device silent-stub entry. The progress scanner changes from 2578/3044 (84.69%) to 2600/3044 (85.41%), +22 implementations and +0.72 percentage points. ### Tested Windows, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON: - Native USB tests enumerated 9 host devices, read cached device descriptors and available configuration descriptors, checked device/list reference lifetimes, repeated initialization/exit, transfer allocation/preparation, SysV guest callback invocation, invalid arguments, and remaining throwing paths. - Deterministic control-transfer tests replace only the native libusb control-transfer call at link time. They verify setup fields, byte counts and buffer output, error conversion (including OTHER), zero/maximum/invalid lengths, string-descriptor requests, and that invalid calls never reach the backend. - Native libusb functions are not exported from the built guest library. - Test registration and conventions checks passed. - `cmake --build build --parallel 12` completed successfully, as did `cmake --build build --target libs --parallel 12`. - `ctest --test-dir build --output-on-failure --parallel 4 --timeout 30`: 506 passed, 1 skipped (`guest_video_out_wqhd_detection_no_vulkan`), 1 timed out (`agc_driver_flat_store`). The timeout was 30.06 s; no timeout setting was raised. - Re-ran `agc_driver_flat_store`, `guest_usbd` and `guest_usbd_control` sequentially with the same 30-second limit: all 3 passed (24.19 s, 0.10 s, 0.01 s respectively). No game or homebrew was tested. Physical devices were enumerated and their descriptors read; control-transfer payload tests used the test backend. Linux has not been tested locally. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
github-actions[bot] commented 2026-10-09 12:40:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-09T12:40:23Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2351 docs/dev/TechnicalDebt.md L246
#2364 docs/dev/TechnicalDebt.md L23-24
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6081077891 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2224#issuecomment-6081077891). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T12:40:23Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #2351 | `docs/dev/TechnicalDebt.md` [L246](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/docs/dev/TechnicalDebt.md#L246) | | | | #2364 | `docs/dev/TechnicalDebt.md` [L23-24](https://github.com/boykopovar/AnyPS5/blob/8b393b6e9a8ade9188d4f74a0293e0efd9828597/docs/dev/TechnicalDebt.md#L23-L24) | | |
oneandonlydean commented 2026-10-09 20:10:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T20:10:23Z.


Closing: no title reaches these Usbd calls on main, and a new libusb dependency needs one that does. If you find a title that talks to a USB device, please reopen with its ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088448307 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2224#issuecomment-6088448307). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:10:23Z. --- Closing: no title reaches these Usbd calls on main, and a new libusb dependency needs one that does. If you find a title that talks to a USB device, please reopen with its ID and the log line.

Pull request closed

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!2224
No description provided.