Skip to content

fix(libSceNgs2.native): read the waveform format and write the block and frame outputs through the guest helpers - #20158

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
kaiffeetasse:contrib/ngs2-waveform-guest-pointers
Nov 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
kaiffeetasse:contrib/ngs2-waveform-guest-pointers

Conversation

@kaiffeetasse

Copy link
Copy Markdown
Contributor

What

sceNgs2CalcWaveformBlock and sceNgs2GetWaveformFrameInfo in core/libs/prx/libSceNgs2.native/src/Atrac9.cpp dereferenced both the guest-supplied Ngs2WaveformFormat and their guest output pointers directly, so an unmapped guest address crashed the host instead of returning an error.

  • The format struct is now copied in through GuestCopyIn_nid_no_patch and the block (Ngs2WaveformBlock) or the four frame outputs are built locally and written through GuestCopyOut_nid_no_patch; the caller's errno is preserved across both helpers.
  • Error codes follow the existing null-pointer paths: INVALID_WAVEFORM_FORMAT when the format cannot be read, INVALID_OUT_ADDRESS when the block or an output cannot be written, and the previous return values (including the zeroed block written before an invalid-format error) are unchanged.
  • docs/dev/debt/libSceNgs2.native.md records the fallback as unmeasured on a console (490-character bullet).

Tested

  • cmake -S . -B build-libs -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON succeeded; cmake --build build-libs --target ngs2_parse_tests built 263 targets with no diagnostics from the changed file.
  • ctest --test-dir build-libs -R '^ngs2_(parse|atrac9)$': 100% tests passed, 0 tests failed out of 2 (ngs2_parse 0.01 s, ngs2_atrac9).
  • Regression proof: with Atrac9.cpp from main and the new Ngs2Parse.cpp, ctest -R '^ngs2_parse$' fails with 1 tests failed out of 1 / ngs2_parse (SEGFAULT) — the new cases pass only with the change.
  • The new cases cover an unmapped format pointer, an unmapped block pointer and each of the four unmapped frame outputs, with errno checked to stay at the value the caller set.
  • python3 tools/check_conventions.py --base origin/main: All conventions checks passed.
  • Linux 6.8, GCC 13.3, Release. Windows and macOS not run here.

Gate 1 (tools/pr_overlap.py --branch contrib/ngs2-waveform-guest-pointers --jobs 8) failed closed on PR #5548, which conflicts with main in docs/dev/debt/libSceNgs2.native.md only. No open PR touches Atrac9.cpp or Ngs2Parse.cpp: the file lists of the open PRs whose title mentions ngs2 (#5548, #1384, #13491, #15946, #17913, #18464, #18501, #19444) name Export.cpp, Rack.cpp, Custom.cpp, Reverb.cpp, Ngs2Internal.hpp, the other test files and the debt file, never the two files this PR changes. The overlap is the debt bullet appended at the end of that file.

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: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

@PrivacyOnion PrivacyOnion 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.

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 079c02946d:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: ngs2_parse_tests built cleanly.
  • CTest (ngs2_parse):
    1/1 Test #4199: ngs2_parse .......................   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNgs2.native/src/Atrac9.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4199: ngs2_parse .......................***Exception: SegFault  0.13 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libSceNgs2.native/src/Atrac9.cpp: Verified sceNgs2CalcWaveformBlock checks block == nullptr before reading the format via ReadGuest, initializes and populates local block data (retaining zeroed output on format error), and writes output via WriteGuest while returning SCE_NGS2_ERROR_INVALID_OUT_ADDRESS on write failure.
    • core/libs/prx/libSceNgs2.native/src/Atrac9.cpp: Verified sceNgs2GetWaveformFrameInfo preserves null-pointer validation order, reads format through ReadGuest, enforces channel and sample-rate boundaries, and writes out_frame_size, out_num_frame_samples, out_units_per_frame, and out_num_delay_samples via WriteGuest returning SCE_NGS2_ERROR_INVALID_OUT_ADDRESS on unmapped addresses.
    • core/libs/prx/libSceNgs2.native/src/Atrac9.cpp: Verified ReadGuest and WriteGuest helper templates properly preserve and restore thread-local errno across GuestCopyIn_nid_no_patch and GuestCopyOut_nid_no_patch invocations.
    • core/libs/prx/libSceNgs2.native/tests/Ngs2Parse.cpp: Verified TestCalcWaveformBlockGuestErrors and TestFrameInfoGuestErrors exercise unmapped guest pointer inputs (0x10) across all input and output positions and assert that errno remains unaffected.
    • docs/dev/debt/libSceNgs2.native.md: Verified the fallback behavior on unmapped memory is properly documented under the technical debt ledger with accurate relative markdown links.
    • AGENTS.md compliance: Verified zero disallowed comments were introduced in the implementation or test files, no temporary or extraneous files were created, and Conventional Commit guidelines are satisfied.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

@oneandonlydean
oneandonlydean merged commit e826980 into boykopovar:main Nov 14, 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 5548 docs/dev/debt/libSceNgs2.native.md

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.

3 participants