fix(libSceSdma): reject null and closed handles instead of dereferencing or throwing #16342

Merged
MarcZX10 merged 6 commits from upstream-pr/16342 into main 2026-11-11 08:53:20 +00:00
MarcZX10 commented 2026-11-06 10:12:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-06T10:12:14Z.


What

libSceSdma dereferenced its handle without checking it, and a command submitted on a closed handle ended in a NotImplemented throw because a closed slot has a zero-sized ring.

  • fix(libSceSdma): return an invalid-argument error for a null handle: sceSdmaClose, BeginQueueMode, CancelQueue, EndQueueMode, FenceNonBlocking, FlushAll, KickQueue, TryFlush and the shared Submit used by the copy and fill commands now return SdmaErrorInvalidArgument for a null handle instead of dereferencing it.
  • fix(libSceSdma): reject submissions on a closed handle: Submit returns the same error when the slot is not open, so a blocking or non-blocking command on a closed handle no longer reaches the ring checks.
  • One test commit after each fix in GuestSdma.cpp (RequireNullHandle calls every handle entry point with a null handle; RequireClosedHandle closes a handle and checks that fill and copy commands are rejected and the destination stays zero).
  • docs(debt): record the unmeasured error code for null and closed handles: the code is 0x80990005, the one sceSdmaOpen already uses for bad arguments; no invalid-handle code is documented for this library and the console value for these cases is not measured.

Tested

Linux, throwaway archive build of this head: BUILD-EXIT 0, ctest guest_sdma (target guest_sdma_tests) passed, 1 of 1. python3 tools/check_conventions.py --base upstream/main and git diff --check are clean. The new cases were not run against the unfixed code; that they fail without the fixes is reasoned from the code (a null dereference, and a throw on the closed handle). Not run on Windows or macOS.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5186259332 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16342). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-06T10:12:14Z. --- ### What `libSceSdma` dereferenced its handle without checking it, and a command submitted on a closed handle ended in a `NotImplemented` throw because a closed slot has a zero-sized ring. - `fix(libSceSdma): return an invalid-argument error for a null handle`: `sceSdmaClose`, `BeginQueueMode`, `CancelQueue`, `EndQueueMode`, `FenceNonBlocking`, `FlushAll`, `KickQueue`, `TryFlush` and the shared `Submit` used by the copy and fill commands now return `SdmaErrorInvalidArgument` for a null handle instead of dereferencing it. - `fix(libSceSdma): reject submissions on a closed handle`: `Submit` returns the same error when the slot is not open, so a blocking or non-blocking command on a closed handle no longer reaches the ring checks. - One `test` commit after each fix in `GuestSdma.cpp` (`RequireNullHandle` calls every handle entry point with a null handle; `RequireClosedHandle` closes a handle and checks that fill and copy commands are rejected and the destination stays zero). - `docs(debt): record the unmeasured error code for null and closed handles`: the code is `0x80990005`, the one `sceSdmaOpen` already uses for bad arguments; no invalid-handle code is documented for this library and the console value for these cases is not measured. ### Tested Linux, throwaway archive build of this head: `BUILD-EXIT 0`, ctest `guest_sdma` (target `guest_sdma_tests`) passed, 1 of 1. `python3 tools/check_conventions.py --base upstream/main` and `git diff --check` are clean. The new cases were not run against the unfixed code; that they fail without the fixes is reasoned from the code (a null dereference, and a throw on the closed handle). Not run on Windows or macOS. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
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!16342
No description provided.