Skip to content

fix(libSceNpCppWebApi): keep the reference when an IntrusivePtr is assigned its own object - #11204

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
AlexFigas:fix/npcppwebapi-same-object-assignment
Oct 26, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
AlexFigas:fix/npcppwebapi-same-object-assignment

Conversation

@AlexFigas

Copy link
Copy Markdown
Contributor

What

AnyPS5's IntrusivePtr assignment operators release the target's reference before copying the source. When both pointers hold the same object, as in a self-assignment or two pointers to one object, the release can drop the last reference: the object is passed to its deleter and the pointer is then set to the freed object again.

The module bundled with PPSA21564 (sce_module/libSceNpCppWebApi.prx, the library's own code) checks for this first. Its operators for the three types this library implements call a reset routine that compares the held object with the new one and returns without changing anything when they match (mov rdi, qword ptr [rdi]; cmp rdi, rsi; je):

  • IntrusivePtr<PlayerSession> at 0x287960, which calls 0x287990.
  • IntrusivePtr<Vector<IntrusivePtr<PlayerSession>>> at 0x289080, which calls 0x288fb0.
  • IntrusivePtr<Vector<IntrusivePtr<InGameCatalog::V5::Container>>> at 0xa94c0, which calls 0xa93f0.

Otherwise the reset routine releases the old object and takes the new one's three fields and a reference.

The three operators now go through an AssignIntrusivePtr helper that does the same.

Not changed here:

Tested

Ubuntu 24.04 (WSL2), GCC 13.3, Release build with BUILD_TESTING=ON:

No title run.

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

@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 exact head 49c93d13576520a430e5d6acbf46567f9b8e12f0. The reported console disassembly checks the held object against the assigned object and returns before release when they match; AssignIntrusivePtr applies that guard to the three corresponding operators. The regression covers direct self-assignment, alias assignment to the same object, and assignment to a different object including reference counts and deleter calls.

I compiled the exact PR Export.cpp and GuestNpCppWebApiIntrusivePtr.cpp and ran the test under AddressSanitizer and UndefinedBehaviorSanitizer; it exited 0. I supplied the repository's existing throw behavior for NotImplemented_nid_no_patch as a link stub and discarded unused sections. Current-main conventions and git diff --check pass. The author reports the four focused API tests pass on Ubuntu 24.04; hosted product build jobs for this PR were skipped, so I do not claim a full product build.

@github-actions github-actions Bot added the prx label Oct 26, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 26, 2026
@babyhuey

Copy link
Copy Markdown
Contributor

Windows run of this head 49c93d13576, merged onto main 4e43321bd6c (clean merge, local only), with the selection CI's skipped Windows product job uses: Windows 11, Ryzen 7 5800X, RTX 3080, WinLibs GCC 15.2, Release, BUILD_TESTING=ON. The tree was configured fresh after the merge, then select_tests.py select / ninja -f select.ninja selected / --target libs / select_tests.py ctest --parallel 4 --timeout 120, with check_skips.py --job windows (all skips expected).

  • Selected 388 tests: 381 pass, 1 fails, pr_overlap_encoding, which also fails on 4e43321bd6c itself on this machine, 6 skip. No failures from this PR.

AI-assisted: yes (Claude Code)

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@babyhuey Thanks for the Windows run with the skipped job's selection.

@oneandonlydean
oneandonlydean merged commit 55939ac into boykopovar:main Oct 26, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants