Skip to content

docs(debt): name the console modules that free an IntrusivePtr without a deleter - #16296

Merged
adriadam10 merged 3 commits into
boykopovar:mainfrom
Opensource55:docs/npcppwebapi-intrusiveptr-release
Nov 10, 2026
Merged

adriadam10 merged 3 commits into
boykopovar:mainfrom
Opensource55:docs/npcppwebapi-intrusiveptr-release

Conversation

@Opensource55

Copy link
Copy Markdown
Contributor

What

The IntrusivePtr entry said the destructor throws on the last reference of a pointer without a deleter because destroying the object needs its destructor and the LibContext allocator. The module bundled with PPSA01341 v01.007.000 shows what that path does, so the entry now names it:

  • 0x116460: mov (%rdi),%rdi, call 0x12060 (a lock xadd of -1 that returns the previous count), cmp $1,%eax — the same release the host implementation already does, with the count at 0x00 of the pointee;
  • with no deleter at 0x08: call 0x12040, which is a bare ret, so no destructor runs;
  • then call 0x2c40, which is mov 0x20(%rdi),%rdi; jmp sceLibcMspaceFree, so the LibContext at 0x10 holds the mspace at 0x20 and the pointer is freed from it;
  • both are reached only when 0x47c0 has found the LibContext's first word in a process-wide registry; when it has not, nothing is freed.

The entry now says the registry and the destructor are what is missing, rather than the allocator as a whole, which the host libc implements (sceLibcMspaceFree). No code changes: the throw stays until the registry is modelled. The disassembly this comes from is attached below.

Tested

Not tested. Documentation only: no code, no test and no build output changes.

The addresses above were read from libSceNpCppWebApi.prx of PPSA01341 v01.007.000 with python3 tools/annotate_module.py --out ..., which also resolves the 44,810 exports of that module from the NID database.

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

…t a deleter

The entry said the destructor throws because destroying the object needs
its destructor and the LibContext allocator. The module bundled with
PPSA01341 v01.007.000 shows what the release does instead: a no-op
operator delete at 0x12040 and sceLibcMspaceFree at 0x2c40 with the
mspace the LibContext holds at +0x20, reached only after 0x47c0 finds
the LibContext's first word in a process-wide registry. The registry and
the destructor are the parts not reproduced, so the entry now says that
instead of the allocator as a whole.
@Opensource55

Copy link
Copy Markdown
Contributor Author

The disassembly the entry now cites, from libSceNpCppWebApi.prx of PPSA01341 v01.007.000 (annotate_module.py --out), IntrusivePtr<Leaderboards2V1::User>::~IntrusivePtr() at 0x116460:

  11646d:	mov    (%rdi),%rdi        ; pointee
  116473:	je     0x1164c9
  116475:	call   0x12060            ; lock xadd $-1 with the count at 0x00, returns the previous count
  11647d:	jne    0x1164c9            ; not the last reference
  11647f:	mov    0x8(%rbx),%rax     ; deleter
  116488:	call   *%rax               ; when present
  11648f:	mov    (%rbx),%r14
  116492:	mov    0x10(%rbx),%rdi     ; LibContext
  116496:	call   0x47c0              ; registry lookup, 0 when the context is not registered
  1164b1:	call   0x12040            ; 'ret' — no destructor
  1164bc:	call   0x2c40            ; mov 0x20(%rdi),%rdi; jmp sceLibcMspaceFree
  12060:	mov    $0xffffffff,%eax
  12065:	lock xadd %eax,(%rdi)
  12069:	ret
  2c40:	mov    0x20(%rdi),%rdi
  2c44:	jmp    0x4405b0            ; sceLibcMspaceFree

The release the host already does (fetch_sub and compare with 1) matches 0x12060 and the count offset. What is missing is only the no-deleter branch: the registry at 0x47c0 decides whether the pointer is freed at all, and no destructor runs on the way out.

Note for whoever merges: the other open libSceNpCppWebApi pull requests (#15885, #15823, #15808, #15816, #15863 and one more) may edit the same debt file; this one only rewrites the IntrusivePtr entry, so it should apply on top of any of them.

AI-assisted: yes.

@github-actions github-actions Bot added the docs label Nov 6, 2026
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 16018 docs/dev/debt/libSceNpCppWebApi.md L26-28
PR 16052 docs/dev/debt/libSceNpCppWebApi.md L26-28

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 14212 docs/dev/debt/libSceNpCppWebApi.md

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

Docs check of head fe15d88faa against main 0bae53facd: I compared what the entry says about the code with the code, and checked the links and counts. I can't check the console measurements themselves.

The destructor still throws for the last reference without a deleter (Export.cpp:1163), as the entry says.

@adriadam10 adriadam10 self-assigned this Nov 10, 2026
@adriadam10
adriadam10 merged commit d091399 into boykopovar:main Nov 10, 2026
11 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the entry against ReleaseIntrusivePtr in Export.cpp (still throws on the last reference without a deleter), the one-file docs-only diff and the conventions check; the disassembly addresses come from the author's module and were not re-run here. Merged.

@Opensource55
Opensource55 deleted the docs/npcppwebapi-intrusiveptr-release branch November 10, 2026 11:30
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.

3 participants