feat(libSceJsc): implement WTF hash, hex and MediaTime helpers #18951
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18951"
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-12T15:41:39Z.
What
Implements three WTF helpers in libSceJsc that were
NotImplemented_nid_no_patchstubs. Each follows pinned WebKitc55364d53f97, the revisiondocs/dev/debt/libSceJsc.mdalready pins for the WTF string search (its declarations match these mangled names too):_ZN3WTF31integerToSixCharacterHashStringEjbhNTXZsyzkEstd::array<char, 7> WTF::integerToSixCharacterHashString(unsigned)_ZN3WTF8Internal9appendHexEPhjmjNS_17HexConversionModeEJ9Fo8pqmVZ4std::pair<LChar*, unsigned> WTF::Internal::appendHex(LChar*, unsigned, uintmax_t, unsigned, HexConversionMode)_ZNK3WTF9MediaTimeneERKS0_oJV+0NA8pssbool WTF::MediaTime::operator!=(const MediaTime&) constcompareintegerToSixCharacterHashStringfills six characters from the 62-character table, most significant first, plus a NUL; the 7-byte array comes back in RAX.appendHexwrites the digits backwards frombuffer + bufferSize, pads with'0'up tomin(minimumDigits, bufferSize)and returns{start, length}in RAX:RDX. Any mode other thanLowercaseis uppercase, as in WebKit.MediaTime::operator!=iscompare(rhs) != EqualToon the 16-byteMediaTime(value or double at 0, time scale at 8, flags at 12). Titles buildMediaTimevalues themselves, since both constructors areconstexprand inline in MediaTime.h. libSceNKWebKit already has acompareinsrc/Media.cpp, but libSceJsc does not link libSceNKWebKit and no prx library shares source with another, socompareis ported here from WebKit.Where WebKit corrupts memory or faults, these throw
std::invalid_argument: nullthis, reference or buffer arguments; a number with more hex digits than the buffer holds (WebKit writes before the buffer); and a zero time scale thatcomparewould divide by. The remainder products incompare, which can overflowint64_tin WebKit, wrap as the x86-64 multiply does.The three source files follow WebKit's control flow, so each starts with the notice of the WebKit files it follows, copied verbatim, plus a
Derived fromline, assrc/WtfStringSearch.cppdoes.Left out:
SHA1::computeHash(ALtdQuwSy0A). #19188 has since implemented it onmain, and this branch takes its version through the merge. In WebKit theSHA1constructor andaddBytesare out of line (SHA1.h, SHA1.cpp); libSceJsc exports neither, and no library here exportsaddBytes, so no title can fill aSHA1for it. The first version of this PR implemented it, and commitccb6e329c7restored the stub.SHA1::hexDigest(pF6MaJY4tLM) also stays a stub; it needs aCStringallocator, which #18430 adds.Gaps, in a new debt entry: none of this is compared with a console module, the console WTF version and layouts are unverified, and
appendHexassumes the gueststd::pair<LChar*, unsigned>is returned in RAX:RDX (trivially copyable, as on the host). After mergingmain, the "Additional callable exports" count goes from main's 325 to 322 (325 minus this PR's 3); the 136Api.hppthrowing exports are unchanged.Tested
Linux (Ubuntu 24.04 container, GCC 13.3), Release,
-DBUILD_TESTING=ON, on head8beebd5b35, a merge ofmain74900e8b0f(which brings #19188 and #19313) into the branch: builtlibSceJsc, the patchedcore/libs/libs/libSceJsc.prxand every libSceJsc test target.ctest -R '^(guest_jsc_string|jsc_placement_new|jsc_wtf_string_search|jsc_wtf_random|jsc_wtf_url|guest_jsc_trivial_returns|jsc_wtf_helpers|guest_jsc_register_sets_and_constructors|jsc_wtf_sha1|guest_jsc_script_value|jsc_wtf_bit_vector|public_headers)$'passes 12 of 12, including #19188'sjsc_wtf_sha1and #19313'sjsc_wtf_random. Earlier heads:86549b9df3(merge ofmain6871f7f142) passed the 9 tests that existed then, andccb6e329c7(based on63f37bf00e) passed 8 of 8. PrivacyOnion's review was on344b5ec3dc.Windows (before the SHA-1 removal): JJenkx ran
jsc_wtf_helperson head8ea9f9a577merged ontomain(Windows 11, WinLibs GCC 15.2 UCRT, Release); it passes in 3 of 3 runs, none skipped (comment).The new
jsc_wtf_helperstest uses independent vectors:0x12345678and0xFFFFFFFF, computed with a short Python port ofSixCharacterHash.cpp, and the terminating NUL;appendHexin both modes, with zero,UINTMAX_MAX, padding to 8 digits, a minimum larger than the buffer, an exact-fit buffer, a mode value of 7, the returned pointer and length, and untouched bytes on both sides of the written range;MediaTimeequal and unequal pairs: equal fractions with different scales, negative values, zero, aHasBeenRoundedflag, invalid against invalid and valid, the infinite and indefinite combinations, double against double and against a rational, and the overflow path ofcomparewith values near 2^62 and scales of 2·10^9 and 4·10^9;Every one of these 13 mutations, applied one at a time, makes the test fail: another table modulus, no NUL, swapped hex modes, no zero padding, an off-by-one buffer check,
==for!=, invalid-invalid not equal, indefinite missing from the shared-infinite check, the double comparison inverted, a scaled rational in the mixed double path, no whole-partLessThan, an unscaled remainder, and no zero-scale guard (SIGFPE). They were run on344b5ec3dc; the later commits change no code in these three functions.nm -Don the patchedlibSceJsc.prxlistsbhNTXZsyzkE,J9Fo8pqmVZ4andoJV+0NA8pssat the addresses of the three symbols (ALtdQuwSy0Ais #19188's implementation since the merge), andappendHexreturns in RAX:RDX in the built library.tools/check_conventions.py --base origin/main --head HEADpasses andgit diff --check origin/mainis clean. The second commit,8ea9f9a577, only drops trailing spaces from two copied WebKit notice lines. The third,ccb6e329c7, restores theSHA1::computeHashstub, its declaration and debt table row, and removes its source file, layout and tests. The merge commit86549b9df3resolves only the row-count line indocs/dev/debt/libSceJsc.md(328, counted in the merged table). #19104's debt entries are kept, and on itcheck_conventionsandgit diff --check origin/mainpass. The merge commit8beebd5b35removes the adjacent stubs from both sides inExport.cppandInventoryExports.hpp:cryptographicallyRandomNumber(#19313),SHA1::computeHash(#19188) and this PR's three. It keeps both includes inlibSceJsc.hppand sets the count to 322 (main's 325 minus 3). Indocs/dev/debt/libSceJsc.md, which merges withmerge=union, it keeps one count line and drops the table rows the union brought back. On it,check_conventionsandgit diff --check origin/mainpass.tools/pr_overlap.py --branchreports line conflicts only with #18430 and #18442 (neighbouring stub deletions inExport.cppandInventoryExports.hpp, the include list inlibSceJsc.hpp, the table row count and nearby table rows in the debt file). Neither implements these three functions; whichever merges second needs a trivial rebase, which I am happy to do. It could not compare #14212, which conflicts withmain; by hand, it only rewrites the table row count line indocs/dev/debt/libSceJsc.md, which this PR also edits. 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-12T15:49:47Z.
Review: CHANGES_REQUESTED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
344b5ec3dc:tools/check_conventions.pypassed;git diff --checkreported whitespace errors.jsc_wtf_helpers_testsbuilt cleanly.jsc_wtf_helpers):core/libs/prx/libSceJsc/Export.cpp,core/libs/prx/libSceJsc/include/InventoryExports.hpp,core/libs/prx/libSceJsc/libSceJsc.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Generated withfooter from the description; the AI-assisted checkbox can stay.Requesting changes for the points above.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T08:25:31Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
8beebd5b35:tools/check_conventions.pypassed;git diff --checkclean.jsc_wtf_helpers_testsbuilt cleanly.jsc_wtf_helpers):core/libs/prx/libSceJsc/Export.cpp,core/libs/prx/libSceJsc/include/InventoryExports.hpp,core/libs/prx/libSceJsc/libSceJsc.hppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me