Skip to content

fix(libSceNgs2.native): clear the buffer info through guest copies in sceNgs2RackDestroy and sceNgs2SystemDestroy - #20970

Merged
oneandonlydean merged 4 commits into
boykopovar:mainfrom
MarcZX10:fix/libsceNgs2-destroy-buffer-info-guest-copy
Nov 15, 2026
Merged

oneandonlydean merged 4 commits into
boykopovar:mainfrom
MarcZX10:fix/libsceNgs2-destroy-buffer-info-guest-copy

Conversation

@MarcZX10

Copy link
Copy Markdown
Contributor

What

sceNgs2RackDestroy and sceNgs2SystemDestroy cleared the optional guest Ngs2ContextBufferInfo by writing through the caller's pointer, before any other check. An unmapped output faulted the host.

  • sceNgs2RackDestroy: the output is cleared with WriteGuest before the rack is looked up or destroyed. An unwritable output returns SCE_NGS2_ERROR_INVALID_OUT_ADDRESS and destroys nothing, so the caller can retry with a valid pointer. A null output is still skipped, and a writable output is cleared as before.
  • sceNgs2SystemDestroy: the same change for the system.

Commits: one fix and one test per function, four in total. Each fix and each test builds and passes on its own.

No external source is needed: the change only writes the cleared struct, and the error code is the one this library already returns for its other unwritable outputs.

Tested

Host: Linux, kernel 6.1, x86_64. Throwaway archive build of the tree, with the CPU startup gate patched in that build only (no change to HostCpu.cpp in this branch).

  • At the final head 948669f491, on upstream/main 31a13a37e6: all 49 ngs2_* tests Passed (35 test executables built), including ngs2_handleerrors, which covers the new cases.
  • Per commit: each of the four commits was built and ngs2_handleerrors run on its own; all pass.
  • Negative control: with upstream/main's Rack.cpp and System.cpp and this branch's tests, ngs2_handleerrors stops with SIGSEGV at address 0x10, the unwritable output the new cases pass.
  • Not run: Windows, macOS, a real console, any title.
  • Overlap, checked by hand because pr_overlap.py failed closed:

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

… in sceNgs2RackDestroy

sceNgs2RackDestroy cleared the optional guest buffer info by writing through its
pointer before any other check, so an unmapped output faulted the host. The
output is now cleared with WriteGuest before the rack is looked up or destroyed,
so an unwritable output returns SCE_NGS2_ERROR_INVALID_OUT_ADDRESS without
destroying anything. A writable output is cleared as before, and a null output
is still skipped.
…ckDestroy

An unwritable buffer info must return SCE_NGS2_ERROR_INVALID_OUT_ADDRESS and
leave the rack alive, so a later destroy with a null buffer info still succeeds.
…st in sceNgs2SystemDestroy

sceNgs2SystemDestroy cleared the optional guest buffer info by writing through
its pointer before any other check, so an unmapped output faulted the host. The
output is now cleared with WriteGuest before the system is looked up or
destroyed, so an unwritable output returns SCE_NGS2_ERROR_INVALID_OUT_ADDRESS
without destroying anything. A writable output is cleared as before, and a null
output is still skipped.
…stemDestroy

An unwritable buffer info must return SCE_NGS2_ERROR_INVALID_OUT_ADDRESS and
leave the system alive, so a later destroy with a null buffer info still succeeds.
@ycbuzi

ycbuzi commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Tested 3877c0f02f 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, 2 tests failed out of 5750; 99% tests passed, 2 tests failed out of 5750. 2 of the failing tests fail on main too. run
  • Windows Server 2025 (GitHub-hosted runner), full build, WinLibs GCC 15.2.0: 100% tests passed, 0 tests failed out of 5750; 100% tests passed, 0 tests failed out of 5750. run

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

@oneandonlydean
oneandonlydean merged commit f435c90 into boykopovar:main Nov 15, 2026
14 checks passed
@github-actions

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
core/libs/prx/libSceNgs2.native/src/System.cpp
PR 18501 core/libs/prx/libSceNgs2.native/src/Rack.cpp
PR 20810 core/libs/prx/libSceNgs2.native/src/Rack.cpp
core/libs/prx/libSceNgs2.native/tests/Ngs2HandleErrors.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants