feat(libSceNKWebKit): implement WTF release leak-counter no-ops and descriptor helpers #19103

Merged
KernelPanicNT merged 3 commits from upstream-pr/19103 into main 2026-11-15 23:20:00 +00:00
KernelPanicNT commented 2026-11-12 19:43:13 +00:00 (Migrated from github.com)

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


What

Implements nine libSceNKWebKit WTF exports that threw through NotImplemented_nid_no_patch.

WTF::RefCountedLeakCounter (6 exports, empty bodies). C1(const char*) (7l4jBeWiHI4), C2(const char*) (opqf3CJzhms), increment() (FpxnD+vtdFQ), decrement() (rtWWBSqgRzo), suppressMessages(const char*) (+Abk7CfTivU) and cancelMessageSuppression(const char*) (SM0Cf+K17Yw) move to src/NoOpExports.cpp as empty functions, next to the D1/D2 destructors that are already there.

These bodies follow the release (NDEBUG) build of WebKit c55364d53f97. In that build every member of RefCountedLeakCounter is empty and the struct has no fields. In a debug build the counter keeps an atomic count and a description, and the destructor logs leaks. Why the release build is assumed:

  • The module's own RefCountedLeakCounter destructors are bare ret bodies. That is why D1/D2 are already empty in src/NoOpExports.cpp (see the No-op exports entry in docs/dev/debt/libSceNKWebKit.md). A debug-build destructor reads m_count and can log, so it cannot compile to a bare ret. Only the release build gives that body.
  • The tree's other WTF layouts (String, StringBuilder, TextStream, URL) already follow the release build.

The constructor, increment, decrement and the two static functions were not read from a module themselves. The new debt entry says this.

WTF::setNonBlock(int) (ZH232ViZnko), WTF::dupCloseOnExec(int) (wQ9-tXakN90) and WTF::sleep(Seconds) (gsFoqQ-R5js) are in a new src/WtfUniStd.cpp.

  • The descriptor calls go through the guest descriptor layer: libkernel's fcntl_nid_postfix, dup_nid_postfix and close_nid_postfix, with guest errno from __error_nid_postfix. This is how libSceLibcInternal's fdopendir calls fcntl, and libSceNKWebKit already links libkernel. Commands and flags use the FreeBSD numbers that the guest layer decodes: F_GETFD 1, F_SETFD 2, F_GETFL 3, F_SETFL 4, F_DUPFD_CLOEXEC 17, FD_CLOEXEC 1, O_NONBLOCK 4 and EINTR 4. These are not the host values.
  • dupCloseOnExec takes the #ifdef F_DUPFD_CLOEXEC path of the source, because FreeBSD defines F_DUPFD_CLOEXEC. It retries fcntl(fd, F_DUPFD_CLOEXEC, 0) on EINTR. If that fails for another reason, it falls back to dup plus setCloseOnExec (F_GETFD/F_SETFD, also retried on EINTR). If setting the flag fails, it closes the duplicate with the non-Linux closeWithRetry, which retries close on EINTR, and returns -1. Today the guest layer answers F_DUPFD_CLOEXEC with EOPNOTSUPP for files and sockets, so the fallback is the path that runs. If the guest layer starts supporting command 17, nothing changes here.
  • setNonBlock reads F_GETFL without checking it, then sets flags | O_NONBLOCK with F_SETFL, retrying on EINTR. It returns whether that last call succeeded, as the source does.
  • sleep(Seconds): WebKit waits on a private Condition with waitFor, so the deadline is MonotonicTime::now() + value. waitUntil and the ParkingLot loop only block while now < deadline. The port loops on the tree's MonotonicTime::now and std::this_thread::sleep_for (in chunks of at most an hour). It returns at once for zero, negative, -inf and NaN values, and it never returns for +inf.

Debt: the eight rows leave the Additional callable exports table (suppressMessages was declared in include/Api.hpp and had no row). The table's count is left as it is, since the debt file says inventory prose keeps historical counts. Two entries are added. The first says that the leak-counter bodies come from the assumed release build and were not checked against a module. The second says that the descriptor helpers and sleep come from the pinned source, not from a device, and that F_DUPFD_CLOEXEC answers as the guest layer models it.

Source of the behaviour

Export WebKit c55364d53f97 Here
RefCountedLeakCounter members #ifdef NDEBUG: every body empty, no fields; debug destructor logs leaks empty bodies (release build)
dupCloseOnExec F_DUPFD_CLOEXEC with EINTR retry, then dup + setCloseOnExec, closeWithRetry on failure same, through the guest fcntl/dup/close with FreeBSD numbers
setNonBlock F_GETFL, then F_SETFL with O_NONBLOCK retried on EINTR same
sleep(Seconds) Condition::waitFor on a private lock until now + value sleep until the monotonic deadline; at once if !(now < deadline)

Tested

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

  • nkwebkit_noops calls the six leak-counter exports with a description, a null description, a reason and a null reason. It checks that the one-byte object is left alone and that no call reaches NotImplemented_nid_no_patch.
  • nkwebkit_wtf gets TestUniStdExtras and TestSleepSeconds. On a guest file opened with sceKernelOpen: setNonBlock sets O_NONBLOCK, keeps O_RDWR and is idempotent. dupCloseOnExec returns a new descriptor with FD_CLOEXEC set, and the original keeps FD_CLOEXEC clear. The duplicate shares the file offset (write through the duplicate, lseek on the original). On a closed descriptor setNonBlock returns false with errno EBADF, and dupCloseOnExec(-1) returns -1 with EBADF. sleep(0.05) waits at least 50 ms; zero, negative, -inf and NaN return at once.
  • ctest -R '^nkwebkit_(noops|wtf)$' passed in 2 of 2 runs.
  • Negative control: with the nine bodies replaced by NotImplemented_nid_no_patch, both tests abort.
  • tools/progress.py --compare: +9 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:5284069851 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19103). Originally posted by [KernelPanicNT](https://github.com/KernelPanicNT) on 2026-11-12T19:43:13Z. --- ### What Implements nine `libSceNKWebKit` WTF exports that threw through `NotImplemented_nid_no_patch`. **`WTF::RefCountedLeakCounter` (6 exports, empty bodies).** `C1(const char*)` (`7l4jBeWiHI4`), `C2(const char*)` (`opqf3CJzhms`), `increment()` (`FpxnD+vtdFQ`), `decrement()` (`rtWWBSqgRzo`), `suppressMessages(const char*)` (`+Abk7CfTivU`) and `cancelMessageSuppression(const char*)` (`SM0Cf+K17Yw`) move to `src/NoOpExports.cpp` as empty functions, next to the `D1`/`D2` destructors that are already there. These bodies follow the **release (`NDEBUG`) build** of WebKit `c55364d53f97`. In that build every member of `RefCountedLeakCounter` is empty and the struct has no fields. In a debug build the counter keeps an atomic count and a description, and the destructor logs leaks. Why the release build is assumed: - The module's own `RefCountedLeakCounter` destructors are bare `ret` bodies. That is why `D1`/`D2` are already empty in `src/NoOpExports.cpp` (see the *No-op exports* entry in `docs/dev/debt/libSceNKWebKit.md`). A debug-build destructor reads `m_count` and can log, so it cannot compile to a bare `ret`. Only the release build gives that body. - The tree's other WTF layouts (`String`, `StringBuilder`, `TextStream`, `URL`) already follow the release build. The constructor, `increment`, `decrement` and the two static functions were not read from a module themselves. The new debt entry says this. **`WTF::setNonBlock(int)` (`ZH232ViZnko`), `WTF::dupCloseOnExec(int)` (`wQ9-tXakN90`) and `WTF::sleep(Seconds)` (`gsFoqQ-R5js`)** are in a new `src/WtfUniStd.cpp`. - The descriptor calls go through the guest descriptor layer: libkernel's `fcntl_nid_postfix`, `dup_nid_postfix` and `close_nid_postfix`, with guest errno from `__error_nid_postfix`. This is how `libSceLibcInternal`'s `fdopendir` calls `fcntl`, and libSceNKWebKit already links libkernel. Commands and flags use the FreeBSD numbers that the guest layer decodes: `F_GETFD` 1, `F_SETFD` 2, `F_GETFL` 3, `F_SETFL` 4, `F_DUPFD_CLOEXEC` 17, `FD_CLOEXEC` 1, `O_NONBLOCK` 4 and `EINTR` 4. These are not the host values. - `dupCloseOnExec` takes the `#ifdef F_DUPFD_CLOEXEC` path of the source, because FreeBSD defines `F_DUPFD_CLOEXEC`. It retries `fcntl(fd, F_DUPFD_CLOEXEC, 0)` on `EINTR`. If that fails for another reason, it falls back to `dup` plus `setCloseOnExec` (`F_GETFD`/`F_SETFD`, also retried on `EINTR`). If setting the flag fails, it closes the duplicate with the non-Linux `closeWithRetry`, which retries `close` on `EINTR`, and returns -1. Today the guest layer answers `F_DUPFD_CLOEXEC` with `EOPNOTSUPP` for files and sockets, so the fallback is the path that runs. If the guest layer starts supporting command 17, nothing changes here. - `setNonBlock` reads `F_GETFL` without checking it, then sets `flags | O_NONBLOCK` with `F_SETFL`, retrying on `EINTR`. It returns whether that last call succeeded, as the source does. - `sleep(Seconds)`: WebKit waits on a private `Condition` with `waitFor`, so the deadline is `MonotonicTime::now() + value`. `waitUntil` and the `ParkingLot` loop only block while `now < deadline`. The port loops on the tree's `MonotonicTime::now` and `std::this_thread::sleep_for` (in chunks of at most an hour). It returns at once for zero, negative, `-inf` and NaN values, and it never returns for `+inf`. Debt: the eight rows leave the *Additional callable exports* table (`suppressMessages` was declared in `include/Api.hpp` and had no row). The table's count is left as it is, since the debt file says inventory prose keeps historical counts. Two entries are added. The first says that the leak-counter bodies come from the assumed release build and were not checked against a module. The second says that the descriptor helpers and `sleep` come from the pinned source, not from a device, and that `F_DUPFD_CLOEXEC` answers as the guest layer models it. **Source of the behaviour** | Export | WebKit `c55364d53f97` | Here | |---|---|---| | `RefCountedLeakCounter` members | `#ifdef NDEBUG`: every body empty, no fields; debug destructor logs leaks | empty bodies (release build) | | `dupCloseOnExec` | `F_DUPFD_CLOEXEC` with `EINTR` retry, then `dup` + `setCloseOnExec`, `closeWithRetry` on failure | same, through the guest `fcntl`/`dup`/`close` with FreeBSD numbers | | `setNonBlock` | `F_GETFL`, then `F_SETFL` with `O_NONBLOCK` retried on `EINTR` | same | | `sleep(Seconds)` | `Condition::waitFor` on a private lock until `now + value` | sleep until the monotonic deadline; at once if `!(now < deadline)` | - [RefCountedLeakCounter.cpp#L24-L36](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/RefCountedLeakCounter.cpp#L24-L36) (release bodies), [#L75-L87](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/RefCountedLeakCounter.cpp#L75-L87) (debug destructor), [RefCountedLeakCounter.h#L28-L43](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/RefCountedLeakCounter.h#L28-L43) (fields only without `NDEBUG`) - [UniStdExtrasUnix.cpp#L33-L75](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/unix/UniStdExtrasUnix.cpp#L33-L75) (`setCloseOnExec`, `dupCloseOnExec`, `setNonBlock`), [UniStdExtras.h#L37-L51](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/UniStdExtras.h#L37-L51) (`closeWithRetry`) - [Seconds.cpp#L80-L91](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/Seconds.cpp#L80-L91) (`sleep`), [Condition.h#L69-L89](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/Condition.h#L69-L89) and [#L114-L117](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/Condition.h#L114-L117) (`waitUntil`, `waitFor`), [ParkingLot.cpp#L594-L604](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/ParkingLot.cpp#L594-L604) (wait loop) ### 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_noops` calls the six leak-counter exports with a description, a null description, a reason and a null reason. It checks that the one-byte object is left alone and that no call reaches `NotImplemented_nid_no_patch`. - `nkwebkit_wtf` gets `TestUniStdExtras` and `TestSleepSeconds`. On a guest file opened with `sceKernelOpen`: `setNonBlock` sets `O_NONBLOCK`, keeps `O_RDWR` and is idempotent. `dupCloseOnExec` returns a new descriptor with `FD_CLOEXEC` set, and the original keeps `FD_CLOEXEC` clear. The duplicate shares the file offset (write through the duplicate, `lseek` on the original). On a closed descriptor `setNonBlock` returns false with errno `EBADF`, and `dupCloseOnExec(-1)` returns -1 with `EBADF`. `sleep(0.05)` waits at least 50 ms; zero, negative, `-inf` and NaN return at once. - `ctest -R '^nkwebkit_(noops|wtf)$'` passed in 2 of 2 runs. - Negative control: with the nine bodies replaced by `NotImplemented_nid_no_patch`, both tests abort. - `tools/progress.py --compare`: +9 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:41:29 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: nkwebkit_noops_tests, nkwebkit_wtf_tests built cleanly.
  • CTest (nkwebkit_noops, nkwebkit_wtf):
    1/2 Test #3815: nkwebkit_noops ...................   Passed    0.04 sec
    2/2 Test #3835: nkwebkit_wtf .....................   Passed    0.07 sec
    100% tests passed, 0 tests failed out of 2
    
  • Negative control: with core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/Api.hpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, core/libs/prx/libSceNKWebKit/include/NoOpExports.hpp, core/libs/prx/libSceNKWebKit/include/WtfExports.hpp, core/libs/prx/libSceNKWebKit/src/NoOpExports.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified in core/libs/prx/libSceNKWebKit/src/WtfUniStd.cpp that GuestGetDescriptorFlags (1), GuestSetDescriptorFlags (2), GuestGetStatusFlags (3), GuestSetStatusFlags (4), GuestDuplicateCloseOnExec (17), GuestCloseOnExec (1), GuestNonBlock (4), and GuestEintr (4) match exact FreeBSD/Orbis OS fcntl and errno constants.
    • Audited _ZN3WTF14dupCloseOnExecEi in core/libs/prx/libSceNKWebKit/src/WtfUniStd.cpp: confirmed that fcntl(..., GuestDuplicateCloseOnExec, 0) and fallback dup_nid_postfix correctly loop on GuestEintr, and that SetCloseOnExec failure cleans up the newly duplicated descriptor via CloseWithRetry before returning -1.
    • Audited _ZN3WTF11setNonBlockEi in core/libs/prx/libSceNKWebKit/src/WtfUniStd.cpp: confirmed that status flags are combined with GuestNonBlock, F_SETFL retries on GuestEintr, and calls on closed/invalid handles propagate failure and set guest errno to EBADF (9).
    • Audited _ZN3WTF5sleepENS_7SecondsE in core/libs/prx/libSceNKWebKit/src/WtfUniStd.cpp: confirmed that deadline comparisons with now correctly return immediately for zero, negative, NaN, and -infinity inputs, while positive values sleep until now >= deadline in chunks capped at LongestSleepSeconds (3600.0s).
    • Verified in core/libs/prx/libSceNKWebKit/src/NoOpExports.cpp and include/NoOpExports.hpp that WTF::RefCountedLeakCounter exports (C1, C2, increment, decrement, suppressMessages, cancelMessageSuppression) implement NDEBUG release no-ops without dereferencing this or string pointers.
    • Checked AGENTS.md compliance across all modified files: confirmed zero comments in code (retaining only allowed namespace end comments), exact matching of mangled symbols and NIDs, and accurate technical debt documentation in docs/dev/debt/libSceNKWebKit.md.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5896248038 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19103#pullrequestreview-5896248038). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-13T18:41:29Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `c768ed1db0`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `nkwebkit_noops_tests`, `nkwebkit_wtf_tests` built cleanly. - **CTest** (`nkwebkit_noops`, `nkwebkit_wtf`): ``` 1/2 Test #3815: nkwebkit_noops ................... Passed 0.04 sec 2/2 Test #3835: nkwebkit_wtf ..................... Passed 0.07 sec 100% tests passed, 0 tests failed out of 2 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/Export.cpp`, `core/libs/prx/libSceNKWebKit/include/Api.hpp`, `core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp`, `core/libs/prx/libSceNKWebKit/include/NoOpExports.hpp`, `core/libs/prx/libSceNKWebKit/include/WtfExports.hpp`, `core/libs/prx/libSceNKWebKit/src/NoOpExports.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified in core/libs/prx/libSceNKWebKit/src/WtfUniStd.cpp that GuestGetDescriptorFlags (1), GuestSetDescriptorFlags (2), GuestGetStatusFlags (3), GuestSetStatusFlags (4), GuestDuplicateCloseOnExec (17), GuestCloseOnExec (1), GuestNonBlock (4), and GuestEintr (4) match exact FreeBSD/Orbis OS fcntl and errno constants. - Audited _ZN3WTF14dupCloseOnExecEi in core/libs/prx/libSceNKWebKit/src/WtfUniStd.cpp: confirmed that fcntl(..., GuestDuplicateCloseOnExec, 0) and fallback dup_nid_postfix correctly loop on GuestEintr, and that SetCloseOnExec failure cleans up the newly duplicated descriptor via CloseWithRetry before returning -1. - Audited _ZN3WTF11setNonBlockEi in core/libs/prx/libSceNKWebKit/src/WtfUniStd.cpp: confirmed that status flags are combined with GuestNonBlock, F_SETFL retries on GuestEintr, and calls on closed/invalid handles propagate failure and set guest errno to EBADF (9). - Audited _ZN3WTF5sleepENS_7SecondsE in core/libs/prx/libSceNKWebKit/src/WtfUniStd.cpp: confirmed that deadline comparisons with now correctly return immediately for zero, negative, NaN, and -infinity inputs, while positive values sleep until now >= deadline in chunks capped at LongestSleepSeconds (3600.0s). - Verified in core/libs/prx/libSceNKWebKit/src/NoOpExports.cpp and include/NoOpExports.hpp that WTF::RefCountedLeakCounter exports (C1, C2, increment, decrement, suppressMessages, cancelMessageSuppression) implement NDEBUG release no-ops without dereferencing this or string pointers. - Checked AGENTS.md compliance across all modified files: confirmed zero comments in code (retaining only allowed namespace end comments), exact matching of mangled symbols and NIDs, and accurate technical debt documentation in docs/dev/debt/libSceNKWebKit.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!19103
No description provided.