Repository navigation
fix(libSceUsbd): return SCE_USBD_ERROR_INVALID_ARG from sceUsbdCancelTransfer for a null transfer - #21195
fix(libSceUsbd): return SCE_USBD_ERROR_INVALID_ARG from sceUsbdCancelTransfer for a null transfer#21195roboterspinne wants to merge 1 commit into
Conversation
…Transfer for a null transfer sceUsbdCancelTransfer threw std::runtime_error for a null transfer, so a title that cancelled one ended the process. FreeBSD 11.4 libusb_cancel_transfer returns LIBUSB_ERROR_INVALID_PARAM for it, which ToGuestError maps to 0x80240002, and the libSceUsbd errors debt entry states that rule. The call now returns SCE_USBD_ERROR_INVALID_ARG, as sceUsbdSubmitTransfer already does; GuestUsbd.cpp checks it.
PrivacyOnion
left a comment
There was a problem hiding this comment.
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against c69337c980:
- Conventions:
tools/check_conventions.pypassed;git diff --checkclean. - Build:
guest_usbd_testsbuilt cleanly. - CTest (
guest_usbd):1/1 Test #4773: guest_usbd ....................... Passed 2.34 sec 100% tests passed, 0 tests failed out of 1 - Negative control: with
core/libs/prx/libSceUsbd/Export.cppreverted tomainand the new tests kept, the suite fails:Restoring the change makes it pass again.1/1 Test #4773: guest_usbd .......................Subprocess aborted***Exception: 2.73 sec 0% tests passed, 1 tests failed out of 1 - Code reading:
- Verified core/libs/prx/libSceUsbd/Export.cpp:486-487 checks transfer == nullptr before acquiring state.mutex or accessing state.inFlight, returning SCE_USBD_ERROR_INVALID_ARG (0x80240002).
- Confirmed error code mapping matches FreeBSD libusb_cancel_transfer returning LIBUSB_ERROR_INVALID_PARAM (-2), which maps via ToGuestError (Export.cpp:75-79) to 0x80240002 (SCE_USBD_ERROR_INVALID_ARG, defined at Export.cpp:27).
- Checked concurrency and lock lifetimes in sceUsbdCancelTransfer: the early return happens prior to std::lock_guard lock(state.mutex), so no lock is held or leaked and no shared state is mutated.
- Verified core/libs/tests/GuestUsbd.cpp:573 directly exercises sceUsbdCancelTransfer(nullptr) and asserts it returns invalidArgument (0x80240002) without leaving dirty state.
- Checked compliance with AGENTS.md and docs/dev/debt/libSceUsbd.md: no code comments added, no title-specific special cases, and the behavior aligns with the documented libSceUsbd error rule for null arguments rejected by FreeBSD libusb.
Looks Good To Me
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The null-transfer check now returns the established invalid-argument error, and the added test covers that behavior.
What I ran
Reviewed head c69337c980fd316e065ecf3455653e0b4f911c99. No commands or tests were run; the author reports Windows 11 test results in the PR description.
Results
| Check | Result | Note |
|---|---|---|
| Changed code review | passed | Both changed files read |
guest_usbd test |
not run | Windows result reported by author |
| Linux and macOS | not run | Not verified here |
Findings
Blocking
None.
Non-blocking
None.
Not verified
I read core/libs/prx/libSceUsbd/Export.cpp and core/libs/tests/GuestUsbd.cpp; both files listed as reviewed were included in the prepared review folder. I did not run tests or verify the author's reported results, Linux/macOS behavior, or console behavior.
To get this to a good state
Nothing is required.
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
ligmaSec
left a comment
There was a problem hiding this comment.
I ran guest_usbd with the patch applied on Linux. The full fixture passed, including the regression check for the invalid-argument result from a null cancel-transfer request.
AI-assisted: yes.
Plyxen
left a comment
There was a problem hiding this comment.
I read the diff at c69337c980. Windows 11 with GCC 15.2 and Linux (Ubuntu 24.04 in WSL2, GCC 13.3), merged into main at c1593e4e1dd together with other open PRs (so not an isolated build).
guest_usbd: pass on both.- Control (the same tree and tests, with the sources of this PR and of the other CPU PRs in the batch put back to
main's): it fails with "sceUsbdCancelTransfer: null transfer".
Not checked: the values against a console.
AI-assisted: yes (Claude Code)
What
On
maind4a1472sceUsbdCancelTransfer(core/libs/prx/libSceUsbd/Export.cpp:486-493) throwsstd::runtime_error("sceUsbdCancelTransfer: null transfer")for a null transfer (:487), so a title that cancels a null transfer ends the host process (counter-check under Tested). The library follows FreeBSD 11.4 libusb (docs/dev/debt/libSceUsbd.md:5-6). Therelibusb_cancel_transferbegins withif (uxfer == NULL) return (LIBUSB_ERROR_INVALID_PARAM);(libusb10.c:1510-1511).LIBUSB_ERROR_INVALID_PARAMis -2, andToGuestError(Export.cpp:75-79) maps it to 0x80240000 + 2 = 0x80240002,SCE_USBD_ERROR_INVALID_ARG(Export.cpp:27). The debt entry "libSceUsbd errors" (docs/dev/debt/libSceUsbd.md:6) states this rule: the null arguments FreeBSD libusb rejects return0x80240002. It names onlysceUsbdOpenandsceUsbdGetActiveConfigDescriptoras null throws, on a null device they dereference. The siblingsceUsbdSubmitTransferalready returnsSCE_USBD_ERROR_INVALID_ARGfor a null transfer (Export.cpp:670), as FreeBSD'slibusb_submit_transferdoes (libusb10.c:1447-1448), andcore/libs/tests/GuestUsbd.cpp:572asserts it. What the console returns is not measured; the debt entry "libSceUsbd transfers, kernel drivers and host access" (docs/dev/debt/libSceUsbd.md:7) records the error codes as unverified on PS5.sceUsbdCancelTransfer(nullptr)returnsSCE_USBD_ERROR_INVALID_ARG(0x80240002) instead of throwing. One line changes (Export.cpp:487). A non-null transfer that is not in flight still returnsSCE_USBD_ERROR_NOT_FOUND(0x80240005,:491), and an in-flight transfer still goes throughToGuestError(libusb_cancel_transfer(...))(:492). FreeBSD'suxfer->status = LIBUSB_TRANSFER_CANCELLEDwrite for a transfer that is not pending (libusb10.c:1533-1536) is a separate topic and not part of this change.docs/dev/debt/libSceUsbd.md:6) already states the rule this change follows, and no entry mentions a throw for a null transfer (tools/debt_fold.py --show libSceUsbd, pending fragments applied, has no match for "null transfer").core/libs/tests/GuestUsbd.cpp, inmainright after thesceUsbdSubmitTransfer(nullptr)check (:572):Require(sceUsbdCancelTransfer(nullptr) == invalidArgument, "null transfer cancelled"), withinvalidArgumentdefined as 0x80240002 at:24. ctestguest_usbd; no other test name matches^guest_usbd$, and no CMake change.mainreaches the line without a USB device: aftersceUsbdInit(:472) there is no return,argcbranch or#ifbefore it, and initialization keeps an empty device list when the host has no USB access (docs/dev/debt/libSceUsbd.md:7). The existing cancel checks (:359,:362,:384,:396,:571) pass a non-null transfer and are unchanged.guest_usbdis registered underif(BUILD_TESTING)with no host condition (core/libs/prx/libSceUsbd/CMakeLists.txt:9-18); only itsPATHsetting is underWIN32, and libSceUsbd links the3rdparty/libusb-cmakesubmodule on every host. Without the change the throw is the first statement ofsceUsbdCancelTransfer, before any lock or libusb call, so it does not depend on the host. Nothing catches it andRequireis not wrapped inThrowsthere, so the test terminates with the uncaughtstd::runtime_erroron Linux and macOS as it does on Windows. Nothing was run on Linux here.pr_overlap.py --names sceUsbdCancelTransferfinds no open pull request that implements it.pr_overlap.py --branchreports no shared lines or exports with the open pull requests it can compare (maind4a1472); it cannot compare fix(libSceUsbd): retain devices during active USB operations #9803 (Dellz36), which does not merge withmain. Checked by hand: fix(libSceUsbd): retain devices during active USB operations #9803 leavessceUsbdCancelTransferas its own base has it, and a trial merge of fix(libSceUsbd): retain devices during active USB operations #9803 with this branch conflicts in the same two files with the same number of regions (16 inExport.cpp, 11 inGuestUsbd.cpp) as a trial merge withmaind4a1472.Tested
Windows 11, WinLibs GCC 15.2.0, Ninja, Release,
BUILD_TESTING=ON, build directory configured through its 8.3 short path, on d4a1472. Built withcmake --build <build> --parallel 4 --target guest_usbd_tests; each of the four builds below exited 0. Before every run eachcore/libs/libs/unpatched/*.prxthat also exists in<build>/tests(libSceUsbd.prx,libc.prx,libkernel.prx) was copied there withcmake -E copy_if_different, and themd5sumoflibSceUsbd.prxin both places matched each time.ctest --test-dir <build> -R '^guest_usbd$' --show-only=json-v1lists one test,guest_usbd(tests/guest_usbd_tests.exe);-R 'usbd'lists no other test, and no other CMake file linkslibSceUsbd.Export.cppof d4a1472, new test line in place):ctest --test-dir <build> -R '^guest_usbd$' --output-on-failurefails withExit code 0xc0000409; the output showsterminate called after throwing an instance of 'std::runtime_error'andwhat(): sceUsbdCancelTransfer: null transfer.Export.cppline put back to d4a1472 andguest_usbd_testsrebuilt, the test failed again withExit code 0xc0000409andwhat(): sceUsbdCancelTransfer: null transfer. With the change restored and rebuilt, it passed 1 of 1.python tools/check_conventions.py --base upstream/main --head HEADwith this title and description passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)