feat(libSceUsbd): pass USB devices and transfers through to the host with libusb #3848
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3848"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by 13hourstilliland on 2026-10-11T17:55:53Z.
What
Replaces the no-device path with host libusb 1.0.30, built from a new
3rdparty/libusb-cmakesubmodule (pinned to bea6567).static_assertpins sizes and offsets.0x80240000 - code, withLIBUSB_ERROR_OTHERas0x802400FF, as in shadPS4.sceUsbdHandleEventsTimeout. Transfer flags other than short-not-ok and add-zero-packet throw.This builds on LordLava's closed #2870, which used the same submodule and approach. Stacked on #3847; until that merges the diff shows both commits.
Tested
guest_usbd devicewithAPS5_USBD_DEVICE=3537:100flists the device, reads its device and config descriptors and product string, does a synchronous control request, claims and releases all three interfaces, and completes an asynchronous control transfer through the event loop. Each result matches the controller's own descriptor.guest_usbdrun passes.check_conventions.pypasses. Isochronous transfers and PS5 behaviour are unverified, as recorded in TechnicalDebt. Not tested with a title.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T17:56:12Z.
Progress report (
84659e1→42cf829)📈 System libraries: 87.19% (+0.04%, +10 implemented functions)
✅ 10 implemented
sceUsbdBulkTransfersceUsbdControlTransferGetDatasceUsbdControlTransferGetSetupsceUsbdFillBulkTransfersceUsbdFillControlSetupsceUsbdFillControlTransfersceUsbdFillIsoTransfersceUsbdGetIsoPacketBuffersceUsbdInterruptTransfersceUsbdSetIsoPacketLengthsImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T18:17:38Z.
Review: CHANGES_REQUESTED
Thanks for the rework. Built the PR merged onto
mainand ranguest_usbd: it passes, and it fails without the change.One problem to fix:
core/libs/prx/libSceUsbd/Export.cpp:254-262(sceUsbdCancelTransfer): the mutex is released beforelibusb_cancel_transfer(host). If another thread runssceUsbdHandleEventsTimeoutandCompleteTransferfinishes (libusb_free_transfer(host)) in between,hostis a dangling pointer. Keepstate.mutexlocked across thelibusb_cancel_transfercall (it does not invoke the callback synchronously, soCompleteTransfertaking the same mutex cannot deadlock), or otherwise make the lookup and the cancel atomic. A test with one thread cancelling while another pumps events would pin it.This is stacked on #3847, so it also has to wait for that one to merge.
Imported from boykopovar/AnyPS5. Originally posted by 13hourstilliland on 2026-10-11T19:05:33Z.
Fix pushed
sceUsbdCancelTransfernow keepsstate.mutexheld acrosslibusb_cancel_transfer, as suggested: the lookup and the cancel are one critical section.feat/usbd-libusb(741f43cc); the helpers PR stays helpers-only. Both are 0 commits behindmain.Imported from boykopovar/AnyPS5. Originally posted by 13hourstilliland on 2026-10-11T22:12:02Z.
Thanks — the cancel lock is fixed in 21f764e69:
sceUsbdCancelTransfernow holdsstate.mutexacrosslibusb_cancel_transfer, and the lookup and the cancel are one critical section.CompleteTransfertaking the same mutex off the event thread cannot deadlock, because the cancel never invokes the callback synchronously.While running the device path on Windows with the Xbox 360 controller (VID 3537, PID 100F) I found a second crash in the test, present before this PR and without it:
guest_usbd_tests devicedies with an access violation at its endpoint scan. Root cause was a use-after-free — the test read the config descriptor for the interrupt-endpoint scan aftersceUsbdFreeConfigDescriptorhad already freed it, soconfig->interfaceand the array behind it came back as freed garbage whose inner pointers were null or stale (alternate[4]was the first hardened read to trip). Fixed by refetching config descriptor 0 over the handle before the scan and skipping nullaltsetting/endpointarrays in it (59dca5975, previously 873100e97).On the updated head 59dca5975 with the controller live: the full device run including the cancel-vs-events race completes 3 for 3, exit 0;
guest_usbdctest passes on Linux and Windows.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-12T20:41:31Z.
Review: APPROVED
Rebased onto current
main; the only conflict wasdocs/dev/TechnicalDebt.md, whose libSceUsbd entry now lives indocs/dev/debt/libSceUsbd.md, so I moved the PR's updated line there. No logic changed.Checked on Linux with the PR merged onto
main: full build,guest_usbdpasses and fails without the change (no-device path only, no USB access here), whole ctest green. The cancel-under-lock fix from the earlier review is in. Device, isochronous and PS5 behaviour were not run here and stay as recorded in TechnicalDebt; merging once CI is green.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T20:47:14Z.
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.
main).gitmodulesL33.gitmodulesL33.gitmodulesL33