feat(libSceNKWebKit): implement 115 virtual-dispatch thunks translated from the module #24009
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24009"
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-20T00:51:56Z.
What
Implements 115
libSceNKWebKitexports whose module body reads a function pointer (from the object's vtable, or from an argument) and jumps to it. All 115 throwNotImplementedonmaintoday. Stacked on #23758 (lifted wrappers), which is stacked on #23755 (lifted leaf functions); it reusessrc/LiftedAbi.hppandCallfrom them and addsCallFp(a tail call that also forwards adoubleargument register).Source: the
libSceNKWebKit.sprxwith SHA-2563af992253665387feeb5df90ff27dff683e3aa270cc4d92a0535b46ab18fa20d(the module the existing Constant-return exports debt entry reads as 11.00). Each body was translated instruction by instruction into C++ with the same translator as #23758, extended with indirect tail jumps (jmp *%reg,jmp *disp(%reg)):D1/D2) and 24 copy constructors (C1/C2) of JS wrapper classes, 8WK*C exports, 33 other member functions and 6boolgetters.MediaPlayer::setVolumeandvolumeChangedalso forward theirdouble.std::invalid_argumentwhere the module would fault.Return-type gate
A tail-jump returns whatever the target leaves in the result register, and the mangled name does not say what the target's return type is. So before packaging, I looked up the declared return type of every export in the WebKit source (a 11.x tree and the 2021 tree; the C API headers for the 8
WK*exports) and kept only those that fit one integer register and that the lifted C++ returns at full width. The table (name, declared type, kept or dropped, reason) is attached to this PR asreturns.tsv.void(41, including the 8WK*exports), destructors and constructors (68, no return value),bool(6).MediaPlayer::extraMemoryCost(size_t),MediaPlayer::platformErrorCode(long),MediaPlayer::fileSize(unsigned long long),WindowProxy::window(a pointer).rax:rdx). The twodoubleparameters (MediaPlayer::setVolume,volumeChanged) returnvoid.ScrollView::setDelegatesScrolling,MediaPlayer::setSizeandImageBufferBackend::drawConsumingno longer exist in the 11.x tree; their declarations arevoidin the 2021 tree, which is what I used.The lifter rejected 4 more thunks before this gate, so they are not here:
ScrollableArea::visibleContentRectandvisibleContentRectIncludingScrollbars(return anIntRectinrax:rdx),ScrollView::setUnobscuredContentSize(vucomiss, not modelled) andPageOverlay::clear(an index-only address,0x0(,%rsi,4)).Debt: the fragment
docs/dev/debt/changes/feat-nkwebkit-lifted-virtual-thunks.mdadds the Functional entry and removes the 106 inventory rows that exist for these exports.Overlap: I diffed all 152 open PRs that touch
libSceNKWebKit(2020 open in total),mainat49119834f1, and the lifted jump-out and branchy-wrapper branches for the 115 names. None implements them.How it was checked
Offline, against the module's own code (none of it is in the repository), for the 119 thunks the translator lifted. The 4 dropped by the gate were included in these runs; the 115 kept were re-run in the last step.
+0, counters, flags and links in the next words), arguments that alias object fields, and arguments that are stub addresses. It compares the call log (slot, six argument registers,xmm0for the twodoublefunctions), the memory and the return value. 119/119 pass 3000 trials each, 0 mismatches, 0 thin (at least 47 trials reach the jump for every function kept; the smallest overall is 24).doubleargument 2, branch condition 95, constant 108): 4172 caught, 1 equivalent, 0 missed. The equivalent one isEditor::Command::isSupported,~0xffchanged to~0xfein(v & ~0xff) | 1: bit 0 is forced to 1 either way, so the result is identical. Mutants that survived early rounds exposed gaps in the harness (a pointee equal to a field of*this, offsets taken from the function's own displacements, flag-shaped bytes at those offsets); those were fixed and the whole run repeated.0x5a0000000000, the fake vtable at0x5b0000000000and the recording stubs at0x5c0000000000. 0 disagreements with the C++; replaying the seeds reproduces identical digests with and without ASLR; a build with one offset changed is detected.In the repository, the new
nkwebkit_liftedvirtualthunkstest, on x86-64:VirtualAllocon Windows,mmapwithMAP_FIXED_NOREPLACEelsewhere) and aborts with the address and the error code if any of them cannot be mapped. It never relies on heap addresses. The stubs are 1024 small trampolines written into the stub region and made executable; each records its slot id, the argument registers andxmm0/xmm1and returns a seeded value.Tested
Linux Mint 22.3, GCC 13.3, Release:
nkwebkit_liftedvirtualthunkspasses. Negative control: changing one vtable offset (Scrollbar::setProportioncalls+0x128instead of+0x120) makes it abort.nkwebkitpass.tools/check_conventions.pyand the public-headers audit (test_public_headers.py --audit-only) pass. A merge with currentmainhas no conflicts.VirtualAlloc,VirtualProtect,FlushInstructionCache) is written but not compiled or run here.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-20T01:17:05Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
c4a209701d:tools/check_conventions.pypassed.nkwebkit_liftedleaffunctions_tests,nkwebkit_liftedvirtualthunks_tests,nkwebkit_liftedwrappers_testsbuilt cleanly.nkwebkit_liftedleaffunctions,nkwebkit_liftedvirtualthunks,nkwebkit_liftedwrappers):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/LegacyExports.hpp,core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp,core/libs/prx/libSceNKWebKit/src/LiftedLeafFunctions.cpp,core/libs/prx/libSceNKWebKit/src/LiftedVirtualThunks.cpp,core/libs/prx/libSceNKWebKit/src/LiftedWrappers.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-20T05:23:57Z.
Review: COMMENTED
Reviewed — comments
The review is incomplete: I inspected selected files and ranges, but did not verify every changed file or run checks.
What I ran
Read the prepared PR description, commit list, manifest, diff, and selected repository code at head
c4a209701d2f8f9fb08d0a182261906dfaa3e895. No commands or tests were run.Results
Findings
Blocking
None verified in the inspected ranges.
Non-blocking
None verified in the inspected ranges.
Sources
Reviewed the prepared diff and selected code at the pinned head. No behavior claims beyond the inspected ranges are made.
Not verified
The review folder lists 18 changed files. I read the full text of
CMakeLists.txt,LiftedAbi.hpp, andlibSceNKWebKit.hpp; partial ranges ofExport.cpp,LiftedVirtualThunks.cpp,LiftedVirtualThunks.cpptests, andLiftedVirtualThunksExports.hpp; and selected ranges ofdiff.patch. The remaining changed files and uninspected ranges were not reviewed. The description's reported tests and differential checks were not run by me.Export.cppwas excluded from the review folder, though selected ranges were available through the reader.To get this to a good state
Nothing is required. Optional: complete review of the remaining changed files and run the relevant checks before making a formal decision.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T13:48:26Z.
Review: COMMENTED
Reviewed — comments
The review is incomplete because several changed source and test files, including the full
Export.cpp, were not read, so the available evidence does not justify a formal approval or changes request.What I ran
No checks were run. I inspected the prepared diff and selected files through
repo_read.pyat headc5ad5e13962cc29dc2d9079f644c9b493ac719cd; no merged-preview check was run.Results
Findings
Blocking
None verified from the inspected code.
Non-blocking
None.
Not verified
The complete implementation and test changes were not inspected. Read:
core/libs/prx/libSceNKWebKit/src/LiftedAbi.hpp,core/libs/prx/libSceNKWebKit/src/LiftedVirtualThunks.cpp(lines 1–450),core/libs/prx/libSceNKWebKit/tests/LiftedVirtualThunks.cpp(lines 1–120),core/libs/prx/libSceNKWebKit/CMakeLists.txtdiff, and review bundle documentsdescription.md,commits.md,manifest.json,diff.patch, andREADME.md. Excluded/not fully read:core/libs/prx/libSceNKWebKit/Export.cpp(not included in the review folder), and the remaining changed-file lines and diff hunks, including other source, test, header, and debt files. The author-reported checks were not independently run.To get this to a good state
Complete inspection of every changed file and run the applicable checks before making a formal review decision.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T20:17:49Z.
Review: COMMENTED
Reviewed — comments
The review is incomplete: I inspected the prepared diff and selected virtual-thunk implementation and test ranges at head
fc409f3c3cb5d36e7056c649441948078cc1a964, but did not read every changed line or run checks.What I ran
No commands or tests were run;
repo_read.pywas unavailable as a shell command in this session. I read the prepared review documents and used the pinned reader for selected source ranges.Results
Findings
Blocking
None verified in the inspected ranges.
Non-blocking
None.
Not verified
The complete contents of most changed files were not read. In particular,
Export.cppwas excluded by the review folder size limit; I did not inspect all ofLiftedLeafFunctions.cpp,LiftedWrappers.cpp, their tests, or the full virtual-thunk implementation and test. The author reports Linux test results in the PR description; these were not independently run. Windows behavior was also not verified.Files read:
review/README.md,review/description.md,review/commits.md,review/manifest.json,review/diff.patch;core/libs/prx/libSceNKWebKit/src/LiftedAbi.hpp; lines 1–180 ofcore/libs/prx/libSceNKWebKit/src/LiftedVirtualThunks.cpp; and lines 1–180 ofcore/libs/prx/libSceNKWebKit/tests/LiftedVirtualThunks.cpp.Files excluded or not fully read: the remaining changed files and ranges listed in the manifest;
Export.cppwas not available through the review folder and was not read through the repository reader.To get this to a good state
Nothing is required. Optional: complete review of the changed lines and run the documented checks before making a formal decision.
Pull request closed