fix(libSceAgc): use firmware semaphore memory results #8318

Merged
hypermoist merged 5 commits from upstream-pr/8318 into main 2026-10-24 12:26:30 +00:00
hypermoist commented 2026-10-20 09:57:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-20T09:57:55Z.


What

Replaces the guessed semaphore memory behaviour with the firmware's. The evidence is the decrypted libSceAgc.sprx. Upstream threw "the console's error is unknown" on every rejected call; each of those now returns the firmware's code.

  • sceAgcSetAmmSemaphoreMemory (OQTgEXyihvA). Checks run in this order:

    • memory already registered (cmp qword ptr [0x4a098], 0): returns 0x8a6c0048;
    • size not 16 KiB aligned (shl rax, 0x32 on the size), then memory not 16 KiB aligned: returns 0x8a6c0002.

    It then stores memory and size and calls memset(memory, 0, size), clearing the whole region. That settles the OpenAGC-versus-sharpemu disagreement in the debt entry, so the "labels hold data past 8 bytes" throw is gone. There is no null check: (nullptr, 0) passes, leaves the size at 0 and so registers nothing.

  • sceAgcSetSemaphoreMemory (v3G+IipShZs, previously a throwing stub). Same body and the same two globals, so either call blocks the other. One extra check sits between the two alignment checks: a size above 0x40000000 returns 0x8a6c000b.

  • sceAgcGetSemaphoreLabel (hFQ9pUxoLQ4).

    • nothing registered: returns 0x8a6c0049;
    • index * 32 + 32 > size: returns 0x8a6c000b;
    • otherwise stores memory + index * 32. There is no null check on the output.
  • Debt entry. Rewritten to list what is still not done. The firmware runs libkernel qSleeVC6lwI (ioctl 0xc018ac15 with {memory, size, 1}) and sceAgcDriverPassInfoDownward({7: memory, 8: size, 0xb: 0|1}), and both results are defined by the kernel and driver.

Tested

Linux (CachyOS, GCC, Release). agc_semaphore_tests was updated to the firmware results and passes. It checks:

  • every error code and the check order (limit before address alignment, registration before alignment);
  • the whole-region clear;
  • that an empty registration registers nothing;
  • that the AMM and non-AMM calls share one registration.

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: #8302 (the debt entry sits next to the workload entry that PR rewrites; this branch carries #8302's current documentation-only commit and none of the reverted workload code)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a (CPU-side registration only)
  • AI-assisted: yes (Claude Code), reviewed by the contributor

🤖 Generated with Claude Code

https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4934107401 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8318). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-20T09:57:55Z. --- ### What Replaces the guessed semaphore memory behaviour with the firmware's. The evidence is the decrypted `libSceAgc.sprx`. Upstream threw "the console's error is unknown" on every rejected call; each of those now returns the firmware's code. - **`sceAgcSetAmmSemaphoreMemory` (`OQTgEXyihvA`).** Checks run in this order: - memory already registered (`cmp qword ptr [0x4a098], 0`): returns `0x8a6c0048`; - size not 16 KiB aligned (`shl rax, 0x32` on the size), then memory not 16 KiB aligned: returns `0x8a6c0002`. It then stores memory and size and calls `memset(memory, 0, size)`, clearing the whole region. That settles the OpenAGC-versus-sharpemu disagreement in the debt entry, so the "labels hold data past 8 bytes" throw is gone. There is no null check: `(nullptr, 0)` passes, leaves the size at 0 and so registers nothing. - **`sceAgcSetSemaphoreMemory` (`v3G+IipShZs`, previously a throwing stub).** Same body and the same two globals, so either call blocks the other. One extra check sits between the two alignment checks: a size above `0x40000000` returns `0x8a6c000b`. - **`sceAgcGetSemaphoreLabel` (`hFQ9pUxoLQ4`).** - nothing registered: returns `0x8a6c0049`; - `index * 32 + 32 > size`: returns `0x8a6c000b`; - otherwise stores `memory + index * 32`. There is no null check on the output. - **Debt entry.** Rewritten to list what is still not done. The firmware runs libkernel `qSleeVC6lwI` (ioctl `0xc018ac15` with `{memory, size, 1}`) and `sceAgcDriverPassInfoDownward({7: memory, 8: size, 0xb: 0|1})`, and both results are defined by the kernel and driver. ### Tested Linux (CachyOS, GCC, Release). `agc_semaphore_tests` was updated to the firmware results and passes. It checks: - every error code and the check order (limit before address alignment, registration before alignment); - the whole-region clear; - that an empty registration registers nothing; - that the AMM and non-AMM calls share one registration. ### 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: #8302 (the debt entry sits next to the workload entry that PR rewrites; this branch carries #8302's current documentation-only commit and none of the reverted workload code) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a (CPU-side registration only) - [x] AI-assisted: yes (Claude Code), reviewed by the contributor 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
hypermoist commented 2026-10-22 12:52:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-22T12:52:24Z.


Overlap note: #9166 rewrites the sceAgcDcbSetWorkloadsActive entry in docs/dev/debt/libSceAgc.md (line 45). This PR rewrites the sceAgcSetAmmSemaphoreMemory entry right above it (line 44), and #8302's documentation commit, which this branch carries, adds the workload packet entry below it. The code doesn't overlap. Whichever is merged second merges main and keeps all three entries. If #9166 lands first, I'll do that here and fold its workload wording into #8302's entry, so the file doesn't end up with two entries for the same calls.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6341215868 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8318#issuecomment-6341215868). Originally posted by [hypermoist](https://github.com/hypermoist) on 2026-10-22T12:52:24Z. --- Overlap note: #9166 rewrites the `sceAgcDcbSetWorkloadsActive` entry in `docs/dev/debt/libSceAgc.md` (line 45). This PR rewrites the `sceAgcSetAmmSemaphoreMemory` entry right above it (line 44), and #8302's documentation commit, which this branch carries, adds the workload packet entry below it. The code doesn't overlap. Whichever is merged second merges `main` and keeps all three entries. If #9166 lands first, I'll do that here and fold its workload wording into #8302's entry, so the file doesn't end up with two entries for the same calls. 🤖 Generated with [Claude Code](https://claude.com/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!8318
No description provided.