fix(libSceNKWebKit): take WTF::numberOfProcessorCores from the guest sysconf #20053
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20053"
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 MatteoSid on 2026-11-14T14:01:52Z.
What
WTF::numberOfProcessorCores()in libSceNKWebKit (_ZN3WTF22numberOfProcessorCoresEv, NIDL5XKYpXLrrE) returned the host'sstd::thread::hardware_concurrency()on every call and threw when the host reported 0. The PS5 11.x WebKit tree the library follows does something else. Its NumberOfCores.cpp first reads theWTF_numberOfProcessorCoresoverride withgetenv_np(thePLATFORM(PLAYSTATION)branch). It then callssysconf(_SC_NPROCESSORS_ONLN)onOS(FREEBSD), which the PS5 compiler's__FreeBSD__selects (PlatformOS.h). If that call fails it usesdefaultIfUnavailable(1), and it keeps the result in a static. WebKit c55364d53f97 has the same sysconf path; only its override goes throughgetenv.Changes:
numberOfProcessorCores()now asks guest libkernelsysconf(58)(_SC_NPROCESSORS_ONLN), the same guest view #19993 used forpageSize()withsysconf(47). It computes the value once and returns 1 when sysconf fails, where it used to throw. libSceNKWebKit already links libkernel.src/WtfNumberOfCores.cpp, which starts with aDerived fromline and the NumberOfCores.cpp notice copied verbatim, likeWtfPageBlock.cpp.WtfSystem.cpponly changes the export's body and declares the helper. It keeps<thread>, because #19380 and #19823 edit the lines around that include.numberOfProcessorCorescomes out of the "WTF host services" entry and gets its own entry next toWTF::pageSize:WTF_numberOfProcessorCoreswithgetenv_npinto a 4-byte buffer. This PR does not read it, because what the console'sgetenv_npreads (the environment or a storesetenv_npfills) is unknown. The libScePosixForWebKit debt file lists this, and ourgetenv_npthrows on values that do not fit. Reading the guestgetenvwould be a guess.sysconf(58)still reports the host's processor count, not the 16 a PS5 payload read. The libkernelsysconfentry already records that gap.Reachability:
numberOfProcessorCores()takes no arguments and needs no object, so any module that imports it from libSceNKWebKit reaches it directly. In the pinned PS5 tree, a web view calls it on these paths:Optionsinitialization, run when the first VM is created:overrideDefaultslowers the GC options below 4 cores.computeNumberOfWorkerThreadssizes the GC marker and JIT compiler threads throughkernTCSMAwareNumberOfProcessorCores.NavigatorBase::hardwareConcurrency, which servesnavigator.hardwareConcurrency(4 below 8 cores, else 8).WorkQueue::concurrentApplyandParallelJobs.Which console modules import this NID has not been checked against a dump.
Tested
Linux (Ubuntu 24.04 container, GCC 13.3), Release,
-DBUILD_TESTING=ON, on head5cbbba1df2based onmain3ffcba66e0. BuiltlibSceNKWebKit, the patchedcore/libs/libs/libSceNKWebKit.prxand every libSceNKWebKit test target.ctest -R 'nkwebkit|^public_headers$'passes 81 of 81.Windows (checked by JJenkx): Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. Head
5cbbba1df2was merged ontomainc04f8bec02(38abbd0fca, clean merge), andnkwebkit_wtfpassed in 3 of 3 runs, none skipped.Since
2aab2311db(after review):nkwebkit_wtfdrives the export throughNumberOfProcessorCoresSysconfForTest_nid_no_patch. That hook follows theLoginNameForTest_nid_no_patchpattern in libkernel: it replaces the sysconf query and drops the cached count, andnullptrrestores guestsysconf_nid_postfix. The test checks three things:sysconf_nid_postfix(58)and is stable.Negative controls on
2aab2311db, one at a time, in the Docker build. Each makesnkwebkit_wtffail, and the restored tree passes:WtfSystem.cppexport body (std::thread::hardware_concurrency);sysconf(57)instead of 58;static_cast<int>(result));cached > 0return removed).The same suite on
2aab2311db:ctest -R 'nkwebkit|^public_headers$'passes 81 of 81. The Windows run above was on5cbbba1df2, before this commit.nm -Don the patchedlibSceNKWebKit.prxlistsL5XKYpXLrrEat the address of_ZN3WTF22numberOfProcessorCoresEv, and the hook keeps its_nid_no_patchname.tools/check_conventions.py --base origin/main --head HEADpasses, andgit diff --check origin/mainis clean.Overlap: no open PR mentions
numberOfProcessorCores,NumberOfCoresor the NID.tools/pr_overlap.py --branchreported #19380 and #19823 onWtfSystem.cppL12-13 only, from an earlier draft that dropped the now-unused#include <thread>. The include is back, and this PR's hunks in that file sit at L21 and L30-32. It also listed 19 PRs it could not compare (debt file andtests/Wtf.cpp), which I checked by hand:WTF::pageSizeentries, ornumberOfProcessorCores;tests/Wtf.cppat lines 6, 562-573, 1132 and 1424, far fromTestSystem(line 273).No title tested.
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)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T14:05:56Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
5cbbba1df2:tools/check_conventions.pypassed;git diff --checkclean.nkwebkit_wtf_testsbuilt cleanly.nkwebkit_wtf):Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T15:34:12Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
2aab2311db:tools/check_conventions.pypassed;git diff --checkclean.nkwebkit_wtf_testsbuilt cleanly.nkwebkit_wtf):core/libs/prx/libSceNKWebKit/src/WtfSystem.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me