feat(libSceNKWebKit): implement the WTF atom string table #22678
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/22678"
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-18T01:45:57Z.
What
Implements the WTF atom string table: 20 11.x exports that all throw on
maintoday.addforLChar/UCharbuffers, substrings andStaticStringImpl,addLiteral, bothaddSlowCaseoverloads,lookUpSlowCaseand bothlookUpoverloads.fromUTF8Internal, the sixnumberoverloads andconvertToASCIILowercase/Uppercase.destroy, which guest-inlinedderef()calls when the last reference goes.Source: pinned AtomStringImpl.cpp, AtomString.cpp, AtomStringTable.cpp and StringImpl.cpp (PS5 11.x). For these functions the code is the same as in the 3.20 revision.
Details:
Thread::atomStringTable). It's a host container keyed by content. New atoms get the WebKit hash and the atom flag (16), and each translator creates the same kind of string as upstream:add(UChar*)narrows to 8-bit when it can;addLiteralandadd(StaticStringImpl*)don't copy the characters;addSlowCase(StringImpl&)adopts the passed string when its content is new, as upstream does.addSlowCase(AtomStringTable&, StringImpl&)uses the calling thread's table, because nothing here models the guestAtomStringTablelayout.~AtomStringTable.WtfString.cpp: releasing the last reference to an atom used to callstd::terminate.Releasenow shares aDestroyhelper with thedestroyexport, which removes the atom from the table and frees it. Symbols still terminate.AtomString::number(double)needs WebKit's shortest double formatting.WtfNumberFormat.cppalready had it forfloat, so that code is now a template with adoubleoverload. #14259 (String::number(double/float)) could reuse it.addSlowCase/lookUpSlowCase, a non-static string given toadd(StaticStringImpl*), an empty literal) throw. Releasing an atom from another thread's table callsstd::terminate, because carrying on would leave a dangling pointer in that table.~AtomStringTableexports, which only matter for a guest-owned table; andString::number(double/float), which belong to #14259.Debt: a fragment,
docs/dev/debt/changes/feat-nkwebkit-atom-string-table.md, adds the entries and removes the 20 inventory rows.Overlap:
pr_overlap.py --namesfinds no open PR with these 20 exports.Tested
Linux Mint 22.3. A shared driver runs random sequences of:
add(8- and 16-bit, null and empty),lookUpandaddLiteral;add(StaticStringImpl*)andaddSlowCase(both overloads) on fresh 8-bit, 16-bit and substring strings;lookUpSlowCaseand substringaddwith out-of-range starts and lengths;fromUTF8Internalon valid, overlong, surrogate and truncated UTF-8, with and without an end pointer;numberoverloads (zero, ±0, integers, 1e21-scale, tiny, random bit patterns, ±infinity);destroy) so that atoms leave the table and are created again.It hashes each result's identity (null, the input, or which earlier result), length, flags, stored hash, reference count and characters. The hash is compared with the one from the real WTF
AtomStringImpl/AtomStringcode (WebKit e12a212a, the same code for these functions) running the same driver.nkwebkit_wtfatomstringtest: 16 sequences of 1,000 operations match. As a one-off, 200 sequences of 10,000 also matched.number(double)throughfloatfails the transcript check.nkwebkit_wtftext_allocationstill passes (it now buildsWtfAtomString.cpptoo), and all NKWebKit tests pass.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-18T01:49:34Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
f94a9280da:tools/check_conventions.pypassed.nkwebkit_wtfatomstring_testsbuilt cleanly.nkwebkit_wtfatomstring):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.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 PrivacyOnion on 2026-11-18T02:17:55Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
d6ff9fcf63:tools/check_conventions.pypassed.nkwebkit_wtfatomstring_testsbuilt cleanly.nkwebkit_wtfatomstring):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.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:11:21Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: preserve the borrowed symbol backing when atomizing a full-length symbol so its last release does not free non-owned storage.
What I ran
d6ff9fcf637a069b45cf401bfea61c1b3d7c9346and the prepared diff; no build or test commands were run.description.md,commits.md,manifest.json,diff.patch,CMakeLists.txt,WtfAtomStringExports.hpp,libSceNKWebKit.hpp,WtfAtomString.cpp,WtfString.cpp,WtfStringAbi.hpp,WtfValueExports.hpp,WtfNumberFormat.cpp, andExport.cppat the relevant ranges.Export.cppandInventoryExports.hppfull texts were excluded from the review folder; the targetedExport.cpprange was read throughrepo_read.py.files.jsonwas unavailable.Results
Findings
Blocking
core/libs/prx/libSceNKWebKit/src/WtfAtomString.cpp:264: The symbol branch callsAddSubstring(string, 0, string.length). For a full-length string,CreateSubstringSharingImplcopies short content but, for longer content, creates a substring wrapper whose owner is the original symbol.AddToTablethen sets only the atom flag. On final release,Destroyrejects symbol-flagged wrappers and otherwise deallocates ordinary owned buffers; here the wrapper is treated as owned despite its data being borrowed from symbol storage, leading to invalid deallocation and potentially a dangling symbol backing. Preserve ownership correctly or make an owned copy for this path, and cover releasing a long full-length symbol atom.Non-blocking
None.
Not verified
Export.cppandInventoryExports.hpp, plus excluded files listed infiles.json, were not reviewed. The changed export range and new export header were inspected.To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T19:11:35Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed source paths show a coherent atom table implementation, but two changed export files were excluded and prevent a complete review.
What I ran
Reviewed head
7a6c6c0818281ca80b58f38ca9ee914f89a4baa6using the prepared diff and pinned repository reader. No build or tests were run.Results
Findings
Blocking
None verified in the source read.
Non-blocking
None.
Not verified
Export.cppandinclude/InventoryExports.hppwere excluded because they were too large for the review folder; their full text was not read. The manifest and diff were read, but not every changed file’s full text, so export registration and inventory consistency were not fully verified. No build, automated tests, or console behavior was verified. Other changed files reviewed:CMakeLists.txt,include/WtfAtomStringExports.hpp,libSceNKWebKit.hpp,src/WtfAtomString.cpp,src/WtfStringAbi.hpp,src/WtfString.cpp, andsrc/WtfNumberFormat.cpp.To get this to a good state
Nothing is required. Optional: verify the excluded export and inventory files and run the relevant build and tests before approval.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T20:18:35Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: prevent non-owning static and literal atom entries from being destroyed as owned strings.
What I ran
407846bd08a75d42e6e2566ff81d7b17ed2facd4using the prepared diff and readerrepo_read.py.description.md,commits.md,manifest.json,diff.patch,CMakeLists.txt,WtfAtomStringExports.hpp,WtfAtomString.cpp,WtfString.cpp,WtfStringAbi.hpp,tests/WtfAtomString.cpp, and the debt change note.Export.cppandInventoryExports.hppfull texts were excluded as too large; their diff hunks were reviewed.Results
Findings
Blocking
AddStaticandaddLiteralcreate these entries with ownership bits zero (WtfAtomString.cpp:490-493,WtfAtomString.cpp:600-604);Destroythen frees theStringImplunconditionally (WtfString.cpp:253-265). When the last reference to such an atom is released, this frees storage that was not allocated for the atom and leaves the table’s source pointer dangling. Preserve the upstream lifetime semantics for static/literal-backed atoms and avoid freeing their non-owned implementation or character storage. Changed lines:core/libs/prx/libSceNKWebKit/src/WtfString.cpp:255andcore/libs/prx/libSceNKWebKit/src/WtfAtomString.cpp:492.Non-blocking
None.
Not verified
Export.cppandInventoryExports.hppwere excluded as too large; only their changed hunks were inspected. Other parts of those files were not verified.To get this to a good state
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T13:33:55Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: last-reference release of an atom from a different thread terminates the process.
What I ran
Reviewed head
c0f9210306fc1d100a824ddc80eb0a61c5de6cceusing the prepared diff and the pinned-head repository reader. I did not run build or test commands.Results
Findings
Blocking
core/libs/prx/libSceNKWebKit/src/WtfString.cpp:255, destroying the last reference to an atom callsRemoveAtom, which looks only in the current thread’s table (core/libs/prx/libSceNKWebKit/src/WtfAtomString.cpp:332-333) and callsstd::terminateif it is absent. An atom created in one thread and released in another therefore terminates when the receiving thread drops its final reference. This is a concrete failure for shared atom strings; make atom removal safe across threads or otherwise ensure the owning table remains addressable for release.Non-blocking
None.
Sources
Not verified
No build, automated test, console, or hardware behavior was verified. I read the prepared change and the relevant changed source ranges, including targeted ranges in
Export.cppandInventoryExports.hpp; those two files were excluded from the prepared full-text bundle because of size. No other changed files were excluded from review.To get this to a good state
Make final-reference release safe when the atom was created in another thread, then rerun the atom-string and related WTF tests on the new head.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-11-30T03:52:35Z.
Review: COMMENTED
Architecture findings (2)
Advisory architecture findings (2)
1f79042f-3226-4690-b387-c8ea75384731Reviewing files that changed from the base of the PR and between
aecfbf79b1and8edd01d16b.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/libSceNKWebKit.hppcore/libs/prx/libSceNKWebKit/src/WtfAtomString.cppcore/libs/prx/libSceNKWebKit/src/WtfString.cppcore/libs/prx/libSceNKWebKit/src/WtfStringAbi.hppcore/libs/prx/libSceNKWebKit/tests/WtfAtomString.cppdocs/dev/debt/changes/feat-nkwebkit-atom-string-table.mdLimit details: You’ve used all 10 included reviews currently available.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T06:33:04Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
Changes are required before merge: make atom removal safe when the final reference is released on a thread other than the one that created the atom.
What I ran
Reviewed head
8edd01d16b6309c309317d99cb1791f831f744c2. Read the prepared description, commit list, manifest, and diff, plus targeted source ranges in the atom-string implementation, string lifetime code, ABI declarations, number formatting, and CMake configuration. No commands or tests were run in this review.Results
Findings
Blocking
core/libs/prx/libSceNKWebKit/src/WtfAtomString.cpp:332:RemoveAtomsearches only the releasing thread’sCurrentTable(). Atoms are stored in the creating thread’s table, and the added worker-table test explicitly allows an atom to outlive that table after clearing its atom flag. If an atom remains flagged and its finalStringreference is destroyed from another thread,WtfString.cppcallsDestroy, which callsRemoveAtom; the lookup fails andstd::terminate()ends the process. Track the owning table or make final release remove the atom safely regardless of the releasing thread.Non-blocking
None.
Not verified
core/libs/prx/libSceNKWebKit/Export.cppwas excluded from the review folder as too large; its full contents were not read. Its changed hunks in the prepared diff remove the previous stubs, but the full file was not reviewed.Export.cppwas the only excluded changed file.To get this to a good state
Make atom removal safe across threads, then rerun the atom-string tests and relevant NKWebKit checks on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T12:52:49Z.
Review: COMMENTED
Built the branch’s changed sources and ran WtfAtomString on Linux against the existing runtime libraries. The test run passed and covered the atom string table cases.
AI-assisted: yes.
Pull request closed