Repository navigation
fix(libSceNpCppWebApi): keep the reference when an IntrusivePtr is assigned its own object - #11204
Conversation
…signed its own object
MarcZX10
left a comment
There was a problem hiding this comment.
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.
|
Windows run of this head
AI-assisted: yes (Claude Code) |
|
@babyhuey Thanks for the Windows run with the skipped job's selection. |
What
AnyPS5's
IntrusivePtrassignment 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
AssignIntrusivePtrhelper that does the same.Not changed here:
IntrusivePtr<Vector<unsigned long>>::operator=has the same pattern. fix(libSceNpCppWebApi): count Vector<String> and Vector<unsigned long> references where the bundled module does #10925 changes its reference-count offset, so it will move to the helper once that lands.Tested
Ubuntu 24.04 (WSL2), GCC 13.3, Release build with
BUILD_TESTING=ON:guest_np_cpp_web_api_intrusive_ptrgains a case for each operator. It checks self-assignment, assignment from another pointer to the same object (the count stays 1, no deleter call, deleter and context kept), and assignment from a different object (the old object is released through its deleter and the new count is 2).guest_np_cpp_web_api_intrusive_ptr,guest_np_cpp_web_api_string,guest_np_cpp_web_api_signed_outandguest_np_cpp_web_api_offlinepass.python3 tools/check_conventions.py --base origin/mainpasses.python3 tools/pr_overlap.py --branch fix/npcppwebapi-same-object-assignmentfinds no overlap. The branch merges cleanly with fix(libSceNpCppWebApi): count Vector<String> and Vector<unsigned long> references where the bundled module does #10925, fix(npcppwebapi): preserve aliased inputs during growth #9612, feat(libSceNpCppWebApi): cover the UserProfile models and remaining Common instantiations #9015 and feat(libSceNpCppWebApi): fail the InGameCatalog and TitleCloudStorage transactions signed out #10832, which edit the same files.No title run.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)