Skip to content

fix(libSceNgs2.native): return the module's buffer and allocator errors from sceNgs2RackCreate and sceNgs2RackCreateWithAllocator - #20810

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
roboterspinne:fix/libscengs2-rack-create-errors
Nov 17, 2026

Conversation

@roboterspinne

@roboterspinne roboterspinne commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

What

On main 4b83e9d (these lines are unchanged since e4caa07) sceNgs2RackCreate (core/libs/prx/libSceNgs2.native/src/Rack.cpp:269-279) checks the handle first (:270, 0x804A8010), throws APS5_INVALID_ARG_EX for a null buffer info (:271) and returns SCE_NGS2_ERROR_INVALID_BUFFER_INFO (0x804A8020) only for an unreadable one (:273, ReadGuest, #20893). A buffer info with a null host_buffer is not checked: it passes the option check and the system lookup in CreateRack (:141-146), and Ngs2Place (core/libs/prx/libSceNgs2.native/src/System.cpp:217-219) throws std::invalid_argument. sceNgs2RackCreateWithAllocator (Rack.cpp:281-306) also checks the handle first (:282), throws for a null allocator (:283), returns SCE_NGS2_ERROR_INVALID_BUFFER_ALLOCATOR (0x804A8023) for an unreadable one (:285) and throws for a null alloc_handler or free_handler (:286).

Tested

Windows 11, WinLibs GCC 15.2.0, Ninja, Release, BUILD_TESTING=ON, build directory configured through its 8.3 short path, on 24ee695 (the merge commit 45f8a4e with main 4b83e9d, plus the test commit). Built with cmake --build <build> --parallel 10 --target libSceNgs2.native libSceNgs2 and the 37 ngs2_*_tests executables of the build (exit 0); ctest --test-dir <build> -N -R '^ngs2' lists 51 tests. Before every run each core/libs/libs/unpatched/*.prx that also exists in <build>/tests was copied there with cmake -E copy_if_different, and the md5sum of libSceNgs2.native.prx in both places matched each time.

  • With the change: ctest --test-dir <build> -R '^ngs2' --output-on-failure passed 51/51, ngs2_channelmixer, ngs2_handleerrors, ngs2_custom, ngs2_core_custom and ngs2_commands among them.
  • Negative control for the test commit: on the merge commit 45f8a4e alone, built the same way, -R '^ngs2' passed 50/51; ngs2_channelmixer failed with Exit code 0xc0000409 and NGS2 check failed at line 199.
  • Negative control for Rack.cpp: with only Rack.cpp of 4b83e9d put back and libSceNgs2.native libSceNgs2 ngs2_handleerrors_tests ngs2_channelmixer_tests ngs2_custom_tests ngs2_core_custom_tests rebuilt (exit 0), ctest --test-dir <build> -R '^(ngs2_handleerrors|ngs2_channelmixer|ngs2_custom|ngs2_core_custom)$' --output-on-failure failed ngs2_handleerrors with sceNgs2RackCreate: invalid argument and passed the other three, so neither pinned test is a negative control. With the change restored and rebuilt (exit 0), -R '^ngs2' passed 51/51.
  • The changed Ngs2ChannelMixer.cpp alone on main 4b83e9d (a second checkout, same host and settings, .prx copied the same way): ctest --test-dir <build> -R '^ngs2_channelmixer$' --output-on-failure passed 1/1.
  • python tools/debt_fold.py --check passes on main 4b83e9d and on 24ee695, and --show libSceNgs2.native differs from main only in the changed entry.
  • Not run here: Linux and macOS (see the Linux bullet above).
  • python tools/check_conventions.py --base upstream/main --head HEAD with this title and description passed.

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: n/a
  • AI-assisted: yes (Claude Code)

…rs from sceNgs2RackCreate and sceNgs2RackCreateWithAllocator

sceNgs2RackCreate checked the handle first and threw for a null buffer
info, and a null host buffer threw later in Ngs2Place.
sceNgs2RackCreateWithAllocator checked the handle first and threw for a
null allocator or alloc handler. Both now return 0x804A8020 or
0x804A8023 before the null-handle check, as the system create calls
already do, and a rack allocator without a free handler throws only
after the option and system checks. CheckRackCreateArguments covers
the order, and the Ngs2Custom num_buffers check passes a real buffer.
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

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 1384 core/libs/prx/libSceNgs2.native/src/Rack.cpp
PR 21141 core/libs/prx/libSceNgs2.native/src/Rack.cpp
core/libs/prx/libSceNgs2.native/tests/Ngs2Custom.cpp
core/libs/prx/libSceNgs2.native/tests/Ngs2HandleErrors.cpp

oneandonlydean pushed a commit that referenced this pull request Nov 15, 2026
…n sceNgs2RackCreate

sceNgs2RackCreate dereferenced the guest Ngs2ContextBufferInfo pointer when it
passed the buffer info to CreateRack, so an unmapped buffer info faulted the
host. The struct is now copied in with ReadGuest and the local copy is passed
on. An unreadable pointer returns SCE_NGS2_ERROR_INVALID_BUFFER_INFO, the code
PR #20810 returns for a null buffer info. A null pointer keeps its current
behaviour in this change. CreateRack copies the buffer info by value, so
readable input behaves as before.
oneandonlydean pushed a commit that referenced this pull request Nov 15, 2026
…sceNgs2RackCreateWithAllocator

sceNgs2RackCreateWithAllocator called the allocator handlers through the guest
pointer, so an unmapped allocator faulted the host. The allocator is now copied
in with ReadGuest, and the handlers, the creation and the release all use the
local copy. An unreadable allocator returns SCE_NGS2_ERROR_INVALID_BUFFER_ALLOCATOR,
the code PR #20810 returns for a null allocator. A readable null allocator or a
readable null handler keeps its current behaviour. CreateRack stores the
allocator by value, so no pointer to the local outlives the call.
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 15, 2026
@roboterspinne

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Merged main (e4caa07) into this branch as 8e4e8c0 and resolved the conflict with #20893 as its description states: its ReadGuest lines and this pull request's null checks are both kept, and in Ngs2HandleErrors.cpp the call list of main keeps both sides. host_buffer and alloc_handler are now checked on the local copies, and the copies run before the null-handle check, as sceNgs2SystemCreate and sceNgs2SystemCreateWithAllocator do. On the merge commit ctest -R '^ngs2' passes 50/50, including your CheckRackCreateGuestPointers rows; the description is updated.

@ycbuzi

ycbuzi commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Tested 8e4e8c0b08 merged into main, with the whole ctest suite on each machine below. Nothing fails that does not also fail on main on the same machine.

  • Windows Server 2022 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 3 tests failed out of 5960; 99% tests passed, 5 tests failed out of 5960. 4 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 99% tests passed, 1 tests failed out of 5960; 99% tests passed, 1 tests failed out of 5960. 1 of the failing tests fail on main too. run

AI-assisted: yes (Claude Code); the runs are automated, this summary was written from their reports.

@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 and supplied test report support merging.

What I ran

Reviewed head 8e4e8c0b088c85108f31bfb68921e5f71d465471. No commands or tests were run in this review; the Windows test results below are author reported.

Results

Check Result Note
Patch and changed code passed Four changed files read
Author reported tests passed 50/50 Ngs2 tests on Windows
Reviewer test run not run No local test execution

Findings

Blocking

None.

Non-blocking

None.

Not verified

No Linux or macOS run, physical console behavior, or independent test execution was performed. The author reports testing the change on Windows 11 with GCC 15.2.0 and a negative control; those results were not reproduced here. All four files listed under reviewed in manifest.json were read: Rack.cpp, Ngs2Custom.cpp, Ngs2HandleErrors.cpp, and fix-libscengs2-rack-create-errors.md. files.json was not provided in the review folder, so excluded files were not verified.

To get this to a good state

Nothing is required.

@roboterspinne

Copy link
Copy Markdown
Contributor Author

@MarcZX10 Merged main (4b83e9d) into this branch as 45f8a4e. main now has #21478 (akkadbakkad89), whose ngs2_channelmixer test passed a buffer info with a null host_buffer to sceNgs2RackCreate and expected the module option errors. With this pull request that call returns 0x804A8020 first, so the test failed at line 199 on the merge. 24ee695 makes its helper CreateMixerRack pass a real buffer, queried with the valid option; the expected codes and Rack.cpp are unchanged. On 24ee695 ctest -R '^ngs2' passes 51/51, and the description is updated. The approval was on 8e4e8c0, so this needs another look.

@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 — no blocking findings

Nothing blocks this; the points below are optional.

Head 24ee695, base main. The change returns the module's buffer and allocator errors from sceNgs2RackCreate and sceNgs2RackCreateWithAllocator, as the description states, and the code I read does what it says.

What I ran

  • Read the title and description, the commit list, manifest.json, files.json and diff.patch for this head.
  • Read the house-rule sections "Readable reviews", "Accuracy and evidence" and "Standard PR response format" from the ruling file.
  • Targeted reads at the head, with the reader:
repo_read.py cat core/libs/prx/libSceNgs2.native/tests/Ngs2Custom.cpp 545 560
repo_read.py cat core/libs/prx/libSceNgs2.native/src/Rack.cpp 120 150
repo_read.py search CountedAllocate core/libs/prx/libSceNgs2.native/tests/Ngs2HandleErrors.cpp
repo_read.py search Returned core/libs/prx/libSceNgs2.native/tests/Ngs2HandleErrors.cpp

Results

Check Result Note
Changed hunks, five files passed Each file in the reviewed list was read through its hunks
Test helpers used by new rows passed Returned and CountedAllocate exist at the head
Build and ctest not run Author-reported only, not rerun here
Negative controls not run Author-reported only, not rerun here

Findings

Blocking

None.

Non-blocking

  • core/libs/prx/libSceNgs2.native/tests/Ngs2HandleErrors.cpp:414: the row "a null free handler and bad option" returns at the option check, before the free-handler throw. The new check at core/libs/prx/libSceNgs2.native/src/Rack.cpp:294 is therefore not exercised by any row, and the row name suggests it is. Add a row with a valid option and a null free handler that expects the throw, or rename the row.

Not verified

  • No build or test was run here. The author's ctest result (51/51) and the negative controls are not confirmed by me.
  • The error order comes from the prosper permalinks in the description. I did not check them, and the description says the order was not measured on a console.
  • The new query sceNgs2RackQueryBufferSize for the submixer rack with a null option (in CheckRackCreateArguments) was not checked against the module. The test uses Status and would fail loudly if the call were refused.
  • Rack.cpp, Ngs2ChannelMixer.cpp, Ngs2Custom.cpp and Ngs2HandleErrors.cpp were read through their changed hunks and nearby lines, not as whole files.
  • Linux and macOS were not run. The author ran on Windows only.

To get this to a good state

Nothing is required. The optional point is the non-blocking row above.

@oneandonlydean
oneandonlydean merged commit ed9c722 into boykopovar:main Nov 17, 2026
16 checks passed
@roboterspinne
roboterspinne deleted the fix/libscengs2-rack-create-errors branch November 17, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants