feat(libSceNKWebKit): implement WTF symbols and the symbol registry #22684
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22684"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by RiverWhy on 2026-11-18T02:18:48Z.
What
Stacked on #22678 (the atom string table; its two commits come first, the last commit is this change). Implements 6 11.x WTF symbol exports:
SymbolImpl::create,SymbolImpl::createNullSymbolandPrivateSymbolImpl::create;SymbolRegistry::symbolForKeyand the registry'sD1/D2destructors.Source: pinned SymbolImpl.cpp, SymbolImpl.h and SymbolRegistry.cpp (PS5 11.x).
Details:
BufferSubstringStringImpl with the symbol flag (32). It shares the description's characters and holds a reference to the description's owner at +24, followed by the symbol hash from the existingnextHashForSymbolexport (+32) and the flags (+36). That's 40 bytes, or 48 for registered symbols, which add the registry pointer at +40. A substring description is resolved to its owner, as upstream does.HashSet<RefPtr<StringImpl>>that holds a strong reference to every symbol it creates. Here those references live in a host table keyed by the registry's address, and the guestHashSetstays empty. The registry's constructor is inline in the guest, so it is never called.symbolForKeyreturns the same symbol for equal keys (8- or 16-bit). A private registry (type 1) creates registered private symbols. The destructor clears each symbol's registry pointer, then drops the registry's references, like~SymbolRegistry.WtfString.cpp. Releasing a symbol used to callstd::terminate. Now it frees the symbol, releases the owner and, if the symbol is still registered, forgets it.RegisteredSymbolImplhas no exports of its own here, andSymbolRegistry::removeis inline.#22678 also gets a fix found while writing this:
addSlowCaseon a symbol (or any full-length substringadd) usedSubstringSharingImpl. That returns the string itself at full length, so the symbol itself was turned into an atom. It now always builds a new substring (or a copy when shorter than the substring header), likecreateSubstringSharingImpl, and #22678's test covers it.Debt: a fragment,
docs/dev/debt/changes/feat-nkwebkit-symbol-registry.md, adds the entry and removes the 6 inventory rows.Overlap:
pr_overlap.py --namesfinds no open PR with these exports.Tested
Linux Mint 22.3. New
nkwebkit_wtfsymbolregistrytest:symbolForKeywith equal 8- and 16-bit keys, public and private registries;The full build succeeds, and all NKWebKit tests pass, including the atom and
wtftext_allocationtests (the latter now also buildsWtfSymbolRegistry.cppandWtfSymbolImpl.cpp).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)Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-18T02:21:17Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
59b40f9624:tools/check_conventions.pypassed.nkwebkit_wtfatomstring_tests,nkwebkit_wtfsymbolregistry_testsbuilt cleanly.nkwebkit_wtfatomstring,nkwebkit_wtfsymbolregistry):core/libs/prx/libSceNKWebKit/Export.cpp,core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp,core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp,core/libs/prx/libSceNKWebKit/src/WtfNumberFormat.cpp,core/libs/prx/libSceNKWebKit/src/WtfString.cpp,core/libs/prx/libSceNKWebKit/src/WtfStringAbi.hpp,core/libs/prx/libSceNKWebKit/src/WtfTextAbi.hpp,core/libs/prx/libSceNKWebKit/src/WtfAtomString.cpp,core/libs/prx/libSceNKWebKit/src/WtfSymbolRegistry.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T03:19:13Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: make registry lookup and insertion atomic so concurrent calls for one key return the same symbol.
What I ran
Reviewed head
59b40f9624215e3254ca6d00c890e0be4ea5d921; no build or tests were run.Results
Findings
Blocking
core/libs/prx/libSceNKWebKit/src/WtfSymbolRegistry.cpp:204andcore/libs/prx/libSceNKWebKit/src/WtfSymbolRegistry.cpp:209: lookup releases the registry mutex before creating and inserting a symbol. Two concurrent calls for the same registry and key can both miss, create different symbols, and each return its own symbol; the secondemplacesilently fails. This breaks the registry guarantee that equal keys resolve to the same symbol. Keep lookup, creation and insertion atomic, or recheck after reacquiring the lock and discard/return the winner.Non-blocking
None.
Not verified
No build, tests, CI results, or console behavior were verified.
Export.cppandinclude/InventoryExports.hppwere excluded as too large for the review folder; their diff hunks were inspected, but their full text was not read. All other changed files were read, including the full text of files markedincludedin the manifest.To get this to a good state
Make registry creation safe for concurrent calls, then rerun the build and relevant NKWebKit tests.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T22:32:38Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this review; the points below are optional.
What I ran
Reviewed head
00cc5d4e8e6c003841364ce1477e3898d433343f. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
addSlowCase(AtomStringTable&, StringImpl&)validates the supplied table but adds to the current thread’s host table instead (WtfAtomString.cpp:377-379). The debt note documents this limitation. Consider preserving the table association so guest callers using distinct tables retain expected lookup and release behavior.fromUTF8Internalrejects an empty range (WtfAtomString.cpp:399-402), while invalid non-empty UTF-8 returns a null atom (WtfAtomString.cpp:405). Consider checking upstream behavior for an empty range and matching it if empty input is valid.Not verified
No build or tests were run, and no console behavior was checked. Read the prepared description, commits, manifest and diff, plus
WtfSymbolRegistry.cpp,WtfSymbolImpl.cpp,WtfString.cpp,WtfAtomString.cpp,WtfNumberFormat.cpp,WtfSymbolExports.hpp,CMakeLists.txt, andWtfSymbolRegistry.cpptests.Export.cppandInventoryExports.hppwere excluded from the review folder as too large; their full text was not read. Other changed files were not read.To get this to a good state
Nothing is required. The two non-blocking points above are optional follow-up considerations.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T00:12:50Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
0fcc403cdb1433011262f5f3110ff88e7ca1f184using the prepared diff and pinned reader. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceNKWebKit/src/WtfAtomString.cpp:377: the overload receiving anAtomStringTable&ignores that table and inserts into the current thread’s table. An atom released on another thread can therefore fail to be found byRemoveAtomand terminate. This limitation is documented in the debt entry; consider tracking the owning table or routing removal through the supplied table when addressing that debt.Sources
Behavior and limitation were checked against the changed source and the debt entry at this head.
Not verified
No build or tests were run. Full text was read for the included changed files except
Export.cppandinclude/InventoryExports.hpp, which the review bundle excluded for size; their relevant diff hunks were inspected. The complete test files were not read.files.jsonwas not available through the reader; the file list showed the two excluded files above and the remaining changed files included.To get this to a good state
Nothing is required. Optional: resolve the atom-table ownership/threading limitation described above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T19:05:48Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: ensure atom strings can be released from a different thread than the one whose table owns them.
What I ran
Reviewed head
cdae24958ed029a28964b1794cc4ba3f79397ee6using the prepared diff and the pinned-head readerrepo_read.py. No build or tests were run; the Linux Mint test results in the description are author-reported.Results
Findings
Blocking
core/libs/prx/libSceNKWebKit/src/WtfAtomString.cpp:332:RemoveAtomremoves an atom only from the releasing thread'sCurrentTable(), and terminates if it is not there. Atoms can be transferred across threads: the addedTestThreadTablesmoves a worker-created atom to the main thread atcore/libs/prx/libSceNKWebKit/tests/WtfAtomString.cpp:442-445, but releases it before the worker exits, so it does not exercise release from another thread. If the worker exits while an atom reference remains held elsewhere, its table destructor leaves the atom's flag set; releasing that atom on the receiving thread then terminates because that thread's table does not contain it. Track the owning table for each atom or otherwise make cross-thread release remove it safely.Non-blocking
None.
Not verified
Export.cppandinclude/InventoryExports.hppwere excluded from the review folder because they were too large. Their relevant hunks were visible indiff.patch, and the changed export region inExport.cppwas read through the pinned-head reader. The complete files were not read.To get this to a good state
Make atom-table ownership safe when references cross threads, then rerun the atom-string and full NKWebKit test suites.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T20:07:04Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing in the reviewed code establishes a blocking defect; review remains incomplete because two changed files were excluded from the review folder and could not be read in full.
What I ran
Reviewed head
e20f111179e1cb0c99b3e4fa2355df02d4e22803using the prepared diff andrepo_read.pyat the pinned head. No build or tests were run. The author reports a successful full build and passing NKWebKit tests; this was not independently verified.Results
Findings
Blocking
None identified in the code read.
Non-blocking
None.
Not verified
Full contents of
core/libs/prx/libSceNKWebKit/Export.cppandcore/libs/prx/libSceNKWebKit/include/InventoryExports.hppwere excluded as too large for the review folder. They were not read throughrepo_read.py. Also not verified: build/test claims, Windows behavior, and behavior on physical PS5 hardware.Files read:
description.md,commits.md,manifest.json,diff.patch,core/libs/prx/libSceNKWebKit/CMakeLists.txt,core/libs/prx/libSceNKWebKit/src/WtfAtomString.cpp,core/libs/prx/libSceNKWebKit/src/WtfString.cpp,core/libs/prx/libSceNKWebKit/src/WtfStringAbi.hpp,core/libs/prx/libSceNKWebKit/src/WtfSymbolRegistry.cpp, andcore/libs/prx/libSceNKWebKit/tests/WtfSymbolRegistry.cpp. Files excluded:Export.cppandinclude/InventoryExports.hpp.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T13:32:33Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: reject reversed or empty UTF-8 ranges without forming an invalid length or passing them to the decoder.
What I ran
Reviewed diff and targeted code at head
5a6572d9c036916e8040f8c05e99ede207936e7dusingrepo_read.py. No build or tests were run in this review.Results
Findings
Blocking
core/libs/prx/libSceNKWebKit/src/WtfAtomString.cpp:765: The function rejectsend <= startonly whenendis non-null. A caller can pass a non-nullendbeforestart; the subsequentend - startis negative and converted tosize_tforfromUTF8, potentially causing an oversized read. Check ordering before computing the length and reject or return null for an empty range, consistent with the intended behavior.Non-blocking
None.
Not verified
Export.cppandInventoryExports.hppfull text was excluded from the review bundle; only their diff hunks were inspected. Other files in the diff and manifest were inspected in the prepared bundle.To get this to a good state
Validate the UTF-8 range before subtracting its pointers, then rerun the UTF-8 edge tests and the NKWebKit test suite.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T03:57:42Z.
Review: COMMENTED
Actionable comments posted: 6
Architecture findings (3)
Advisory architecture findings (3)
3f30c07e-aafe-4aff-a9cb-50f3139619f4Reviewing files that changed from the base of the PR and between
aecfbf79b1andd817048120.core/libs/prx/libSceNKWebKit/CMakeLists.txtcore/libs/prx/libSceNKWebKit/Export.cppcore/libs/prx/libSceNKWebKit/include/InventoryExports.hppcore/libs/prx/libSceNKWebKit/include/WtfAtomStringExports.hppcore/libs/prx/libSceNKWebKit/include/WtfSymbolExports.hppcore/libs/prx/libSceNKWebKit/libSceNKWebKit.hppcore/libs/prx/libSceNKWebKit/src/WtfAtomString.cppcore/libs/prx/libSceNKWebKit/src/WtfString.cppcore/libs/prx/libSceNKWebKit/src/WtfStringAbi.hppcore/libs/prx/libSceNKWebKit/src/WtfSymbolRegistry.cppcore/libs/prx/libSceNKWebKit/tests/WtfAtomString.cppcore/libs/prx/libSceNKWebKit/tests/WtfSymbolRegistry.cppdocs/dev/debt/changes/feat-nkwebkit-atom-string-table.mddocs/dev/debt/changes/feat-nkwebkit-symbol-registry.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T04:34:49Z.
Review: COMMENTED
Reviewed — comments
The reviewed changes have concrete lifetime and concurrency edge cases in atom and symbol cleanup that should be addressed before relying on these implementations.
What I ran
Reviewed head
d8170481208aefea5b586bf5a99f7a48ffbdf323. Read the prepared description, commits, manifest, diff, and the changed symbol, registry, string, atom-string, ABI, and test code at the pinned head. No build or test command was run.Results
Findings
Blocking
None verified.
Non-blocking
core/libs/prx/libSceNKWebKit/src/WtfString.cpp:253—Destroyroutes every nonempty atom toRemoveAtom, which searches only the current thread’s table and callsstd::terminate()when the atom belongs to another thread’s table. The debt entry acknowledges this cross-thread release behavior. Consider storing the owning table or making atom membership/removal safe across threads.core/libs/prx/libSceNKWebKit/src/WtfSymbolRegistry.cpp:149— Registry destruction clearssymbolRegistryfor every symbol copied out of the registry, then releases its retained reference. If a symbol has no other references, that release destroys it; however, a concurrent lookup can retain or return it only while holding the registry lock. The destructor erases the registry before clearing pointers outside the lock, so a concurrentsymbolForKeycan create a new symbol for the same registry while teardown is in progress. Registry teardown should be synchronized against lookups for the full operation or otherwise prevent reuse during destruction.Not verified
Export.cppwas excluded by the review-folder size rule; its relevant removed stubs were read through the pinned-head reader, but the full file was not read. No build, tests, or console behavior were run. The author-reported test results were not independently verified. The prepared file listing says all changed files were included, but the fullExport.cpptext was excluded.To get this to a good state
Nothing is required. Optional: make atom removal safe when release occurs on a different thread, and prevent registry lookups from racing with destruction.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T12:52:45Z.
Review: COMMENTED
Built the branch’s changed sources and ran WtfAtomString and WtfSymbolRegistry on Linux against the existing runtime libraries. The test run passed and covered the atom string and symbol registry cases.
AI-assisted: yes.
Pull request closed