Files
AnyPS5/docs/dev/debt/libSceUsbd.md
T
MaxandClaude Opus 5.5 9f3799cfaa fix(libSceUsbd): wake event waiters after each pass of event handling
FreeBSD 11.4's libusb10_handle_events_sub ends every pass, a timed-out
one included, with pthread_cond_broadcast on the context's condition
variable, so a thread in libusb_wait_for_event wakes after each pass of
the handler. Here waiters woke only when the handler unlocked, so a
waiter could sleep through the handler's whole loop. Notify them when
the handler takes the event lock back after a pass.

The follower test that expected a timeout while the handler ran 20 ms
passes now races that wake-up, so guest_usbd checks three cases
instead: a follower with a long timeout returns 0 after a pass, a
follower times out during a longer pass, and a follower returns after
the handler held the event lock past its timeout.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-28 15:27:07 +01:00

6.2 KiB

libSceUsbd technical debt

Silent stubs

  • libSceUsbd passes the calls through to the host with libusb built from the 3rdparty/libusb-cmake submodule. Devices, handles and descriptors are libusb's own objects: the device, config, interface and endpoint descriptor layouts of FreeBSD 11.4 libusb match libusb's field for field, which static_assert pins. Each one handed to the title is tracked, and a pointer this library did not return throws.
  • libSceUsbd errors (libSceUsbd) - errors are libusb's codes mapped to 0x80240000 - code, with LIBUSB_ERROR_OTHER at 0x802400FF, following shadPS4; the null arguments FreeBSD libusb rejects (libusb10.c, libusb10_desc.c, libusb10_io.c) return 0x80240002, and sceUsbdOpen and sceUsbdGetActiveConfigDescriptor throw on a null device, which it dereferences.
  • libSceUsbd transfers, kernel drivers and host access (libSceUsbd) - a submitted transfer is copied into a host transfer whose completion copies the status, actual length and iso packet results back and then calls the title's callback from event handling; transfer flags other than short-not-ok and add-zero-packet throw. sceUsbdAttachKernelDriver returns 0 as FreeBSD's stub does, sceUsbdCheckConnected reports a device gone when reading its configuration fails with LIBUSB_ERROR_NO_DEVICE (FreeBSD asks the kernel directly). When the host has no USB access, initialization keeps the empty device list and event handling waits for its timeout. Opening, descriptors, string and control requests, interface claims and an asynchronous control transfer were checked against an Xbox 360 controller on Windows; the transfer layout, the argument lists, the error codes and isochronous transfers are unverified on PS5

Functional