Skip to content

fix(libSceAgc): validate and safely copy semaphore label pointer in sceAgcGetSemaphoreLabel - #22215

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
Kikoarl:fix/libSceAgc-semaphore-label-copyout
Nov 27, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
Kikoarl:fix/libSceAgc-semaphore-label-copyout

Conversation

@Kikoarl

@Kikoarl Kikoarl commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What

  • Open GuestArena::HostWrite around GuestWritable_nid_no_patch and GuestCopyOut_nid_no_patch in sceAgcGetSemaphoreLabel, restoring caller errno before Agc::Command::Require checks so write-watched output pages succeed without leaking errno.
  • Upgrade core/libs/prx/libSceAgc/tests/Semaphore.cpp to use armed GuestArena write-watched destination pages (PAGE_READONLY assertion on Windows, GuestArenaCollectWrites / GuestWriteWatchCollect dirty-page verification) alongside unmapped and 0x02 read-only refusal checks with errno preservation.
  • Record technical debt in docs/dev/debt/changes/fix-libSceAgc-semaphore-label-copyout.md.

Tested

  • Linux x86_64 Release RAM-disk build in /tmp/anyps5_verify_build, rebased onto origin/main (5f04682cef, PR head fdc1b8c5cd):
    • ctest --test-dir /tmp/anyps5_verify_build --output-on-failure -R "^agc_semaphore_tests$": 1/1 Passed.
  • python3 tools/debt_fold.py --check and python3 tools/check_conventions.py --base origin/main: Passed cleanly.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: none
  • AI-assisted: yes

@github-actions github-actions Bot added docs agc libSceAgc* labels Nov 17, 2026
@maskym

maskym commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Windows + NVIDIA result for head f8c18ae8a3, merged alone into main e069a7562f (the PR's Tested section names no Windows run).

Host: Windows 11 26300, Intel i7-12700K, NVIDIA GeForce RTX 2070 SUPER, WinLibs GCC 15.2.0 (x86_64-ucrt-posix-seh, r6), Release, BUILD_TESTING=ON, Ninja. main itself fails to compile one test on Windows at this commit (UploadCacheReadOnlyFlush.cpp:177, setenv; #19899 fixes it), so both trees were built with ninja -k 0.

Validation-layer protocol on main and on this PR (ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation 1.4.366, VK_LOADER_DEBUG=error,warn,layer, ctest -R '^(agc|guest_video_out|video_out|pad_sdl)' --parallel 4 -V):

Tree Passed Layer inserted was not found but was requested VUID- set
main 2050/2054 1856 0 none
this PR 2050/2054 1856 0 identical

agc_driver_upload_cache_read_only_flush is Not Run on both trees because of the main build break above. No new validation errors and no new failures. The failures on this PR's tree (agc_driver_stencil_plane_memory, agc_driver_store_over_untracked, agc_driver_msaa_dcc_unwatch) also fail on main here; rerun alone on this PR's tree they pass 0 of 3 times.

The tests this PR adds or changes (agc_semaphore_tests) pass in the full validation-layer run. Not run on a PS5.

AI-assisted: yes (Claude Code), the runs and the numbers above are from this machine.

This was referenced Nov 21, 2026
@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head f8c18ae8a3, applied with git apply on main fd4aeed483 together with the other 29 PRs of one batch (#24470, #24601, #17439, #17546, #21117, #21261, #21741, #21995, #22067, #22398, #23111, #23346, #23864, #24377, #24475, #24556, #14106, #14109, #19966, #20050, #20161, #20622, #21237, #22764, #22884, #22938, #23745, #24399, #24460). All applied without conflicts and the whole tree built.

Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON. GPUs: NVIDIA GeForce RTX 3080 (driver 621.24) and the AMD Radeon iGPU of the CPU (gfx1036, driver 32.0.21036.18). No validation layer. iGPU run: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 ANYPS5_GPU="AMD Radeon", agc_/video tests only.

tests RTX 3080 iGPU
guest_semaphore, guest_semaphore_handoff, guest_semaphore_trace (3 tests, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6525 tests) on the RTX 3080 has 5 failing tests; the 4 that also fail on main fd4aeed483 are agc_driver_stencil_plane_memory, agc_driver_msaa_dcc_unwatch, agc_storage_write_back_host_retile, and pr_overlap_names, which needs a newer Python than my 3.10. Traced to other PRs of the batch, each by reverting it and testing again: #21117 (guest_pad); none is in this PR's area. The 2125 agc_/video tests on the iGPU have 1 failing: agc_driver_stencil_plane_memory (agc_driver_stencil_plane_memory also fails on main).

This is one combined tree, not a run of this PR alone.

AI-assisted: yes (Claude Code)

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this change; the reviewed code validates and safely copies the semaphore label output, and the test covers an unmapped destination.

What I ran

Reviewed head f8c18ae8a3946bebe84dcc9011d16be5ea9ed045. No commands or tests were run. Read description.md, commits.md, manifest.json, diff.patch, all three changed files, and the GuestWritable_nid_no_patch / GuestCopyOut_nid_no_patch implementations in General.cpp. All files listed in the manifest were read.

Results

Check Result Note
Diff and changed files passed All three changed files reviewed
Relevant copy helpers passed Implementations inspected
Test execution not run Relied on code inspection
Hardware behavior not run Description says console behavior is unmeasured

Findings

Blocking

None.

Non-blocking

None.

Not verified

The author reports that agc_semaphore_tests and check_conventions.py passed; I did not run them. Physical console behavior and the description’s hardware, sanitizer, and formatting checklist claims were not independently verified. files.json was not available as a readable review document; the review folder listing and manifest were used to identify the changed files. No files were excluded in manifest.json.

To get this to a good state

Nothing is required.

@Kikoarl

Kikoarl commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto origin/main and pushed 67727870b0 wrapping GuestWritable_nid_no_patch / GuestCopyOut_nid_no_patch in GuestArena::HostWrite, restoring errno before throwing on failure, adding write-watched and read-only label pointer test coverage in Semaphore.cpp, and adding Closes when: / Labels: metadata to the debt fragment.

@Kikoarl
Kikoarl force-pushed the fix/libSceAgc-semaphore-label-copyout branch from f8c18ae to 6772787 Compare November 24, 2026 18:17
@Kikoarl
Kikoarl force-pushed the fix/libSceAgc-semaphore-label-copyout branch from 6772787 to fdc1b8c Compare November 24, 2026 19:43
@Kikoarl

Kikoarl commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Updated and rebased onto origin/main (5f04682cef) as fdc1b8c5cd: upgraded Semaphore.cpp to use armed GuestArena write-watched pages (PAGE_READONLY assertion on Windows, GuestArenaCollectWrites / GuestWriteWatchCollect dirty-page verification) and GuestArenaSetProtection 0x02 read-only refusal checks. Verified 1/1 agc_semaphore_tests plus debt_fold.py --check and check_conventions.py.

numeric_limits<T>::max() in this file breaks under the windows.h max macro on MSVC.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — looks good

Nothing blocks this review; the points below are optional.

What I ran

  • Reviewed head 4b3dd781fadf6eea04ab6443dd60938f81018fd3 using the prepared diff and repository reader.
  • Read core/libs/prx/libSceAgc/Misc/src/Semaphore.cpp, core/libs/prx/libSceAgc/tests/Semaphore.cpp, and docs/dev/debt/changes/fix-libSceAgc-semaphore-label-copyout.md; also read targeted GuestArena and existing test context in core/libs/prx/libc/include/GuestArena.hpp, core/libs/prx/libc/src/General.cpp, and core/libs/prx/libSceAgc/tests/StaticBuffer.cpp.
  • Did not run commands or tests. Build and test results in the PR description are author-reported.

Results

Check Result Note
Diff review passed All three changed files read
Build and tests not run Reported by author only
Negative control not run No test mutation performed

Findings

Blocking

None.

Non-blocking

None.

Not verified

  • The reported Linux build, semaphore test, and convention/debt checks were not independently run.
  • Windows and console hardware behavior were not exercised.
  • All files marked reviewed in the manifest were read; no changed file was excluded.

To get this to a good state

Nothing is required.

@oneandonlydean
oneandonlydean merged commit 90466aa into boykopovar:main Nov 27, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants