feat(usbd): submit and cancel asynchronous USB transfers #2228

Closed
erick-dsnk wants to merge 2 commits from upstream-pr/2228 into main
erick-dsnk commented 2026-10-09 12:29:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by erick-dsnk on 2026-10-09T12:29:43Z.


What

Depends on #2224.

Implement sceUsbdSubmitTransfer and sceUsbdCancelTransfer on the source-built libusb backend introduced by #2224. Submitted transfers now reach native USB I/O, completions copy status, byte counts and isochronous packet results back to the guest object, and cancellation completes through the same callback path. A separate native transfer invokes the original guest callback through the System V ABI, including on Windows. Supporting allocation/free changes preserve resubmission and freeing from callbacks, prevent freeing pending transfers, and release auto-free buffers through the guest heap.

This contribution adds 2 implementations beyond #2224: CPU libraries move from 2600/3044 (85.41%) to 2602/3044 (85.48%). The 22 synchronous implementations and dependency files visible in the current diff belong to #2224; they are inherited unchanged. This branch is based on its exact head 3dbf85f0d9be6a45baa955d28528b46058426e27 and should merge after it. sceUsbdCheckConnected still throws.

The asynchronous signatures follow OpenOrbis Usbd.h and shadPS4 declarations. Transfer ownership, flags and completion behavior follow libusb 1.0.30. There is no additional third-party dependency in this follow-up.

PS5 hardware ABI, Windows asynchronous execution, game behavior and physical control/interrupt payloads remain unverified. Linux native tests enumerate devices and read descriptors; transfer completion tests use a deterministic native submission/event backend. These limits are recorded in TechnicalDebt.

Tested

Linux x86-64, GCC 13.3.0, Release, BUILD_TESTING=ON:

  • Full CMake configure/build and --target libs: passed.
  • guest_usbd, guest_usbd_control, guest_usbd_async: passed. Native tests enumerated 17 host devices and read descriptors. The new asynchronous tests use real libusb allocations/context, wrapping only native allocation/free accounting and submit/cancel/event delivery. They verify error translation, double submission rejection, pending-free rejection, cancellation, guest callback identity and data, resubmission, freeing from callbacks, isochronous results, and guest-heap auto-free ownership.
  • AddressSanitizer and UndefinedBehaviorSanitizer asynchronous suite: passed.
  • Full ctest --parallel 2 --timeout 30: 512 passed, 1 skipped (agc_driver_storage_cache_budget), 2 failed (agc_driver_dcc_keys_first_write assertion and agc_driver_flat_store timeout). Neither involves USB.
  • Serial recheck on this head: DCC assertion reproduced; flat-store still exceeded 30 s. On the exact #2224 parent, after normal configure/full build/libs, the identical DCC assertion reproduced and flat-store passed in 29.14 s. That test is close to the fixed 30-second limit; no AGC code or timeout was changed.
  • Conventions check against current upstream/main: passed.
  • Windows build/runtime and a game/homebrew: not tested locally for this follow-up.

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: #2224
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4800420966 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2228). Originally posted by [erick-dsnk](https://github.com/erick-dsnk) on 2026-10-09T12:29:43Z. --- ### What Depends on #2224. Implement `sceUsbdSubmitTransfer` and `sceUsbdCancelTransfer` on the source-built libusb backend introduced by #2224. Submitted transfers now reach native USB I/O, completions copy status, byte counts and isochronous packet results back to the guest object, and cancellation completes through the same callback path. A separate native transfer invokes the original guest callback through the System V ABI, including on Windows. Supporting allocation/free changes preserve resubmission and freeing from callbacks, prevent freeing pending transfers, and release auto-free buffers through the guest heap. This contribution adds **2** implementations beyond #2224: CPU libraries move from 2600/3044 (85.41%) to 2602/3044 (85.48%). The 22 synchronous implementations and dependency files visible in the current diff belong to #2224; they are inherited unchanged. This branch is based on its exact head `3dbf85f0d9be6a45baa955d28528b46058426e27` and should merge after it. `sceUsbdCheckConnected` still throws. The asynchronous signatures follow [OpenOrbis Usbd.h](https://github.com/OpenOrbis/OpenOrbis-PS4-Toolchain/blob/master/include/orbis/Usbd.h) and [shadPS4 declarations](https://github.com/shadps4-emu/shadPS4/blob/0fe263a4760dfbfa973366890061749b4af0de97/src/core/libraries/usbd/usbd.h). Transfer ownership, flags and completion behavior follow [libusb 1.0.30](https://github.com/libusb/libusb/tree/v1.0.30). There is no additional third-party dependency in this follow-up. PS5 hardware ABI, Windows asynchronous execution, game behavior and physical control/interrupt payloads remain unverified. Linux native tests enumerate devices and read descriptors; transfer completion tests use a deterministic native submission/event backend. These limits are recorded in TechnicalDebt. ### Tested Linux x86-64, GCC 13.3.0, Release, BUILD_TESTING=ON: - Full CMake configure/build and `--target libs`: passed. - `guest_usbd`, `guest_usbd_control`, `guest_usbd_async`: passed. Native tests enumerated 17 host devices and read descriptors. The new asynchronous tests use real libusb allocations/context, wrapping only native allocation/free accounting and submit/cancel/event delivery. They verify error translation, double submission rejection, pending-free rejection, cancellation, guest callback identity and data, resubmission, freeing from callbacks, isochronous results, and guest-heap auto-free ownership. - AddressSanitizer and UndefinedBehaviorSanitizer asynchronous suite: passed. - Full `ctest --parallel 2 --timeout 30`: 512 passed, 1 skipped (`agc_driver_storage_cache_budget`), 2 failed (`agc_driver_dcc_keys_first_write` assertion and `agc_driver_flat_store` timeout). Neither involves USB. - Serial recheck on this head: DCC assertion reproduced; flat-store still exceeded 30 s. On the exact #2224 parent, after normal configure/full build/libs, the identical DCC assertion reproduced and flat-store passed in 29.14 s. That test is close to the fixed 30-second limit; no AGC code or timeout was changed. - Conventions check against current upstream/main: passed. - Windows build/runtime and a game/homebrew: not tested locally for this follow-up. ### 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: #2224 - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-09 12:40:25 +00:00 (Migrated from github.com)

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


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:6081078415 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2228#issuecomment-6081078415). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-09T12:40:25Z. --- <!-- 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:29 +00:00 (Migrated from github.com)

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


Closing with #2224: no title reaches the async Usbd calls on main. Please reopen when one does.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6088449735 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2228#issuecomment-6088449735). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T20:10:29Z. --- Closing with #2224: no title reaches the async Usbd calls on main. Please reopen when one does.

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