feat(libSceNKWebKit): implement WTF file-system representation and path joining #19106

Merged
KernelPanicNT merged 4 commits from upstream-pr/19106 into main 2026-11-17 01:28:12 +00:00
KernelPanicNT commented 2026-11-12 19:43:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by KernelPanicNT on 2026-11-12T19:43:29Z.


What

Implements three WTF::FileSystemImpl helpers in libSceNKWebKit that threw through NotImplemented_nid_no_patch. They are in src/WtfString.cpp, next to encodeForFileName, decodeFromFilename and lastComponentOfPathIgnoringTrailingSlash.

Export NID Behaviour
fileSystemRepresentation(const String&) sxavOcVMOFA path.utf8(), i.e. the tree's String::utf8 in lenient mode (unpaired surrogates become 3-byte sequences); a null String gives an empty, non-null CString
stringFromFileSystemRepresentation(const char*) Q5IWykchiD8 null pointer -> null String, otherwise the tree's String::fromUTF8 (invalid UTF-8 -> null String)
pathByAppendingComponents(StringView, const Vector<StringView>&) k73D+1jaJZ0 path, then '/' and each component, built as WebKit's StringBuilder does
  • These are the non-Cocoa (!USE(CF)) POSIX paths of the pinned source. No guest-to-host path mapping happens here. The representation is only the byte string WebKit would pass to its own POSIX calls, and the new debt entry says so.
  • pathByAppendingComponents keeps WebKit's 8-bit/16-bit result:
    • append(StringView) keeps the builder 8-bit for 8-bit text, an empty view, or a single Latin-1 code unit from a 16-bit view. Any other 16-bit path upconverts.
    • append('/', component) goes through appendFromAdapters, which upconverts whenever the component view is 16-bit, even an empty one.
    • An empty result is the shared empty string (reifyString).
  • Totals above 2^31-1 units hit WebKit's RELEASE_ASSERT in toString, and here they throw std::length_error. A null String or Vector reference, and null characters with a nonzero length, throw where WebKit faults.
  • include/WtfValueExports.hpp declares the three exports, next to the other Vector-taking WTF exports. They leave Export.cpp and InventoryExports.hpp, and their three rows leave the Additional callable exports table. The table's count is left as it is, since the debt file keeps historical inventory counts.

Overlap: #14931 and #14949 (w4rc0n) implement the file-handle, path and directory operations. They show these three declarations only as diff context and implement none of them. The PRs share Export.cpp, InventoryExports.hpp and the debt file, so whichever lands second needs a trivial rebase.

Source of the behaviour (WebKit c55364d53f97; the only source)

Tested

Linux x86-64 (Ubuntu 24.04, GCC 14), on main 09ab49de9649. nkwebkit_wtf gets TestFileSystemRepresentations:

  • The UTF-8 of ASCII, Latin-1, CJK and an unpaired surrogate path; a null String; a null reference.
  • Valid, invalid and empty UTF-8 and a null pointer for stringFromFileSystemRepresentation.
  • Joins with an empty component, a trailing slash, an empty or null base and no components.
  • The 8-bit/16-bit result for a 16-bit base, a single Latin-1 16-bit base, an empty 16-bit base, a Latin-1 16-bit component and an empty 16-bit component.
  • Null characters with a length, and a null Vector.

Results:

  • ctest -R '^nkwebkit_(wtf|wtftext_allocation)$' passed in 2 of 2 runs. nkwebkit_wtftext_allocation compiles WtfString.cpp on its own.
  • Negative control: with the three bodies replaced by NotImplemented_nid_no_patch, nkwebkit_wtf aborts.
  • tools/progress.py --compare: +3 implemented.
  • tools/check_conventions.py --base origin/main passes.

Not tested on a device or with a title.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5284073787 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19106). Originally posted by [KernelPanicNT](https://github.com/KernelPanicNT) on 2026-11-12T19:43:29Z. --- ### What Implements three `WTF::FileSystemImpl` helpers in `libSceNKWebKit` that threw through `NotImplemented_nid_no_patch`. They are in `src/WtfString.cpp`, next to `encodeForFileName`, `decodeFromFilename` and `lastComponentOfPathIgnoringTrailingSlash`. | Export | NID | Behaviour | |---|---|---| | `fileSystemRepresentation(const String&)` | `sxavOcVMOFA` | `path.utf8()`, i.e. the tree's `String::utf8` in lenient mode (unpaired surrogates become 3-byte sequences); a null `String` gives an empty, non-null `CString` | | `stringFromFileSystemRepresentation(const char*)` | `Q5IWykchiD8` | null pointer -> null `String`, otherwise the tree's `String::fromUTF8` (invalid UTF-8 -> null `String`) | | `pathByAppendingComponents(StringView, const Vector<StringView>&)` | `k73D+1jaJZ0` | `path`, then `'/'` and each component, built as WebKit's `StringBuilder` does | - These are the non-Cocoa (`!USE(CF)`) POSIX paths of the pinned source. No guest-to-host path mapping happens here. The representation is only the byte string WebKit would pass to its own POSIX calls, and the new debt entry says so. - `pathByAppendingComponents` keeps WebKit's 8-bit/16-bit result: - `append(StringView)` keeps the builder 8-bit for 8-bit text, an empty view, or a single Latin-1 code unit from a 16-bit view. Any other 16-bit path upconverts. - `append('/', component)` goes through `appendFromAdapters`, which upconverts whenever the component view is 16-bit, even an empty one. - An empty result is the shared empty string (`reifyString`). - Totals above 2^31-1 units hit WebKit's `RELEASE_ASSERT` in `toString`, and here they throw `std::length_error`. A null `String` or `Vector` reference, and null characters with a nonzero length, throw where WebKit faults. - `include/WtfValueExports.hpp` declares the three exports, next to the other `Vector`-taking WTF exports. They leave `Export.cpp` and `InventoryExports.hpp`, and their three rows leave the *Additional callable exports* table. The table's count is left as it is, since the debt file keeps historical inventory counts. Overlap: #14931 and #14949 (w4rc0n) implement the file-handle, path and directory operations. They show these three declarations only as diff context and implement none of them. The PRs share `Export.cpp`, `InventoryExports.hpp` and the debt file, so whichever lands second needs a trivial rebase. **Source of the behaviour** (WebKit `c55364d53f97`; the only source) - [FileSystemPOSIX.cpp#L323-L330](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/posix/FileSystemPOSIX.cpp#L323-L330) (`pathByAppendingComponents`), [#L406-L419](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/posix/FileSystemPOSIX.cpp#L406-L419) (`stringFromFileSystemRepresentation`, `fileSystemRepresentation`) - [WTFString.cpp#L816-L819](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/WTFString.cpp#L816-L819) (`utf8()` is lenient), [#L886-L891](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/WTFString.cpp#L886-L891) (`fromUTF8(const LChar*)`) - [StringBuilder.h#L130-L136](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringBuilder.h#L130-L136) (`append(StringView)`), [#L394-L417](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringBuilder.h#L394-L417) (`appendFromAdapters`), [StringBuilder.cpp#L274-L297](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringBuilder.cpp#L274-L297) (upconvert), [#L325-L345](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringBuilder.cpp#L325-L345) (`appendCharacters(const UChar*, unsigned)`), [#L42-L68](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/text/StringBuilder.cpp#L42-L68) (`reifyString`) ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Linux x86-64 (Ubuntu 24.04, GCC 14), on `main` `09ab49de9649`. `nkwebkit_wtf` gets `TestFileSystemRepresentations`: - The UTF-8 of ASCII, Latin-1, CJK and an unpaired surrogate path; a null `String`; a null reference. - Valid, invalid and empty UTF-8 and a null pointer for `stringFromFileSystemRepresentation`. - Joins with an empty component, a trailing slash, an empty or null base and no components. - The 8-bit/16-bit result for a 16-bit base, a single Latin-1 16-bit base, an empty 16-bit base, a Latin-1 16-bit component and an empty 16-bit component. - Null characters with a length, and a null `Vector`. Results: - `ctest -R '^nkwebkit_(wtf|wtftext_allocation)$'` passed in 2 of 2 runs. `nkwebkit_wtftext_allocation` compiles `WtfString.cpp` on its own. - Negative control: with the three bodies replaced by `NotImplemented_nid_no_patch`, `nkwebkit_wtf` aborts. - `tools/progress.py --compare`: +3 implemented. - `tools/check_conventions.py --base origin/main` passes. Not tested on a device or with a title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
PrivacyOnion commented 2026-11-13 18:32:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T18:32:08Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 1abf20f6c1:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: nkwebkit_wtf_tests built cleanly.
  • CTest (nkwebkit_wtf):
    1/1 Test #3835: nkwebkit_wtf .....................   Passed    0.03 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, core/libs/prx/libSceNKWebKit/include/WtfValueExports.hpp, core/libs/prx/libSceNKWebKit/src/WtfString.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceNKWebKit/src/WtfString.cpp: verified _ZN3WTF14FileSystemImpl24fileSystemRepresentationERKNS_6StringE uses Checked() to throw std::invalid_argument on nullptr and invokes String::utf8 in lenient mode (conversion mode 0), safely returning an empty CString on null String inputs.
    • core/libs/prx/libSceNKWebKit/src/WtfString.cpp: verified _ZN3WTF14FileSystemImpl34stringFromFileSystemRepresentationEPKc validates null pointers before dereference and delegates to String::fromUTF8, which produces a null String for invalid UTF-8 sequences.
    • core/libs/prx/libSceNKWebKit/src/WtfString.cpp: verified _ZN3WTF14FileSystemImpl25pathByAppendingComponentsENS_10StringViewERKNS_6VectorIS1_Lm0ENS_15CrashOnOverflowELm16ENS_10FastMallocEEE performs complete pointer and buffer validation (components, parts.buffer when size > 0, and view.data when length > 0) and guards against integer overflow with std::length_error before string construction.
    • core/libs/prx/libSceNKWebKit/src/WtfString.cpp: verified 8-bit vs 16-bit upconversion logic strictly conforms to WebKit's StringBuilder append(StringView) and appendFromAdapters('/', component) semantics, correctly retaining 8-bit storage for empty views and single-unit Latin-1 base views while upconverting on any 16-bit component.
    • core/libs/prx/libSceNKWebKit/tests/Wtf.cpp: verified TestFileSystemRepresentations exercises ASCII, Latin-1, multi-byte CJK, unpaired surrogate inputs, empty and null paths, upconversion edge cases, and exception paths.
    • docs/dev/debt/libSceNKWebKit.md and core/libs/prx/libSceNKWebKit/Export.cpp: verified the 3 exports were correctly removed from stubs in Export.cpp and InventoryExports.hpp, inventory debt counts were updated (5961 to 5958), and no comments were added to code files in compliance with AGENTS.md.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5896136263 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19106#pullrequestreview-5896136263). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-13T18:32:08Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `1abf20f6c1`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `nkwebkit_wtf_tests` built cleanly. - **CTest** (`nkwebkit_wtf`): ``` 1/1 Test #3835: nkwebkit_wtf ..................... Passed 0.03 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/Export.cpp`, `core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp`, `core/libs/prx/libSceNKWebKit/include/WtfValueExports.hpp`, `core/libs/prx/libSceNKWebKit/src/WtfString.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libSceNKWebKit/src/WtfString.cpp: verified _ZN3WTF14FileSystemImpl24fileSystemRepresentationERKNS_6StringE uses Checked() to throw std::invalid_argument on nullptr and invokes String::utf8 in lenient mode (conversion mode 0), safely returning an empty CString on null String inputs. - core/libs/prx/libSceNKWebKit/src/WtfString.cpp: verified _ZN3WTF14FileSystemImpl34stringFromFileSystemRepresentationEPKc validates null pointers before dereference and delegates to String::fromUTF8, which produces a null String for invalid UTF-8 sequences. - core/libs/prx/libSceNKWebKit/src/WtfString.cpp: verified _ZN3WTF14FileSystemImpl25pathByAppendingComponentsENS_10StringViewERKNS_6VectorIS1_Lm0ENS_15CrashOnOverflowELm16ENS_10FastMallocEEE performs complete pointer and buffer validation (components, parts.buffer when size > 0, and view.data when length > 0) and guards against integer overflow with std::length_error before string construction. - core/libs/prx/libSceNKWebKit/src/WtfString.cpp: verified 8-bit vs 16-bit upconversion logic strictly conforms to WebKit's StringBuilder append(StringView) and appendFromAdapters('/', component) semantics, correctly retaining 8-bit storage for empty views and single-unit Latin-1 base views while upconverting on any 16-bit component. - core/libs/prx/libSceNKWebKit/tests/Wtf.cpp: verified TestFileSystemRepresentations exercises ASCII, Latin-1, multi-byte CJK, unpaired surrogate inputs, empty and null paths, upconversion edge cases, and exception paths. - docs/dev/debt/libSceNKWebKit.md and core/libs/prx/libSceNKWebKit/Export.cpp: verified the 3 exports were correctly removed from stubs in Export.cpp and InventoryExports.hpp, inventory debt counts were updated (5961 to 5958), and no comments were added to code files in compliance with AGENTS.md. - Note: the AI-assisted checkbox can stay. Looks Good To Me
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!19106
No description provided.