feat(libSceAcm): validate context and batch parameters in batch wait and lifecycle exports #7567

Merged
pushkarreddyy merged 1 commit from upstream-pr/7567 into main 2026-10-20 01:30:46 +00:00
pushkarreddyy commented 2026-10-18 14:30:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-18T14:30:56Z.


What

Validates context handles and pointers in libSceAcm exports (sceAcmContextCreate, sceAcmContextDestroy, sceAcmBatchStartBuffer, sceAcmBatchStartBuffers, sceAcmBatchWait):

  • Tracks created context IDs; start/wait/destroy on a zero or unknown context return 0x81940002, null out-pointers return 0x81940006 (codes from prosper's hle_audio_spatial.cpp).
  • sceAcmBatchWait succeeds for any valid context without inspecting batch IDs (KytyPS5 and prosper do not track batches).
  • Clears batch_error when provided.
  • Removes legacy inline comments from Export.cpp.
  • Tests cover nominal lifecycle, double destroy, invalid contexts and null pointers.

Tested

guest_acm_tests in core/libs/tests/GuestAcm.cpp testing context creation/destruction, parameter validation, double-destruction handling, batch wait tracking, and negative paths. Validated conventions with python tools/check_conventions.py --base origin/main.

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: PPSA06147 #7020
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4909917445 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7567). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-18T14:30:56Z. --- ### What Validates context handles and pointers in libSceAcm exports (sceAcmContextCreate, sceAcmContextDestroy, sceAcmBatchStartBuffer, sceAcmBatchStartBuffers, sceAcmBatchWait): - Tracks created context IDs; start/wait/destroy on a zero or unknown context return 0x81940002, null out-pointers return 0x81940006 (codes from prosper's `hle_audio_spatial.cpp`). - `sceAcmBatchWait` succeeds for any valid context without inspecting batch IDs (KytyPS5 and prosper do not track batches). - Clears `batch_error` when provided. - Removes legacy inline comments from Export.cpp. - Tests cover nominal lifecycle, double destroy, invalid contexts and null pointers. ### Tested guest_acm_tests in core/libs/tests/GuestAcm.cpp testing context creation/destruction, parameter validation, double-destruction handling, batch wait tracking, and negative paths. Validated conventions with python tools/check_conventions.py --base origin/main. ### 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: PPSA06147 #7020 - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-18 14:59:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T14:59:06Z.


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
PR 7064 docs/dev/debt/libSceAcm.md L5-10

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 6044 core/libs/tests/GuestAcm.cpp
PR 8106 core/libs/prx/libSceAcm/Export.cpp
docs/dev/debt/libSceAcm.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251386099 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7567#issuecomment-6251386099). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T14:59:06Z. --- <!-- 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 | |---|---|---|---| | [PR 7064](https://www.github.com/boykopovar/AnyPS5/pull/7064) | `docs/dev/debt/libSceAcm.md` [L5-10](https://github.com/boykopovar/AnyPS5/blob/3aa4448ed3a02eb960abe7a99971e0f5d599ecb2/docs/dev/debt/libSceAcm.md#L5-L10) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestAcm.cpp` | | [PR 8106](https://www.github.com/boykopovar/AnyPS5/pull/8106) | `core/libs/prx/libSceAcm/Export.cpp`<br>`docs/dev/debt/libSceAcm.md` |
xXPBSXx commented 2026-10-19 08:13:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-19T08:13:36Z.


Windows data point for a6406334a merged onto main fb0dc118f (together with #7388 in one tree, a8bdd9935; the two PRs touch different files): Windows 10 (10.0.19045), WinLibs GCC 15.2.0, Release, ctest -R '^guest_acm$'.

  • With the PR: passes 3 of 3.
  • Same tree with core/libs/prx/libSceAcm/Export.cpp restored to main (git checkout upstream/main -- core/libs/prx/libSceAcm/Export.cpp; git status shows only that file staged, 17 insertions / 55 deletions; the new GuestAcm.cpp test kept): fails 3 of 3, guest_acm (Exit code 0xc0000409) (the test's abort path).

Not tested: a title run, Linux, guest_acm on any other tree.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6262747081 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7567#issuecomment-6262747081). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-19T08:13:36Z. --- Windows data point for `a6406334a` merged onto `main` `fb0dc118f` (together with #7388 in one tree, `a8bdd9935`; the two PRs touch different files): Windows 10 (10.0.19045), WinLibs GCC 15.2.0, Release, `ctest -R '^guest_acm$'`. - With the PR: passes 3 of 3. - Same tree with `core/libs/prx/libSceAcm/Export.cpp` restored to `main` (`git checkout upstream/main -- core/libs/prx/libSceAcm/Export.cpp`; `git status` shows only that file staged, 17 insertions / 55 deletions; the new `GuestAcm.cpp` test kept): fails 3 of 3, `guest_acm (Exit code 0xc0000409)` (the test's abort path). Not tested: a title run, Linux, `guest_acm` on any other tree. AI-assisted (Claude Code).
pushkarreddyy commented 2026-10-19 14:02:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-19T14:02:23Z.


@xXPBSXx Thank you for testing and sharing the Windows GCC 15.2 data point! Glad to hear ctest -R '^guest_acm$' cleanly verifies the validation behavior (3/3 pass vs abort without the PR).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6269069429 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7567#issuecomment-6269069429). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-19T14:02:23Z. --- @xXPBSXx Thank you for testing and sharing the Windows GCC 15.2 data point! Glad to hear `ctest -R '^guest_acm$'` cleanly verifies the validation behavior (3/3 pass vs abort without the PR).
adriadam10 commented 2026-10-19 16:29:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T16:29:53Z.

Review: CHANGES_REQUESTED


Checked against the references; a few points before this can merge:

  • sceAcmBatchWait rejecting an unknown or already-waited batch (Export.cpp:57-67) has no source. KytyPS5 acm.cpp returns OK unconditionally for wait and destroy, and prosper (module-derived offsets) has no batch tracking either. A title that waits twice or on an id from another path would now get an error where main succeeds. Please cite where this behaviour comes from, or limit the change to what is sourced.
  • Error code: for an unknown context prosper's hle_audio_spatial.cpp returns 0x81940002 (BAD_CONTEXT, with 0x81940006 for null pointers), not 0x80E30002. Please say which one is right and where it comes from, and put the unverified part under "Unknown function info" in docs/dev/debt/libSceAcm.md.
  • The "Unblocks: PPSA06147 #7020" claim cannot be checked (#7020 is not readable). Please link the evidence that this title needs the validation.
  • docs/dev/debt/libSceAcm.md:5 overlaps with #7064 (same line); that one merges first or this needs rebasing on it.
  • The test only pins this PR's own choices (error != 0); nothing ties them to a reference value.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5574603644 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7567#pullrequestreview-5574603644). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T16:29:53Z. **Review:** CHANGES_REQUESTED --- Checked against the references; a few points before this can merge: - `sceAcmBatchWait` rejecting an unknown or already-waited batch (`Export.cpp:57-67`) has no source. KytyPS5 `acm.cpp` returns OK unconditionally for wait and destroy, and prosper (module-derived offsets) has no batch tracking either. A title that waits twice or on an id from another path would now get an error where `main` succeeds. Please cite where this behaviour comes from, or limit the change to what is sourced. - Error code: for an unknown context prosper's `hle_audio_spatial.cpp` returns `0x81940002` (BAD_CONTEXT, with `0x81940006` for null pointers), not `0x80E30002`. Please say which one is right and where it comes from, and put the unverified part under "Unknown function info" in `docs/dev/debt/libSceAcm.md`. - The "Unblocks: PPSA06147 #7020" claim cannot be checked (#7020 is not readable). Please link the evidence that this title needs the validation. - `docs/dev/debt/libSceAcm.md:5` overlaps with #7064 (same line); that one merges first or this needs rebasing on it. - The test only pins this PR's own choices (error != 0); nothing ties them to a reference value.
pushkarreddyy commented 2026-10-19 17:15:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-19T17:15:48Z.


@adriadam10 Thanks for the review and references!

Pushed commit 77cfd9eab addressing all feedback:

  1. Batch Wait Behavior & Error Codes:

    • Replaced custom batch rejection with the reference behavior from KytyPS5 (acm.cpp) and prosper: sceAcmBatchWait succeeds for any valid context without rejecting untracked or previously waited batch IDs.
    • Adopted the exact reference error codes from prosper's hle_audio_spatial.cpp: 0x81940002 (SCE_ACM_ERROR_BAD_CONTEXT) for invalid/unknown contexts and 0x81940006 (SCE_ACM_ERROR_BAD_POINTER) for null pointer arguments.
    • Updated core/libs/tests/GuestAcm.cpp assertions to verify these exact return values (BadContext and BadPointer).
  2. Technical Debt & Overlap:

    • Rebased cleanly onto latest origin/main (00d7e611e).
    • Documented the reference sources (prosper hle_audio_spatial.cpp, KytyPS5 acm.cpp) and unmeasured hardware DSP scheduling under Unknown function info in docs/dev/debt/libSceAcm.md.
  3. Checklist Update:

    • Updated checklist to Unblocks: none to avoid citing unverified title discussions.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6272930190 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7567#issuecomment-6272930190). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-19T17:15:48Z. --- @adriadam10 Thanks for the review and references! Pushed commit `77cfd9eab` addressing all feedback: 1. **Batch Wait Behavior & Error Codes**: - Replaced custom batch rejection with the reference behavior from KytyPS5 (`acm.cpp`) and prosper: `sceAcmBatchWait` succeeds for any valid context without rejecting untracked or previously waited batch IDs. - Adopted the exact reference error codes from prosper's `hle_audio_spatial.cpp`: `0x81940002` (`SCE_ACM_ERROR_BAD_CONTEXT`) for invalid/unknown contexts and `0x81940006` (`SCE_ACM_ERROR_BAD_POINTER`) for null pointer arguments. - Updated `core/libs/tests/GuestAcm.cpp` assertions to verify these exact return values (`BadContext` and `BadPointer`). 2. **Technical Debt & Overlap**: - Rebased cleanly onto latest `origin/main` (`00d7e611e`). - Documented the reference sources (prosper `hle_audio_spatial.cpp`, KytyPS5 `acm.cpp`) and unmeasured hardware DSP scheduling under `Unknown function info` in `docs/dev/debt/libSceAcm.md`. 3. **Checklist Update**: - Updated checklist to `Unblocks: none` to avoid citing unverified title discussions.
adriadam10 commented 2026-10-19 17:17:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T17:17:08Z.

Review: CHANGES_REQUESTED


Thanks, the earlier points are addressed (wait no longer rejects batches, error codes from prosper, debt entry). One thing left:

  • ContextRecord::batches (Export.cpp:16-18, inserted at :38 and :54) is never read or erased any more now that sceAcmBatchWait doesn't track batches, so every sceAcmBatchStartBuffer(s) call grows it until the context is destroyed. Nothing bounds it. Either drop the set (a context only needs to exist in g_contexts) or keep it with a bound and a reason to read it.
  • Nit: the new line in docs/dev/debt/libSceAcm.md:9 is missing its final period.
  • This still touches the same three files as #7064; whichever merges second needs a rebase (currently no conflict).
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5575140669 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7567#pullrequestreview-5575140669). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T17:17:08Z. **Review:** CHANGES_REQUESTED --- Thanks, the earlier points are addressed (wait no longer rejects batches, error codes from prosper, debt entry). One thing left: - `ContextRecord::batches` (`Export.cpp:16-18`, inserted at `:38` and `:54`) is never read or erased any more now that `sceAcmBatchWait` doesn't track batches, so every `sceAcmBatchStartBuffer(s)` call grows it until the context is destroyed. Nothing bounds it. Either drop the set (a context only needs to exist in `g_contexts`) or keep it with a bound and a reason to read it. - Nit: the new line in `docs/dev/debt/libSceAcm.md:9` is missing its final period. - This still touches the same three files as #7064; whichever merges second needs a rebase (currently no conflict).
pushkarreddyy commented 2026-10-19 17:23:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-19T17:23:40Z.


@adriadam10 Thanks! Pushed commit 53617c5a6 addressing both points: dropped the atches set completely so g_contexts is a flat std::unordered_set with no per-batch allocations, and added the missing final period to line 9 of docs/dev/debt/libSceAcm.md.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273077763 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7567#issuecomment-6273077763). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-10-19T17:23:40Z. --- @adriadam10 Thanks! Pushed commit 53617c5a6 addressing both points: dropped the atches set completely so g_contexts is a flat std::unordered_set<AcmContextId> with no per-batch allocations, and added the missing final period to line 9 of docs/dev/debt/libSceAcm.md.
adriadam10 commented 2026-10-20 01:33:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T01:33:11Z.


Both earlier points are addressed (batches set dropped, debt line ends with a period). Also updated the PR description, which still described batch rejection and the old error code. Checked: codes against prosper, test fails without the change, Windows data point from @xXPBSXx; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6281233539 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7567#issuecomment-6281233539). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-20T01:33:11Z. --- Both earlier points are addressed (`batches` set dropped, debt line ends with a period). Also updated the PR description, which still described batch rejection and the old error code. Checked: codes against prosper, test fails without the change, Windows data point from @xXPBSXx; merged.
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!7567
No description provided.