fix(libSceAjm.native): stop checking sceAjmInitialize's reserved #16974

Merged
zaryabzip merged 5 commits from upstream-pr/16974 into main 2026-11-09 18:21:08 +00:00
zaryabzip commented 2026-11-08 03:15:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by zaryabzip on 2026-11-08T03:15:28Z.


What

This fixes a regression from #15906. sceAjmInitialize no longer checks reserved, as before #15906; only a null output returns 0x80930005. #15906 refused any nonzero value, and retail titles that pass one stopped working.

Titles that pass a nonzero reserved, all of which work on a console:

  • 0x300000000, loaded as a 64-bit immediate right before the call, in five titles: LEGO Batman: Legacy of the Dark Knight (PPSA16833), Planet Zoo (PPSA18026), Ghost of Tsushima (PPSA02225), Death Stranding 2 (PPSA02015, #17659) and Cyberpunk 2077 (PPSA03974). With #15906 they fault during start-up. Tamalero found the immediate and bisected the first one (comment).
  • 0x20, from Hades II (PPSA36082)'s bundled FMOD (kiansaeidnia's report). It masks a global to 7 bits and passes it. With #15906, FMOD gets 0x80930005, loads no sound banks and the game shows "Audio disabled".

Why ignore it rather than check part of it. An earlier version of this PR compared only the low 32 bits. That fixed the 0x300000000 titles but still refused Hades II's 0x20. The three known results don't fit any rule the sources support:

reserved Source Console
a stack address obSCEne's census refused, 0x80930005
0x300000000 five retail titles accepted
0x20 PPSA36082's FMOD accepted

BunnyFl's 13.42 read shows the native module passes all 64 bits to the AJM driver without checking them, and the driver's own check hasn't been read. So the safe choice is the one that refuses no value a retail title passes. The census case is recorded as a known difference in the debt entry.

Test. GuestAjm.cpp (ctest guest_ajm) checks that sceAjmInitialize returns 0 and writes distinct contexts for 0x20 and 0x300000000, and finalizes each. The row that pinned the stack-address refusal is removed. The two invalid-context rows use highHalf + 1, since each extra context takes the next ID.

Overlap. The overlap bot couldn't compare #14212 (janzezno's blank-line reformat of the debt files), because it already conflicts with main. I checked it with git merge-tree. Its conflict hunks in libSceAjm.native.md are the same two with this PR as with main. The sceAjmInitialize line is already inside one of them, so this PR adds no new conflict.

Tested

  • Windows and WSL2, by me at a3ae88f573 (tree 3cb23d653f), on main 3aa0ac20df (comment):
    • Windows 11 Home 25H2, WinLibs GCC 15.2.0 r7, Release: ctest -R guest_ajm passes 5 of 5 in each of 3 runs.
    • WSL2, Ubuntu 24.04.5, GCC 13.3.0, Release: 6 of 6 in each of 3 runs.
    • With main's Ajm.cpp, guest_ajm aborts on both at the new sceAjmInitialize(0x300000000, &highHalf) row (GuestAjm.cpp:1021).
    • No warnings in Ajm.cpp or GuestAjm.cpp.
    • The first head, 242942dcbb, aborted at GuestAjm.cpp:1035: the new row allocated the context the test had used as the unallocated one. a3ae88f573 fixes this.
  • Windows, by JJenkx at a3ae88f573 merged onto main e6108f3d8e, a clean merge (comment). Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release: guest_ajm passes 3 of 3, none skipped.
  • PPSA16833 01.010.000, by Tamalero at a3ae88f573 merged onto main 57aaadb561, with no revert and no local changes (comment). On Linux, the title runs the full 300 s with APS5_NET_DISCONNECTED=1, 3,782 frames and no error. main alone segfaults 5–10 s in.
  • PPSA18026 01.009.002 (Planet Zoo), by adam25136 at 784752f2bc merged onto main 522df1e176, a clean merge (comment). Windows 10 Pro 22H2, RTX 5080 (driver 621.14), WinLibs GCC 15.2.0 r7, Release:
    • main faults during start-up, writing to 0xa4 on the Render thread.
    • With this PR, it gets past start-up and opens its logo movie, and was still running when the 41 s run ended.
    • Its eboot.elf loads movabs $0x300000000,%rdi before the call too, at va 0x14d97e.
    • A separate 12-step bisect also found #15906 as the first bad merge.
  • PPSA02225 02.024.000 (Ghost of Tsushima), by milescoviello at 784752f2bc merged onto main 0bae53facd, a clean merge (comment). Ubuntu 26.04.1, RTX 4070 Ti, GCC 15.2, Release:
    • The title passes reserved = 0x300000000 as a 64-bit immediate too.
    • main segfaults after 3 s. With this PR it runs 106 s, to a later GPU stop that has nothing to do with AJM.
    • A bisect also found #15906 as the first bad commit.
  • Windows and WSL2 rerun, by me at 2516536621 (tree 486cb5d33c), on main 3aa0ac20df, after the sceAjmFinalize(highHalf) row was added (comment):
    • ctest -R guest_ajm, run once, Release, on the same toolchains as above: 5 of 5 pass on Windows and 6 of 6 on WSL2.
    • No warnings in Ajm.cpp or GuestAjm.cpp.
  • Linux, by juanpimg, this PR merged onto main d792f1ad5f, a clean merge (comment): all 6 guest_ajm* tests pass. With reserved != 0 restored and the new test kept, guest_ajm aborts.
  • PPSA03974 (Cyberpunk 2077), by klosixgaming-arch, this PR merged onto main d34caa9dbe (comment): the title boots to its title screen again. main crashes in libkernel about 5 s in.
  • Note: the runs above were on the low-32-bit version (up to 2516536621). 4f1bc06940 ignores reserved entirely; its rerun is below.
  • Windows and WSL2 rerun, by me at 4f1bc06940 (tree 85c1d308b6), on main 3aa0ac20df, after reserved stopped being checked (comment):
    • ctest -R guest_ajm, run once, Release, on the same toolchains as above: 5 of 5 pass on Windows and 6 of 6 on WSL2.
    • Control (Windows): with 2516536621's Ajm.cpp (the low-32-bit check), guest_ajm aborts at the new sceAjmInitialize(0x20, &lowValue) row (GuestAjm.cpp:1019).
    • No warnings in Ajm.cpp or GuestAjm.cpp.

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

  • The head 2516536621 differs from a3ae88f573 only in the debt entry's wording (784752f2bc) and one sceAjmFinalize(highHalf) test line, which the rerun above covers.
  • GuestAjm.cpp passes an x86-64 clang++ -fsyntax-only. Ajm.cpp needs the ATRAC9 headers, so it wasn't checked here. The change there is one cast.
  • tools/check_conventions.py --base main passes.
  • The overlap sweep found no conflicts with main 3aa0ac20df or with any open PR that merges with it.

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: Fixes #17659
  • Unblocks: PPSA16833, PPSA18026 #11608, PPSA02225, PPSA02015 #17659, PPSA03974 and PPSA36082 audio (regressions from #15906)
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5208206539 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16974). Originally posted by [zaryabzip](https://github.com/zaryabzip) on 2026-11-08T03:15:28Z. --- ### What This fixes a regression from #15906. `sceAjmInitialize` no longer checks `reserved`, as before #15906; only a null output returns `0x80930005`. #15906 refused any nonzero value, and retail titles that pass one stopped working. **Titles that pass a nonzero `reserved`, all of which work on a console:** - `0x300000000`, loaded as a 64-bit immediate right before the call, in five titles: LEGO Batman: Legacy of the Dark Knight (PPSA16833), Planet Zoo (PPSA18026), Ghost of Tsushima (PPSA02225), Death Stranding 2 (PPSA02015, #17659) and Cyberpunk 2077 (PPSA03974). With #15906 they fault during start-up. Tamalero found the immediate and bisected the first one ([comment](https://github.com/boykopovar/AnyPS5/pull/15906#issuecomment-6718254821)). - `0x20`, from Hades II (PPSA36082)'s bundled FMOD ([kiansaeidnia's report](https://github.com/boykopovar/AnyPS5/pull/15906#issuecomment-6745863413)). It masks a global to 7 bits and passes it. With #15906, FMOD gets `0x80930005`, loads no sound banks and the game shows "Audio disabled". **Why ignore it rather than check part of it.** An earlier version of this PR compared only the low 32 bits. That fixed the `0x300000000` titles but still refused Hades II's `0x20`. The three known results don't fit any rule the sources support: | `reserved` | Source | Console | |---|---|---| | a stack address | [obSCEne's census](https://github.com/project-oops/obSCEne/blob/de5efc406319ade18df00654025494804405a7fb/reports/hardware/report-20261013-172400.log#L26104-L26116) | refused, `0x80930005` | | `0x300000000` | five retail titles | accepted | | `0x20` | PPSA36082's FMOD | accepted | [BunnyFl's 13.42 read](https://github.com/boykopovar/AnyPS5/pull/15906#issuecomment-6716556835) shows the native module passes all 64 bits to the AJM driver without checking them, and the driver's own check hasn't been read. So the safe choice is the one that refuses no value a retail title passes. The census case is recorded as a known difference in the debt entry. **Test.** `GuestAjm.cpp` (ctest `guest_ajm`) checks that `sceAjmInitialize` returns 0 and writes distinct contexts for `0x20` and `0x300000000`, and finalizes each. The row that pinned the stack-address refusal is removed. The two invalid-context rows use `highHalf + 1`, since each extra context takes the next ID. **Overlap.** The overlap bot couldn't compare #14212 (janzezno's blank-line reformat of the debt files), because it already conflicts with `main`. I checked it with `git merge-tree`. Its conflict hunks in `libSceAjm.native.md` are the same two with this PR as with `main`. The `sceAjmInitialize` line is already inside one of them, so this PR adds no new conflict. ### Tested - **Windows and WSL2, by me** at `a3ae88f573` (tree `3cb23d653f`), on `main` `3aa0ac20df` ([comment](https://github.com/boykopovar/AnyPS5/pull/16974#issuecomment-6716698775)): - Windows 11 Home 25H2, WinLibs GCC 15.2.0 r7, Release: `ctest -R guest_ajm` passes 5 of 5 in each of 3 runs. - WSL2, Ubuntu 24.04.5, GCC 13.3.0, Release: 6 of 6 in each of 3 runs. - With `main`'s `Ajm.cpp`, `guest_ajm` aborts on both at the new `sceAjmInitialize(0x300000000, &highHalf)` row (`GuestAjm.cpp:1021`). - No warnings in `Ajm.cpp` or `GuestAjm.cpp`. - The first head, `242942dcbb`, aborted at `GuestAjm.cpp:1035`: the new row allocated the context the test had used as the unallocated one. `a3ae88f573` fixes this. - **Windows, by JJenkx** at `a3ae88f573` merged onto `main` `e6108f3d8e`, a clean merge ([comment](https://github.com/boykopovar/AnyPS5/pull/16974#issuecomment-6717979495)). Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release: `guest_ajm` passes 3 of 3, none skipped. - **PPSA16833 01.010.000, by Tamalero** at `a3ae88f573` merged onto `main` `57aaadb561`, with no revert and no local changes ([comment](https://github.com/boykopovar/AnyPS5/pull/15906#issuecomment-6718254821)). On Linux, the title runs the full 300 s with `APS5_NET_DISCONNECTED=1`, 3,782 frames and no error. `main` alone segfaults 5–10 s in. - **PPSA18026 01.009.002 (Planet Zoo), by adam25136** at `784752f2bc` merged onto `main` `522df1e176`, a clean merge ([comment](https://github.com/boykopovar/AnyPS5/pull/16974#issuecomment-6722226252)). Windows 10 Pro 22H2, RTX 5080 (driver 621.14), WinLibs GCC 15.2.0 r7, Release: - `main` faults during start-up, writing to `0xa4` on the `Render` thread. - With this PR, it gets past start-up and opens its logo movie, and was still running when the 41 s run ended. - Its `eboot.elf` loads `movabs $0x300000000,%rdi` before the call too, at va `0x14d97e`. - A separate 12-step bisect also found #15906 as the first bad merge. - **PPSA02225 02.024.000 (Ghost of Tsushima), by milescoviello** at `784752f2bc` merged onto `main` `0bae53facd`, a clean merge ([comment](https://github.com/boykopovar/AnyPS5/pull/16974#issuecomment-6727729638)). Ubuntu 26.04.1, RTX 4070 Ti, GCC 15.2, Release: - The title passes `reserved = 0x300000000` as a 64-bit immediate too. - `main` segfaults after 3 s. With this PR it runs 106 s, to a later GPU stop that has nothing to do with AJM. - A bisect also found #15906 as the first bad commit. - **Windows and WSL2 rerun, by me** at `2516536621` (tree `486cb5d33c`), on `main` `3aa0ac20df`, after the `sceAjmFinalize(highHalf)` row was added ([comment](https://github.com/boykopovar/AnyPS5/pull/16974#issuecomment-6735139327)): - `ctest -R guest_ajm`, run once, Release, on the same toolchains as above: 5 of 5 pass on Windows and 6 of 6 on WSL2. - No warnings in `Ajm.cpp` or `GuestAjm.cpp`. - **Linux, by juanpimg**, this PR merged onto `main` `d792f1ad5f`, a clean merge ([comment](https://github.com/boykopovar/AnyPS5/pull/16974#issuecomment-6744707036)): all 6 `guest_ajm*` tests pass. With `reserved != 0` restored and the new test kept, `guest_ajm` aborts. - **PPSA03974 (Cyberpunk 2077), by klosixgaming-arch**, this PR merged onto `main` `d34caa9dbe` ([comment](https://github.com/boykopovar/AnyPS5/pull/15906#issuecomment-6744800708)): the title boots to its title screen again. `main` crashes in libkernel about 5 s in. - **Note:** the runs above were on the low-32-bit version (up to `2516536621`). `4f1bc06940` ignores `reserved` entirely; its rerun is below. - **Windows and WSL2 rerun, by me** at `4f1bc06940` (tree `85c1d308b6`), on `main` `3aa0ac20df`, after `reserved` stopped being checked ([comment](https://github.com/boykopovar/AnyPS5/pull/16974#issuecomment-6746233042)): - `ctest -R guest_ajm`, run once, Release, on the same toolchains as above: 5 of 5 pass on Windows and 6 of 6 on WSL2. - Control (Windows): with `2516536621`'s `Ajm.cpp` (the low-32-bit check), `guest_ajm` aborts at the new `sceAjmInitialize(0x20, &lowValue)` row (`GuestAjm.cpp:1019`). - No warnings in `Ajm.cpp` or `GuestAjm.cpp`. Checked so far, on macOS (arm64, where no full build is possible): - The head `2516536621` differs from `a3ae88f573` only in the debt entry's wording (`784752f2bc`) and one `sceAjmFinalize(highHalf)` test line, which the rerun above covers. - `GuestAjm.cpp` passes an x86-64 `clang++ -fsyntax-only`. `Ajm.cpp` needs the ATRAC9 headers, so it wasn't checked here. The change there is one cast. - `tools/check_conventions.py --base main` passes. - The overlap sweep found no conflicts with `main` `3aa0ac20df` or with any open PR that merges with it. ### 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 --> Fixes #17659 - [x] Unblocks: <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> PPSA16833, PPSA18026 #11608, PPSA02225, PPSA02015 #17659, PPSA03974 and PPSA36082 audio (regressions from #15906) - [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)
milescoviello commented 2026-11-09 07:51:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-09T07:51:34Z.

Review: APPROVED


Read 784752f2bc against main b66ca0e85a (the merge preview is clean).

Change. static_cast<std::uint32_t>(reserved) != 0 keeps the one measured refusal (the census passed a stack address, whose low 32 bits are never zero) and accepts 0x300000000. Ghost of Tsushima passes that value as well, and with this head it gets past start-up (my run above). libSceAjm.native is the only library in the tree that exports sceAjmInitialize, so there is no second implementation to keep in step.

Test. The new row is right, and the change to the old rows is needed. other + 1 was the unallocated context ID that sceAjmBatchWait and sceAjmBatchStart were checked against, but with the extra sceAjmInitialize that ID is now highHalf, an allocated context. Moving those checks to highHalf + 1 keeps them testing an unallocated ID, which they would otherwise silently stop doing.

Small thing, not blocking. The test finalizes other but not highHalf. Per the debt entry, finalization doesn't release anything yet, so it changes no result. A sceAjmFinalize(highHalf) next to the existing one would keep the pairing if finalization starts releasing contexts later.

Docs. The entry now gives the low-32-bit rule, the PPSA16833 immediate and what the 13.42 module does with the upper word, all sourced.

I didn't rebuild guest_ajm myself; JJenkx's Windows run and your WSL and Windows runs cover it.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5822948768 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16974#pullrequestreview-5822948768). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-09T07:51:34Z. **Review:** APPROVED --- Read `784752f2bc` against `main` `b66ca0e85a` (the merge preview is clean). **Change.** `static_cast<std::uint32_t>(reserved) != 0` keeps the one measured refusal (the census passed a stack address, whose low 32 bits are never zero) and accepts `0x300000000`. Ghost of Tsushima passes that value as well, and with this head it gets past start-up (my run above). `libSceAjm.native` is the only library in the tree that exports `sceAjmInitialize`, so there is no second implementation to keep in step. **Test.** The new row is right, and the change to the old rows is needed. `other + 1` was the unallocated context ID that `sceAjmBatchWait` and `sceAjmBatchStart` were checked against, but with the extra `sceAjmInitialize` that ID is now `highHalf`, an allocated context. Moving those checks to `highHalf + 1` keeps them testing an unallocated ID, which they would otherwise silently stop doing. **Small thing, not blocking.** The test finalizes `other` but not `highHalf`. Per the debt entry, finalization doesn't release anything yet, so it changes no result. A `sceAjmFinalize(highHalf)` next to the existing one would keep the pairing if finalization starts releasing contexts later. **Docs.** The entry now gives the low-32-bit rule, the PPSA16833 immediate and what the 13.42 module does with the upper word, all sourced. I didn't rebuild `guest_ajm` myself; JJenkx's Windows run and your WSL and Windows runs cover it. AI-assisted: yes (Claude Code)
milescoviello commented 2026-11-09 08:09:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-09T08:09:34Z.

Review: APPROVED


Re-checked 2516536621: the only change since 784752f2bc is Require(sceAjmFinalize(highHalf) == 0); in TestBatchContextOwnership, so the context initialised with the nonzero high half is now released like other. It still merges cleanly into current main. Approval carried over to this head.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5823135474 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16974#pullrequestreview-5823135474). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-09T08:09:34Z. **Review:** APPROVED --- Re-checked `2516536621`: the only change since `784752f2bc` is `Require(sceAjmFinalize(highHalf) == 0);` in `TestBatchContextOwnership`, so the context initialised with the nonzero high half is now released like `other`. It still merges cleanly into current `main`. Approval carried over to this head. AI-assisted: yes (Claude Code)
milescoviello commented 2026-11-09 17:11:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-09T17:11:52Z.

Review: APPROVED


Re-checked 4f1bc06940. Ignoring reserved makes sense given the three data points: a set that rejects a stack address but accepts both 0x300000000 and 0x20 has no rule the sources support. Accepting everything is what titles need, and it's what the code did before #15906.

  • Code: only a null context returns 0x80930005, so every value the low-32-bit version accepted is still accepted, GoT's 0x300000000 included (I ran GoT past this call on the earlier head). Hades II's 0x20 is now accepted too.
  • Test: 0x20 and 0x300000000 each get a fresh, distinct context, and both are finalized. highHalf + 1 is still the first unallocated context, because contexts come from g_nextContext.fetch_add and highHalf is the last one taken, so the invalid-context rows still probe an id nobody owns. No refusal row is left, in line with the positive-only test guidance.
  • Debt: the entry records the titles seen passing nonzero values, PPSA02225 among them, and that the console check itself is unread.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5829680259 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16974#pullrequestreview-5829680259). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-09T17:11:52Z. **Review:** APPROVED --- Re-checked `4f1bc06940`. Ignoring `reserved` makes sense given the three data points: a set that rejects a stack address but accepts both `0x300000000` and `0x20` has no rule the sources support. Accepting everything is what titles need, and it's what the code did before #15906. - **Code:** only a null `context` returns `0x80930005`, so every value the low-32-bit version accepted is still accepted, GoT's `0x300000000` included (I ran GoT past this call on the earlier head). Hades II's `0x20` is now accepted too. - **Test:** `0x20` and `0x300000000` each get a fresh, distinct context, and both are finalized. `highHalf + 1` is still the first unallocated context, because contexts come from `g_nextContext.fetch_add` and `highHalf` is the last one taken, so the invalid-context rows still probe an id nobody owns. No refusal row is left, in line with the positive-only test guidance. - **Debt:** the entry records the titles seen passing nonzero values, PPSA02225 among them, and that the console check itself is unread. 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!16974
No description provided.