Skip to content

fix(libSceMusicCoreInterface): return error on unreadable parameter preserving errno - #24426

Closed
vishnuvardhan3333 wants to merge 1 commit into
boykopovar:mainfrom
vishnuvardhan3333:fix/music-core-interface-guest-param
Closed

vishnuvardhan3333 wants to merge 1 commit into
boykopovar:mainfrom
vishnuvardhan3333:fix/music-core-interface-guest-param

Conversation

@vishnuvardhan3333

Copy link
Copy Markdown
Contributor

What

In libSceMusicCoreInterface:

  • Preserve host errno around GuestCopyIn_nid_no_patch in sceMusicCoreIfInitializeInterface.
  • Return ErrorInvalidArgument (0x81795002) instead of throwing std::invalid_argument when the guest parameter buffer is unreadable.
  • Add regression test coverage in core/libs/tests/GuestMusicCoreInterface.cpp ensuring an unreadable parameter returns invalidArgument and preserves caller errno.
  • Document the host-safety fallback in docs/dev/debt/changes/fix-music-core-interface-guest-param.md.

Tested

  • python tools/check_conventions.py --base origin/main (passed)
  • python tools/debt_fold.py --check (passed)
  • python tools/pr_overlap.py --names sceMusicCoreIfInitializeInterface sceMusicCoreIfSetFunctionTable sceMusicCoreIfMainLoop sceMusicCoreIfSetInternalFunctionTable sceMusicCoreIfSetFunctionTableExt2 sceMusicCoreIfSetFunctionTableUnlimited sceMusicCoreIfInternalInitializeInterface (none)

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

@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 dbb16f7cc8:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_music_core_interface_tests built cleanly.
  • CTest (guest_music_core_interface):
    1/1 Test #4677: guest_music_core_interface .......   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceMusicCoreInterface/Export.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4677: guest_music_core_interface .......Subprocess aborted***Exception:   0.40 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified Export.cpp null-pointer checks for argument1 and param before attempting GuestCopyIn_nid_no_patch
    • Verified errno preservation around GuestCopyIn_nid_no_patch in sceMusicCoreIfInitializeInterface
    • Verified error return ErrorInvalidArgument (0x81795002) when GuestCopyIn_nid_no_patch fails or size != InterfaceParamSize
    • Verified docs/dev/debt/changes/fix-music-core-interface-guest-param.md conforms to debt fragment specifications
    • Verified GuestMusicCoreInterface.cpp test coverage for unreadable parameter handling and errno preservation using GuestArenaSetHostReadHook_nid_no_patch

Looks Good To Me

@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

The changed implementation and regression test are sound by inspection; I could not run the reported checks in this review environment.

What I ran

Reviewed head dbb16f7cc81d7a425c0657d35676c231d331d3f2. Read the prepared description, commits, manifest, diff, and all three changed files through the review reader. No commands or tests were run.

Results

Check Result Note
Code and test review passed All changed files read
Reported convention and debt checks not run Author-reported only
Regression test execution not run No command execution available

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

The convention and debt checks reported in the PR description were not run here. No files were excluded from review; all three files marked changed in the manifest were read.

To get this to a good state

Nothing is required.

This was referenced Nov 21, 2026
@kiwe147

kiwe147 commented Nov 21, 2026

Copy link
Copy Markdown

Tested head dbb16f7cc8, applied with git apply on main fd4aeed483 together with the other 25 PRs of one batch (#24107, #24132, #24238, #15143, #22088, #22685, #23739, #24032, #16054, #20001, #20344, #24170, #24396, #16856, #17298, #20497, #23347, #24554, #24598, #21376, #21556, #22047, #22082, #14124, #18476). 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_music_core_interface (1 test, matched by name to the test file this PR changes) all pass outside the iGPU subset

Whole batch: the full ctest -j 12 (6524 tests) on the RTX 3080 has 8 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. Intermittent in this run (pass when rerun alone, or known flaky): agc_driver_store_over_untracked. Traced to other PRs of the batch, each by reverting it and testing again: #21556 (guest_json_allocator), #16856 (guest_kernel_sys_module_internal), #15143 (guest_math_exact); none is in this PR's area. Failing tests I could not trace to a single PR (reverting the likely candidates did not clear them): public_headers. The 2127 agc_/video tests on the iGPU have 2 failing: agc_driver_stencil_plane_memory, agc_driver_store_over_untracked (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)

@Helldiverr

Copy link
Copy Markdown
Contributor

Windows CPU run with two points. guest_music_core_interface passes on main 45fc4e23bb and on the merge 3 times out of 3, and the negative control is caught. But the errno half of the change is already done by GuestCopyIn_nid_no_patch: removing the new errno = savedErrno; leaves the test passing. The new 0x81795002 for an unreadable block has no console source.

Existing runs:

  • PrivacyOnion ran the test on Ubuntu 24.04 with a negative control (Export.cpp from main: the test aborts).
  • MarcZX10 reviewed the code by reading it.
  • kiwe147 ran Windows 11 with this PR applied together with 25 others on fd4aeed483. guest_music_core_interface passed there, with no control for this PR alone.
  • The PR body lists check_conventions, debt_fold --check and pr_overlap only.

What this run adds.

  • A Windows run of this PR alone, merged onto main 45fc4e23bb.
  • A negative control and two mutations, one of which survives.
  • check_conventions and debt_fold --check on the merge.

Code (line numbers at dbb16f7cc8 for the files the PR changes; General.cpp is cited on main 45fc4e23bb, which is what the merge uses).

  • The errno save is redundant.
    • sceMusicCoreIfInitializeInterface saves errno and restores it around GuestCopyIn_nid_no_patch (core/libs/prx/libSceMusicCoreInterface/Export.cpp:26-29).
    • GuestCopyIn_nid_no_patch already does this. CopyGuestBytes holds a RestoreErrno (core/libs/prx/libc/src/General.cpp:91-94, :97) that is constructed before the host-read hook runs (:98), so the hook's errno = 99 is undone on return.
    • With line 29 removed, the test still passes (mA below). The errno == 71 check (core/libs/tests/GuestMusicCoreInterface.cpp:48) therefore passes on main's copy too. Only the throw-to-return change makes the new test fail there.
    • Lines 26 and 29 can go. Alternatively, the test needs a case that GuestCopyIn_nid_no_patch does not already cover.
  • The unreadable-block result has no console source.
    • main throws std::invalid_argument for an unreadable parameter block. The PR returns 0x81795002 instead (Export.cpp:30).
    • The fragment calls this "a host-safety fallback" (docs/dev/debt/changes/fix-music-core-interface-guest-param.md:5), and the rest of the entry comes from firmware 13.42's disassembly. So the value is chosen, not read from the console function.
    • CONVENTIONS says the error for unreadable memory "is decided per function". If there is no source for this one, keeping main's throw records the gap without inventing an answer. If there is a source (for example the disassembly showing a guarded read), citing it in the fragment would settle it.
  • Debt length. check_conventions warns: "Technical debt entry over 1000 characters … 1089 characters" (fix-music-core-interface-guest-param.md:3). It is a warning, and the check exits 0.
  • I found no code comments other than the namespace end (GuestMusicCoreInterface.cpp:22), and no title-specific cases. At the merge:
    • py -3 tools/check_conventions.py --base 45fc4e23bb exits 0 with that one warning;
    • py -3 tools/debt_fold.py --check exits 0.

Negative control and mutation. All of these ran on guest_music_core_interface, at the merge.

Change to Export.cpp Result
Negative control: Export.cpp from main, test kept caught: "terminate called after throwing an instance of 'std::invalid_argument'", "sceMusicCoreIfInitializeInterface: unreadable parameter"
mA: errno = savedErrno; removed (:29) survives
mB: an unreadable block returns 0 instead of 0x81795002 caught: abort (0xc0000409)

Tests. ctest --test-dir build -R '^guest_music_core_interface$' -V. It is the library's only test.

Test main merge run 1 run 2 run 3
guest_music_core_interface Passed Passed Passed Passed

Host

  • CPU: Ryzen 9 9950X3D
  • OS: Windows 11 Pro 26300
  • Toolchain: WinLibs GCC 15.2, Release (CMAKE_CXX_FLAGS_RELEASE -O3 -DNDEBUG, checked before each build)
  • Commits: head dbb16f7cc8, merged onto main 45fc4e23bb as 819ccddf82. main has since moved 23 commits to dad6acd1b8, none of them in the files cited here, and the head still merges cleanly.

AI-assisted: yes

@vishnuvardhan3333

Copy link
Copy Markdown
Contributor Author

Thanks @Helldiverr for the Windows run and analysis! Since GuestCopyIn_nid_no_patch already preserves errno on main and returning

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.

5 participants