fix(libSceAjm.native): refuse a nonzero reserved in sceAjmInitialize #15906

Merged
zaryabzip merged 2 commits from upstream-pr/15906 into main 2026-11-08 01:23:32 +00:00
zaryabzip commented 2026-11-04 22:54:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-11-04T22:54:23Z.


What

sceAjmInitialize now refuses a nonzero reserved with INVALID_PARAMETER (0x80930005) and writes no context, as obSCEne's census measured. It ran in its own title (PPSA90000) on a PS5 with system software 12.40. main ignored reserved and handed out a context.

Call Console main
reserved = a stack address, context = a valid pointer 0x80930005, output unchanged 0, writes a context
both 0 (null output) 0x80930005 0x80930005

The same results came back in that log's sibling runs, report-20261013-184500.log and report-20261014-004800.log. This is the sceAjmInitialize counterpart of @BunnyFl's #15491, which refuses a nonzero reserved in sceAjmModuleRegister. A new debt entry records the measurement.

Test. TestBatchContextOwnership now first calls sceAjmInitialize with a stack address as reserved, as the probe did. It expects 0x80930005 and checks that its 0xdeadbeef output is unchanged. On main the test fails there.

Overlap: git merge-tree merges this cleanly with main and with every open PR that touches these three files and merges with main. Those are #12613, #14226 and #15846 (mine), #15491 (BunnyFl) and #14078. #14212 already conflicts with main.

Tested

  • WSL2 and Windows, by me at 3a1d204d60 (comment):
    • WSL2: Ubuntu 24.04.5, GCC 13.3.0, Release, merged onto main 1e24993fa3. ctest -R "guest_ajm" passes all 5 tests.
    • Windows: Windows 11 Home 25H2, WinLibs GCC 15.2.0 r7, Release, the same merge. All 4 tests pass (guest_ajm_teardown is Linux-only).
    • --repeat until-fail:3 passes every round on both.
    • With Ajm.cpp from main, guest_ajm aborts on both: sceAjmInitialize(<stack address>, &refused) returns 0 and writes 2.

Checked so far, on macOS (arm64, where no full build is possible):

  • GuestAjm.cpp and the changed lines of Ajm.cpp pass an x86-64 clang++ -fsyntax-only.
  • tools/check_conventions.py --base main passes.

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 (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5162937296 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15906). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-11-04T22:54:23Z. --- ### What `sceAjmInitialize` now refuses a nonzero `reserved` with `INVALID_PARAMETER` (0x80930005) and writes no context, as [obSCEne's census](https://github.com/project-oops/obSCEne/blob/de5efc406319ade18df00654025494804405a7fb/reports/hardware/report-20261013-172400.log#L26104-L26116) measured. It ran in its own title (PPSA90000) on a PS5 with system software 12.40. `main` ignored `reserved` and handed out a context. | Call | Console | `main` | |---|---|---| | `reserved` = a stack address, `context` = a valid pointer | `0x80930005`, output unchanged | 0, writes a context | | both 0 (null output) | `0x80930005` | `0x80930005` | The same results came back in that log's sibling runs, `report-20261013-184500.log` and `report-20261014-004800.log`. This is the `sceAjmInitialize` counterpart of @BunnyFl's #15491, which refuses a nonzero `reserved` in `sceAjmModuleRegister`. A new debt entry records the measurement. **Test.** `TestBatchContextOwnership` now first calls `sceAjmInitialize` with a stack address as `reserved`, as the probe did. It expects `0x80930005` and checks that its `0xdeadbeef` output is unchanged. On `main` the test fails there. Overlap: `git merge-tree` merges this cleanly with `main` and with every open PR that touches these three files and merges with `main`. Those are #12613, #14226 and #15846 (mine), #15491 (BunnyFl) and #14078. #14212 already conflicts with `main`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> - **WSL2 and Windows, by me** at `3a1d204d60` ([comment](https://github.com/boykopovar/AnyPS5/pull/15906#issuecomment-6653523535)): - WSL2: Ubuntu 24.04.5, GCC 13.3.0, Release, merged onto `main` `1e24993fa3`. `ctest -R "guest_ajm"` passes all 5 tests. - Windows: Windows 11 Home 25H2, WinLibs GCC 15.2.0 r7, Release, the same merge. All 4 tests pass (`guest_ajm_teardown` is Linux-only). - `--repeat until-fail:3` passes every round on both. - With `Ajm.cpp` from `main`, `guest_ajm` aborts on both: `sceAjmInitialize(<stack address>, &refused)` returns 0 and writes 2. Checked so far, on macOS (arm64, where no full build is possible): - `GuestAjm.cpp` and the changed lines of `Ajm.cpp` pass an x86-64 `clang++ -fsyntax-only`. - `tools/check_conventions.py --base main` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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: <!-- #PR, or none --> none - [x] Fixes: <!-- issue it closes as Fixes #N, or none --> none - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> none - [x] GPUs tested: <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> n/a - [x] AI-assisted: <!-- yes / no --> yes (Claude Code)
BunnyFl commented 2026-11-05 15:58:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-05T15:58:07Z.

Review: APPROVED


@zaryabzip looks right. I read the census lines you cite (report-20261013-172400.log, lines 26104-26116): call-buffers, with every argument a buffer address, returns 0x80930005 and changes no argument, and call-zeros returns the same.

Firmware 13.42, for comparison

Disassembly only, not measured on a console.

system/common/lib/libSceAjm.native.sprx (SHA-256 8eea270172e7ea177e69fa7865493b72131670f87afa91798d7d749ac183d5c0), sceAjmInitialize at 0xd0, read to its return:

f6:  test %rsi,%rsi               ; a null context
f9:  je   0x144                   ;   returns 0x80930005, nothing written
106: call 0x88a0                  ; opens the AJM device
113: mov  $0xc02889c8,%esi        ; ioctl request; reserved (saved from rdi) is in the argument block at -0x48
126: call 0x88b0
133: test %r15d,%r15d
136: js   0x1bc                   ; a negative kernel result skips the store and closes the device
13c: mov  %r12d,(%r14)            ; *context, only on success

So the module checks only the null output itself and passes reserved to the kernel driver; what the driver answers for a nonzero one isn't visible here, which is what your console measurement settles. Either way the output is written only on success, as your test checks.

Non-blocking, in case it matters later: system/common/lib/libSceAjm.sprx (SHA-256 a65a690c00ec74f107e2fbde3ee782206d994bfdeb108f924e2c8abeddc861e3) has its own sceAjmInitialize at 0xd0 that writes 0xffffffff to the output before refusing a nonzero reserved:

da:  movl $0xffffffff,(%rsi)
e0:  test %rdi,%rdi
e3:  je   0xe6                    ; reserved 0 goes on to open the device; otherwise return 0x80930005

The census saw the output unchanged, which fits the native module, the one this PR changes.

What I ran

Head 3a1d204d60 merged onto main 78e4248fea (clean merge), Windows 11, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON:

  • guest_ajm, guest_ajm_aac_multichannel, guest_ajm_vibration and guest_ajm_wvorbis pass, 4 of 4;
  • with main's core/libs/prx/libSceAjm.native/src/Ajm.cpp, guest_ajm aborts and the other three pass;
  • check_conventions.py passes; pr_overlap.py --branch finds no PR sharing lines or exports among those it could compare (2 conflict with main).

Approving.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5787935869 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15906#pullrequestreview-5787935869). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-05T15:58:07Z. **Review:** APPROVED --- @zaryabzip looks right. I read the census lines you cite (`report-20261013-172400.log`, lines 26104-26116): `call-buffers`, with every argument a buffer address, returns `0x80930005` and changes no argument, and `call-zeros` returns the same. ## Firmware 13.42, for comparison Disassembly only, not measured on a console. `system/common/lib/libSceAjm.native.sprx` (SHA-256 `8eea270172e7ea177e69fa7865493b72131670f87afa91798d7d749ac183d5c0`), `sceAjmInitialize` at `0xd0`, read to its return: ``` f6: test %rsi,%rsi ; a null context f9: je 0x144 ; returns 0x80930005, nothing written 106: call 0x88a0 ; opens the AJM device 113: mov $0xc02889c8,%esi ; ioctl request; reserved (saved from rdi) is in the argument block at -0x48 126: call 0x88b0 133: test %r15d,%r15d 136: js 0x1bc ; a negative kernel result skips the store and closes the device 13c: mov %r12d,(%r14) ; *context, only on success ``` So the module checks only the null output itself and passes `reserved` to the kernel driver; what the driver answers for a nonzero one isn't visible here, which is what your console measurement settles. Either way the output is written only on success, as your test checks. Non-blocking, in case it matters later: `system/common/lib/libSceAjm.sprx` (SHA-256 `a65a690c00ec74f107e2fbde3ee782206d994bfdeb108f924e2c8abeddc861e3`) has its own `sceAjmInitialize` at `0xd0` that writes `0xffffffff` to the output before refusing a nonzero `reserved`: ``` da: movl $0xffffffff,(%rsi) e0: test %rdi,%rdi e3: je 0xe6 ; reserved 0 goes on to open the device; otherwise return 0x80930005 ``` The census saw the output unchanged, which fits the native module, the one this PR changes. ## What I ran Head `3a1d204d60` merged onto `main` `78e4248fea` (clean merge), Windows 11, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`: - `guest_ajm`, `guest_ajm_aac_multichannel`, `guest_ajm_vibration` and `guest_ajm_wvorbis` pass, 4 of 4; - with `main`'s `core/libs/prx/libSceAjm.native/src/Ajm.cpp`, `guest_ajm` aborts and the other three pass; - `check_conventions.py` passes; `pr_overlap.py --branch` finds no PR sharing lines or exports among those it could compare (2 conflict with `main`). Approving. AI-assisted: yes (Claude Code)
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!15906
No description provided.